This commit is contained in:
syuilo
2026-02-22 14:24:57 +09:00
parent 20dc48f221
commit cdb8d86fbf
4 changed files with 42 additions and 6 deletions

View File

@@ -3,19 +3,55 @@
* SPDX-License-Identifier: AGPL-3.0-only
*/
import * as BABYLON from '@babylonjs/core';
import { defineObject } from '../engine.js';
export const chair = defineObject({
id: 'chair',
name: 'Chair',
options: {
schema: {},
default: {},
schema: {
primaryColor: {
type: 'color',
label: 'Primay Color',
},
secondaryColor: {
type: 'color',
label: 'Secondary Color',
},
},
default: {
primaryColor: [0.44, 0.6, 0],
secondaryColor: [0, 0, 0],
},
},
placement: 'floor',
isChair: true,
createInstance: () => {
createInstance: ({ root, options }) => {
const primaryMesh = root.getChildMeshes().find(m => m.name.includes('__X_PRIMARY__')) as BABYLON.Mesh;
const primaryMaterial = primaryMesh.material as BABYLON.PBRMaterial;
const secondaryMesh = root.getChildMeshes().find(m => m.name.includes('__X_SECONDARY__')) as BABYLON.Mesh;
const secondaryMaterial = secondaryMesh.material as BABYLON.PBRMaterial;
const applyPrimaryColor = () => {
const [r, g, b] = options.primaryColor;
primaryMaterial.albedoColor = new BABYLON.Color3(r, g, b);
};
const applySecondaryColor = () => {
const [r, g, b] = options.secondaryColor;
secondaryMaterial.albedoColor = new BABYLON.Color3(r, g, b);
};
applyPrimaryColor();
applySecondaryColor();
return {
onOptionsUpdated: ([k, v]) => {
applyPrimaryColor();
applySecondaryColor();
},
interactions: {},
};
},

View File

@@ -67,10 +67,10 @@ export const tabletopDigitalClock = defineObject({
const colonMeshes = root.getChildMeshes().filter(m => m.name.includes('__TIME_7SEG_COLON__'));
const applyBodyColor = () => {
const bodyMesh = root.getChildMeshes().find(m => m.name.includes('__X_BODY__')) as BABYLON.Mesh;
const bodyMaterial = bodyMesh.material as BABYLON.PBRMaterial;
const bodyMesh = root.getChildMeshes().find(m => m.name.includes('__X_BODY__')) as BABYLON.Mesh;
const bodyMaterial = bodyMesh.material as BABYLON.PBRMaterial;
const applyBodyColor = () => {
if (options.bodyStyle === 'color') {
const [r, g, b] = options.bodyColor;
bodyMaterial.albedoColor = new BABYLON.Color3(r, g, b);