diff --git a/src/BasicBehaveEngine/decorators/BabylonDecorator.ts b/src/BasicBehaveEngine/decorators/BabylonDecorator.ts index 8083019..10e9130 100644 --- a/src/BasicBehaveEngine/decorators/BabylonDecorator.ts +++ b/src/BasicBehaveEngine/decorators/BabylonDecorator.ts @@ -738,6 +738,27 @@ export class BabylonDecorator extends ADecorator { }, (path, value) => { //no-op }, "float4x4", true); + + this.registerJsonPointer(`/nodes/${maxGltfNode}/mesh`, (path) => { + const parts: string[] = path.split("/"); + const node = this.world.glTFNodes[Number(parts[2])]; + return this.world.meshes.indexOf(node.subMeshes[0].mesh); + }, (path, value) => { + //no-op + }, "int", true); + + this.registerJsonPointer(`/meshes/${maxGltfNode}/primitives/${maxGltfNode}/material`, (path) => { + const parts: string[] = path.split("/"); + const mesh = this.world.glTFNodes[Number(parts[2])]; + const primitive = mesh._primitiveBabylonMeshes[Number(parts[4])]; + console.log("results", mesh, primitive, this.world.materials.indexOf(primitive.material)); + return this.world.materials.indexOf(primitive.material); + }, (path, value) => { + const parts: string[] = path.split("/"); + const mesh = this.world.glTFNodes[Number(parts[2])]; + const primitive = mesh._primitiveBabylonMeshes[Number(parts[4])]; + primitive.material = this.world.materials[value]; + }, "int", false); } private swimDownSelectability(node: Node, parentSelctability: boolean) { diff --git a/src/components/engineViews/BabylonEngineComponent.tsx b/src/components/engineViews/BabylonEngineComponent.tsx index fdccd82..1227bd5 100644 --- a/src/components/engineViews/BabylonEngineComponent.tsx +++ b/src/components/engineViews/BabylonEngineComponent.tsx @@ -1,6 +1,7 @@ import React, {useEffect, useRef, useState} from "react"; import {Button, Col, Container, Form, Modal, Row, Tab, Tabs} from "react-bootstrap"; import { + AbstractMesh, AnimationGroup, ArcRotateCamera, DirectionalLight, @@ -73,8 +74,8 @@ export const BabylonEngineComponent = (props: {behaveGraphRef: any, setBehaveGra const play = (shouldOverrideGraph: boolean) => { resetScene() - .then((res: {nodes: Node[], materials: Material[], animations: AnimationGroup[]}) => { - runGraph(babylonEngineRef, props.behaveGraphRef.current, sceneRef.current, res.nodes, res.materials, res.animations, shouldOverrideGraph); + .then((res: {nodes: Node[], materials: Material[], animations: AnimationGroup[], meshes: AbstractMesh[]}) => { + runGraph(babylonEngineRef, props.behaveGraphRef.current, sceneRef.current, res.nodes, res.materials, res.animations, res.meshes, shouldOverrideGraph); setGraphRunning(true); }) } @@ -114,7 +115,12 @@ export const BabylonEngineComponent = (props: {behaveGraphRef: any, setBehaveGra sceneRef.current?.createDefaultCamera(true, true, true); - return {nodes:buildGlTFNodeLayout(container.rootNodes[0]), animations: container.animationGroups, materials: container.materials}; + return { + nodes: buildGlTFNodeLayout(container.rootNodes[0]), + animations: container.animationGroups, + materials: container.materials, + meshes: container.meshes, + }; }; const buildGlTFNodeLayout = (rootNode: Node): Node[] => { @@ -147,12 +153,12 @@ export const BabylonEngineComponent = (props: {behaveGraphRef: any, setBehaveGra return finalNodes; } - const runGraph = (babylonEngineRef: any, behaveGraph: any, scene: any, nodes: Node[], materials: Material[], animations: AnimationGroup[], shouldOverride: boolean) => { + const runGraph = (babylonEngineRef: any, behaveGraph: any, scene: any, nodes: Node[], materials: Material[], animations: AnimationGroup[], meshes: AbstractMesh[], shouldOverride: boolean) => { if (babylonEngineRef.current !== null) { babylonEngineRef.current.clearCustomEventListeners() } - const world = {glTFNodes: nodes, animations: animations, materials: materials}; + const world = {glTFNodes: nodes, animations: animations, materials: materials, meshes: meshes}; babylonEngineRef.current = new BabylonDecorator(new BasicBehaveEngine(60), world, scene) const extractedBehaveGraph = babylonEngineRef.current.extractBehaveGraphFromScene()