fixed large voxelGroup rendering

added terrain object
This commit is contained in:
azykov@mail.ru 2026-06-02 23:19:15 +03:00
parent 32386ba70f
commit 858b47e71b
No known key found for this signature in database
3 changed files with 38 additions and 5 deletions

View File

@ -89,8 +89,8 @@ export const ObjectView = observer(function ({ object }: ObjectViewProps) {
onClick={handleClick} onClick={handleClick}
> >
{ {
voxelGroups(objectType).map((vg) => ( voxelGroups(objectType).map((vg) => {
<Instances key={vg.id}> return <Instances key={vg.id} limit={vg.positions.length}>
<boxGeometry args={[1, 1, 1]} /> <boxGeometry args={[1, 1, 1]} />
<meshStandardMaterial color={vg.color} opacity={vg.opacity} transparent={vg.opacity < 1} /> <meshStandardMaterial color={vg.color} opacity={vg.opacity} transparent={vg.opacity < 1} />
{ {
@ -98,7 +98,7 @@ export const ObjectView = observer(function ({ object }: ObjectViewProps) {
.map((pos, i) => <Instance key={i} position={pos} />) .map((pos, i) => <Instance key={i} position={pos} />)
} }
</Instances> </Instances>
)) })
} }
</group> </group>
</>); </>);

View File

@ -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;
}

View File

@ -5,6 +5,7 @@ import type { VoxelType } from "../types/voxel";
import { state } from "./rootState"; import { state } from "./rootState";
import { DEFAULT_VOXEL_TYPES } from "../model/defaultVoxelTypes"; import { DEFAULT_VOXEL_TYPES } from "../model/defaultVoxelTypes";
import { wolf } from "../model/objectPrefabs/wolf"; import { wolf } from "../model/objectPrefabs/wolf";
import { terrainXZ } from "../model/objectPrefabs/terrain";
export class WorldState { export class WorldState {
public data: World = WorldFactory.create(); public data: World = WorldFactory.create();
@ -57,6 +58,11 @@ export class WorldState {
name: 'Wolf', name: 'Wolf',
voxels: wolf, voxels: wolf,
}, },
terrain: {
id: 'terrain',
name: 'Terrain',
voxels: terrainXZ(50, 50),
}
}, },
voxelTypes: DEFAULT_VOXEL_TYPES, voxelTypes: DEFAULT_VOXEL_TYPES,
editorCamera: { editorCamera: {
@ -66,11 +72,20 @@ export class WorldState {
initialScene: { initialScene: {
character: { character: {
transform: { transform: {
position: [0, 0, 0], position: [0, 0, 20],
look: [0, 0, 0], 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: { gameRules: {
gravity: true, gravity: true,