-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Initial play animation branch commit. #2
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -86,39 +86,72 @@ export class BabylonDecorator extends ADecorator { | |
this.behaveEngine.registerJsonPointer(jsonPtr, getterCallback, setterCallback, typeName); | ||
}; | ||
|
||
registerEngineCallback = (path: string, callback: (value: any, onComplete: ()=> void) => void) => { | ||
this.behaveEngine.registerEngineCallback(path, callback); | ||
} | ||
|
||
registerKnownPointers = () => { | ||
this.registerJsonPointer("nodes/99/scale", (path) => { | ||
const parts: string[] = path.split("/"); | ||
return [(this.world.glTFNodes[Number(parts[1])] as AbstractMesh).scaling.x, | ||
(this.world.glTFNodes[Number(parts[1])] as AbstractMesh).scaling.y, | ||
(this.world.glTFNodes[Number(parts[1])] as AbstractMesh).scaling.z]; | ||
}, (path, value) => { | ||
const parts: string[] = path.split("/"); | ||
(this.world.glTFNodes[Number(parts[1])] as AbstractMesh).scaling = new Vector3(value[0], value[1], value[2]); | ||
}, "float3") | ||
|
||
this.registerJsonPointer("nodes/99/translation", (path) => { | ||
const parts: string[] = path.split("/"); | ||
return [(this.world.glTFNodes[Number(parts[1])] as AbstractMesh).position.x, | ||
(this.world.glTFNodes[Number(parts[1])] as AbstractMesh).position.y, | ||
(this.world.glTFNodes[Number(parts[1])] as AbstractMesh).position.z]; | ||
}, (path, value) => { | ||
const parts: string[] = path.split("/"); | ||
console.log(value); | ||
(this.world.glTFNodes[Number(parts[1])] as AbstractMesh).position= new Vector3(value[0], value[1], value[2]); | ||
}, "float3") | ||
|
||
this.registerJsonPointer("nodes/99/rotation", (path) => { | ||
const parts: string[] = path.split("/"); | ||
return [ | ||
(this.world.glTFNodes[Number(parts[1])] as AbstractMesh).rotationQuaternion?.w, | ||
(this.world.glTFNodes[Number(parts[1])] as AbstractMesh).rotationQuaternion?.x, | ||
(this.world.glTFNodes[Number(parts[1])] as AbstractMesh).rotationQuaternion?.y, | ||
(this.world.glTFNodes[Number(parts[1])] as AbstractMesh).rotationQuaternion?.z]; | ||
}, (path, value) => { | ||
const parts: string[] = path.split("/"); | ||
(this.world.glTFNodes[Number(parts[1])] as AbstractMesh).rotationQuaternion = new Quaternion(value[1], value[2], value[3], value[0]); | ||
}, "float4") | ||
const gltfNodesSize:number = this.world.glTFNodes.length; | ||
|
||
this.registerEngineCallback(`playAnimation`, (value, onComplete) => { | ||
// Note : targetTime not yet implemented to do something yet | ||
const {animation, speed, loopCount, targetTime} = value; | ||
const animationGroup = this.scene.animationGroups[animation]; | ||
|
||
animationGroup.speedRatio = speed; | ||
|
||
// run infinitely | ||
if (loopCount <= 0) { | ||
animationGroup.start(true, speed); | ||
} | ||
else { | ||
let count = loopCount; | ||
animationGroup.start(false, speed); | ||
animationGroup.onAnimationGroupEndObservable.add(function() { | ||
-- count; | ||
if (count > 0) { | ||
animationGroup.start(false, speed); | ||
} else { | ||
onComplete(); | ||
} | ||
}); | ||
} | ||
}); | ||
|
||
for (let i = 0; i < gltfNodesSize; i++) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you only have to register it once for the highest number, so we could just do nodes/${glTFNodesSize}/scale etc.. |
||
this.registerJsonPointer(`nodes/${i}/scale`, (path) => { | ||
const parts: string[] = path.split("/"); | ||
return [(this.world.glTFNodes[Number(parts[1])] as AbstractMesh).scaling.x, | ||
(this.world.glTFNodes[Number(parts[1])] as AbstractMesh).scaling.y, | ||
(this.world.glTFNodes[Number(parts[1])] as AbstractMesh).scaling.z]; | ||
}, (path, value) => { | ||
const parts: string[] = path.split("/"); | ||
(this.world.glTFNodes[Number(parts[1])] as AbstractMesh).scaling = new Vector3(value[0], value[1], value[2]); | ||
}, "float3") | ||
|
||
this.registerJsonPointer(`nodes/${i}/translation`, (path) => { | ||
const parts: string[] = path.split("/"); | ||
return [(this.world.glTFNodes[Number(parts[1])] as AbstractMesh).position.x, | ||
(this.world.glTFNodes[Number(parts[1])] as AbstractMesh).position.y, | ||
(this.world.glTFNodes[Number(parts[1])] as AbstractMesh).position.z]; | ||
}, (path, value) => { | ||
const parts: string[] = path.split("/"); | ||
(this.world.glTFNodes[Number(parts[1])] as AbstractMesh).position= new Vector3(value[0], value[1], value[2]); | ||
}, "float3") | ||
|
||
this.registerJsonPointer(`nodes/${i}/rotation`, (path) => { | ||
const parts: string[] = path.split("/"); | ||
return [ | ||
(this.world.glTFNodes[Number(parts[1])] as AbstractMesh).rotationQuaternion?.w, | ||
(this.world.glTFNodes[Number(parts[1])] as AbstractMesh).rotationQuaternion?.x, | ||
(this.world.glTFNodes[Number(parts[1])] as AbstractMesh).rotationQuaternion?.y, | ||
(this.world.glTFNodes[Number(parts[1])] as AbstractMesh).rotationQuaternion?.z]; | ||
}, (path, value) => { | ||
const parts: string[] = path.split("/"); | ||
(this.world.glTFNodes[Number(parts[1])] as AbstractMesh).rotationQuaternion = new Quaternion(value[1], value[2], value[3], value[0]); | ||
}, "float4") | ||
|
||
} | ||
} | ||
|
||
public extractBehaveGraphFromScene = (): any => { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import {BehaveEngineNode, IBehaviourNodeProps} from "../../BehaveEngineNode"; | ||
|
||
export class PlayAnimation extends BehaveEngineNode { | ||
REQUIRED_VALUES = [{id: "animation"}, {id: "speed"}, {id: "loopCount"}, {id: "targetTime"}] | ||
|
||
_animation: number; | ||
_speed: number; | ||
_loopCount: number; | ||
_targetTime: number; | ||
|
||
constructor(props: IBehaviourNodeProps) { | ||
super(props); | ||
this.name = "PlayAnimation"; | ||
this.validateValues(this.values); | ||
this.validateFlows(this.flows); | ||
this.validateConfigurations(this.configuration); | ||
|
||
const {animation, speed, loopCount, targetTime} = this.evaluateAllValues(this.REQUIRED_VALUES.map(val => val.id)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. values should not be evaluated at construction time, general practice is configuration = "class" private variables and the values are temporary variables only evaluated and used during the processNode function There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Gotcha |
||
|
||
this._animation = animation; | ||
this._speed = speed; | ||
this._loopCount = loopCount; | ||
this._targetTime = targetTime; | ||
} | ||
|
||
override processNode(flowSocket?: string) { | ||
this.graphEngine.clearValueEvaluationCache(); | ||
|
||
const {animation, speed, loopCount, targetTime} = this.evaluateAllValues(this.REQUIRED_VALUES.map(val => val.id)); | ||
|
||
this._animation = animation; | ||
this._speed = speed; | ||
this._loopCount = loopCount; | ||
this._targetTime = targetTime; | ||
|
||
this.graphEngine.processNodeStarted(this); | ||
|
||
console.log("trying to run play animation animation path value"); | ||
//const storeThisProcessNode = super.processNode; | ||
const that = this; | ||
|
||
this.graphEngine.runEngineCallback("playAnimation", {animation, speed, loopCount, targetTime}, function() { | ||
if (that.flows.done) { | ||
that.addEventToWorkQueue(that.flows.done) | ||
} | ||
}); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is not a path, I do like the idea of abstracting the callbacks outside of babylon, but maybe we can do this someplace other than the json get/set trie