Hello,
I would like to deepen keyframe animation.
I made this piece of code.
//Create mesh and material
var mesh = pc.createBox(this.app.graphicsDevice);
var material = new pc.StandardMaterial();
material.diffuse = new pc.Color(1,0,0);
// Create Node
var graphNodeCube = new pc.GraphNode();
graphNodeCube.name = 'Box';
var meshInstance = new pc.MeshInstance(graphNodeCube, mesh, material);
graphNodeCube.setLocalPosition(0,0,0);
var graphNodeCube1 = new pc.GraphNode();
graphNodeCube.addChild(graphNodeCube1);
graphNodeCube1.name = 'Box1';
var meshInstance1 = new pc.MeshInstance(graphNodeCube1, mesh, material);
graphNodeCube1.setLocalPosition(0,1,0);
//Create model
var model = new pc.Model();
model.graph = graphNodeCube;
model.meshInstances = [meshInstance,meshInstance1];
this.app.scene.addModel(model);
//Create Model Entity
var modelEntity = new pc.Entity();
modelEntity.addComponent('model');
modelEntity.model.asset = model;
this.app.root.addChild(modelEntity);
//create animation
var animObj = {};
animObj['animation'] = {};
animObj['animation']['version'] = 4;
animObj['animation']['name'] = "Take 001";
animObj['animation']['duration'] = 10;
animObj['animation']['nodes'] = [];
var node = {};
node['name'] = "Box1"; // nome itemElement
node['defaults'] = {};
node['defaults']['r'] = [0, 0, 0];
node['defaults']['s'] = [1, 1, 1];
node['keys'] = [];
var key = {};
key['t'] = 0;
key['p'] = [0, 1, 0];
node['keys'].push(key);
var key1 = {};
key1['t'] = 10;
key1['p'] = [2, 1, 0];
node['keys'].push(key1);
animObj['animation']['nodes'].push(node);
var assetAnim = new pc.Asset('Take 001', 'animation',null, animObj);
this.app.assets.add(assetAnim);
modelEntity.addComponent('animation', {
assets: [assetAnim],
speed: 1
});
modelEntity.animation.play(assetAnim.name);
The two cube are rendered correctly but the animation doesn’t work.
Someone can give me an help?