From 858b47e71bb3bfd6e68edd656d7cd9c5deaf59ec Mon Sep 17 00:00:00 2001 From: "azykov@mail.ru" Date: Tue, 2 Jun 2026 23:19:15 +0300 Subject: [PATCH] fixed large voxelGroup rendering added terrain object --- src/components/ObjectView.tsx | 6 +++--- src/model/objectPrefabs/terrain.ts | 18 ++++++++++++++++++ src/state/worldState.ts | 19 +++++++++++++++++-- 3 files changed, 38 insertions(+), 5 deletions(-) create mode 100644 src/model/objectPrefabs/terrain.ts diff --git a/src/components/ObjectView.tsx b/src/components/ObjectView.tsx index 845d713..6245240 100644 --- a/src/components/ObjectView.tsx +++ b/src/components/ObjectView.tsx @@ -89,8 +89,8 @@ export const ObjectView = observer(function ({ object }: ObjectViewProps) { onClick={handleClick} > { - voxelGroups(objectType).map((vg) => ( - + voxelGroups(objectType).map((vg) => { + return { @@ -98,7 +98,7 @@ export const ObjectView = observer(function ({ object }: ObjectViewProps) { .map((pos, i) => ) } - )) + }) } ); diff --git a/src/model/objectPrefabs/terrain.ts b/src/model/objectPrefabs/terrain.ts new file mode 100644 index 0000000..c550fdc --- /dev/null +++ b/src/model/objectPrefabs/terrain.ts @@ -0,0 +1,18 @@ +import type { Voxel } from "../../types/voxel"; + +export function terrainXZ(width: number, length: number): Voxel[] { + + const vs = Array(width) + .fill(0) + .flatMap((_, x) => + Array(length) + .fill(0) + .map((_, z) => ({ + typeId: 'dirt', + position: [x - Math.floor(width / 2), 0, z - Math.floor(length / 2)], + color: 'green', + } as Voxel)) + ); + + return vs; +} diff --git a/src/state/worldState.ts b/src/state/worldState.ts index 25bcf94..143b50c 100644 --- a/src/state/worldState.ts +++ b/src/state/worldState.ts @@ -5,6 +5,7 @@ import type { VoxelType } from "../types/voxel"; import { state } from "./rootState"; import { DEFAULT_VOXEL_TYPES } from "../model/defaultVoxelTypes"; import { wolf } from "../model/objectPrefabs/wolf"; +import { terrainXZ } from "../model/objectPrefabs/terrain"; export class WorldState { public data: World = WorldFactory.create(); @@ -57,6 +58,11 @@ export class WorldState { name: 'Wolf', voxels: wolf, }, + terrain: { + id: 'terrain', + name: 'Terrain', + voxels: terrainXZ(50, 50), + } }, voxelTypes: DEFAULT_VOXEL_TYPES, editorCamera: { @@ -66,11 +72,20 @@ export class WorldState { initialScene: { character: { transform: { - position: [0, 0, 0], + position: [0, 0, 20], look: [0, 0, 0], } }, - objects: objectMap, + objects: { + terrain: { + id: 'terrain', + typeId: 'terrain', + position: [0, -1, 0], + rotation: [0, 0, 0], + scale: [1, 1, 1], + }, + ...objectMap, + }, }, gameRules: { gravity: true,