default voxel colors and transparency fixed

This commit is contained in:
azykov@mail.ru 2026-06-02 13:29:08 +03:00
parent 7ebccba199
commit 742e841ce0
No known key found for this signature in database
3 changed files with 23 additions and 9 deletions

View File

@ -56,10 +56,16 @@ export const ObjectView = observer(function ({ object }: ObjectViewProps) {
{ {
objectType.voxels.map((v, idx) => { objectType.voxels.map((v, idx) => {
const vt = state.world.getVoxelTypeById(v.typeId); const vt = state.world.getVoxelTypeById(v.typeId);
const color = (v.color ?? vt?.color) ?? 'white';
const opacity = (v.opacity ?? vt?.opacity) ?? 1;
return ( return (
<mesh key={idx} position={v.position}> <mesh key={idx} position={v.position}>
<boxGeometry args={[1, 1, 1]} /> <boxGeometry args={[1, 1, 1]} />
<meshStandardMaterial color={(v.color ?? vt?.color) ?? 'white'} opacity={(v.opacity ?? vt?.opacity) ?? 1} /> <meshStandardMaterial
color={color}
opacity={opacity}
transparent={opacity < 1}
/>
{isSelected && <Edges color="white" lineWidth={3} stencilWrite={false} />} {isSelected && <Edges color="white" lineWidth={3} stencilWrite={false} />}
</mesh> </mesh>
); );

View File

@ -13,7 +13,7 @@ const dirt: VoxelType = {
name: 'Dirt', name: 'Dirt',
opacity: 1, opacity: 1,
collidable: true, collidable: true,
color: '302520', color: '#302520',
}; };
const water: VoxelType = { const water: VoxelType = {
@ -21,15 +21,15 @@ const water: VoxelType = {
name: 'Stone', name: 'Stone',
opacity: 0.7, opacity: 0.7,
collidable: false, collidable: false,
color: 'c0d0ff', color: '#80a0f0',
}; };
const glass: VoxelType = { const glass: VoxelType = {
id: 'glass', id: 'glass',
name: 'Glass', name: 'Glass',
opacity: 0.4, opacity: 0.3,
collidable: true, collidable: true,
color: 'f0f8ff', color: '#b0d8e8',
}; };
export const DEFAULT_VOXEL_TYPES = { export const DEFAULT_VOXEL_TYPES = {

View File

@ -25,8 +25,9 @@ export class WorldState {
public loadMock() { public loadMock() {
const objTypeId = 'test1'; const objTypeId = 'test1';
const voxelTypeId = 'water'; const voxelTypeId = 'glass';
const objectId = 'object1'; const objectId1 = 'object1';
const objectId2 = 'object2';
this.data = { this.data = {
objectTypes: { objectTypes: {
@ -52,12 +53,18 @@ export class WorldState {
look: [0, 0, 0], look: [0, 0, 0],
}, },
objects: { objects: {
[objectId]: { [objectId1]: {
id: objectId, id: objectId1,
typeId: objTypeId, typeId: objTypeId,
position: [0, 0, 0], position: [0, 0, 0],
rotation: [0, 0, 0], rotation: [0, 0, 0],
}, },
[objectId2]: {
id: objectId2,
typeId: objTypeId,
position: [1, 0, 0],
rotation: [0, 0, 0],
},
}, },
}, },
gameRules: { gameRules: {
@ -67,6 +74,7 @@ export class WorldState {
playing: false, playing: false,
}, },
}; };
this.save();
} }
public load() { public load() {