Skip to content

Commit

Permalink
wip read-only access to nodes/{index}/mesh and read-write access to…
Browse files Browse the repository at this point in the history
… `mesh/{index}/primitive/{primIndex}/material`
  • Loading branch information
hybridherbst committed Dec 18, 2024
1 parent 356df69 commit ef60c1f
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 5 deletions.
21 changes: 21 additions & 0 deletions src/BasicBehaveEngine/decorators/BabylonDecorator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
16 changes: 11 additions & 5 deletions src/components/engineViews/BabylonEngineComponent.tsx
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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);
})
}
Expand Down Expand Up @@ -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[] => {
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit ef60c1f

Please sign in to comment.