Skip to content

Commit

Permalink
add morph targets data #28 #24
Browse files Browse the repository at this point in the history
  • Loading branch information
but0n committed Mar 27, 2019
1 parent 3afc285 commit a789b14
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 10 deletions.
23 changes: 13 additions & 10 deletions src/gltfScene.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,22 +55,25 @@ export class gltfScene {
accessors.push(acc);
}

// if(targets) {
// for (let target of targets) {
// for (let tar in target) {
// let acc: Accessor = gltf.accessors[target[tar]];
// acc.attribute = '_' + tar;
// accessors.push(acc);
// }
// break;
// }
// }

// Triangles
let ebo = gltf.accessors[meshData.indices];

let mf = new Mesh(accessors, ebo, meshData.mode);

// Morph targets
if(targets) {
mf.hasMorphTargets = true;
for (let target of targets) {
for (let tar in target) {
let acc: Accessor = gltf.accessors[target[tar]];
acc.attribute = tar;
mf.targets[tar] = acc;
}
break;
}
}

if (attributes.TANGENT == null && attributes.TEXCOORD_0 != null) {
console.warn('Using computed tagent!');
Mesh.preComputeTangent(mf);
Expand Down
8 changes: 8 additions & 0 deletions src/mesh/mesh.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ export class Mesh {
// Render mode
mode: number;

data = {}; // Raw data
hasMorphTargets = false;
targets = {};

constructor(attributes: Accessor[], indices?: Accessor, mode = WebGL2RenderingContext.TRIANGLES) {
this.attributes = attributes;
Expand All @@ -14,6 +17,11 @@ export class Mesh {
this.indices.bufferView.target = WebGL2RenderingContext.ELEMENT_ARRAY_BUFFER;
}
this.mode = mode;
// reference mesh data
for(let attr of attributes) {
const name = attr.attribute;
this.data[name] = attr.data;
}
}

static bindAccessorsVBO(target: Mesh, gl: WebGL2RenderingContext, locationList) {
Expand Down

0 comments on commit a789b14

Please sign in to comment.