Skip to content

Commit

Permalink
Simplify morph geometry handling
Browse files Browse the repository at this point in the history
  • Loading branch information
Olli Etuaho committed Jun 30, 2014
1 parent ab1075e commit 2796367
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 105 deletions.
138 changes: 54 additions & 84 deletions src/core/display/chunks/geometryChunk.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,203 +38,173 @@ SceneJS_ChunkFactory.createChunkType({
this._uMorphFactorPick = pick.getUniformLocation("SCENEJS_uMorphFactor");
},

morphDraw:function (ctx) {

var targets = this.core.targets;

if (!targets || targets.length == 0) {
ctx.vertexBuf = false;
ctx.normalBuf = false;
ctx.uvBuf = false;
ctx.uvBuf2 = false;
ctx.colorBuf = false;
return;
}

var gl = this.program.gl;
morphDraw:function () {

var target1 = this.core.targets[this.core.key1]; // Keys will update
var target2 = this.core.targets[this.core.key2];

if (this._aMorphVertexDraw) {
this._aVertexDraw.bindFloatArrayBuffer(target1.vertexBuf);
this._aMorphVertexDraw.bindFloatArrayBuffer(target2.vertexBuf);
ctx.vertexBuf = true;
} else {
ctx.vertexBuf = false;
} else if (this._aVertexDraw) {
this._aVertexDraw.bindFloatArrayBuffer(this.core2.vertexBuf);
}

if (this._aMorphNormalDraw) {
this._aNormalDraw.bindFloatArrayBuffer(target1.normalBuf);
this._aMorphNormalDraw.bindFloatArrayBuffer(target2.normalBuf);
ctx.normalBuf = true;
} else {
ctx.normalBuf = false;
} else if (this._aNormalDraw) {
this._aNormalDraw.bindFloatArrayBuffer(this.core2.normalBuf);
}

if (this._aMorphUVDraw) {
this._aUVDraw.bindFloatArrayBuffer(target1.uvBuf);
this._aMorphUVDraw.bindFloatArrayBuffer(target2.uvBuf);
ctx.uvBuf = true;
} else {
ctx.uvBuf = false;
} else if (this._aUVDraw) {
this._aUVDraw.bindFloatArrayBuffer(this.core2.uvBuf);
}

if (this._aMorphUV2Draw) {
this._aUV2Draw.bindFloatArrayBuffer(target1.uvBuf2);
this._aMorphUV2Draw.bindFloatArrayBuffer(target2.uvBuf2);
ctx.uvBuf2 = true;
} else {
ctx.uvBuf2 = false;
} else if (this._aUV2Draw) {
this._aUV2Draw.bindFloatArrayBuffer(this.core2.uvBuf2);
}

if (this._aMorphColorDraw) {
this._aColorDraw.bindFloatArrayBuffer(target1.colorBuf);
this._aMorphColorDraw.bindFloatArrayBuffer(target2.colorBuf);
ctx.colorBuf = true;
} else {
ctx.colorBuf = false;
} else if (this._aColorDraw) {
this._aColorDraw.bindFloatArrayBuffer(this.core2.colorBuf);
}

if (this._uMorphFactorDraw) {
gl.uniform1f(this._uMorphFactorDraw, this.core.factor); // Bind LERP factor
this.program.gl.uniform1f(this._uMorphFactorDraw, this.core.factor); // Bind LERP factor
}

},

draw:function (ctx) {

this.morphDraw(ctx);

var gl = this.program.gl;
if (this.core.targets && this.core.targets.length) {
this.morphDraw();
} else {

if (this.core2.interleavedBuf && !this.core2.interleavedBuf.dirty) {
this.core2.interleavedBuf.bind();
if (this._aVertexDraw && !ctx.vertexBuf) {
if (this._aVertexDraw) {
this._aVertexDraw.bindInterleavedFloatArrayBuffer(3, this.core2.interleavedStride, this.core2.interleavedPositionOffset);
}
if (this._aNormalDraw && !ctx.normalBuf) {
if (this._aNormalDraw) {
this._aNormalDraw.bindInterleavedFloatArrayBuffer(3, this.core2.interleavedStride, this.core2.interleavedNormalOffset);
}
if (this._aUVDraw && !ctx.uvBuf) {
if (this._aUVDraw) {
this._aUVDraw.bindInterleavedFloatArrayBuffer(2, this.core2.interleavedStride, this.core2.interleavedUVOffset);
}
if (this._aUV2Draw && !ctx.uv2Buf) {
if (this._aUV2Draw) {
this._aUV2Draw.bindInterleavedFloatArrayBuffer(2, this.core2.interleavedStride, this.core2.interleavedUV2Offset);
}
if (this._aColorDraw && !ctx.colorBuf) {
if (this._aColorDraw) {
this._aColorDraw.bindInterleavedFloatArrayBuffer(4, this.core2.interleavedStride, this.core2.interleavedColorOffset);
}
} else {
if (this._aVertexDraw && !ctx.vertexBuf) {
if (this._aVertexDraw) {
this._aVertexDraw.bindFloatArrayBuffer(this.core2.vertexBuf);
}

if (this._aNormalDraw && !ctx.normalBuf) {
if (this._aNormalDraw) {
this._aNormalDraw.bindFloatArrayBuffer(this.core2.normalBuf);
}

if (this._aUVDraw && !ctx.uvBuf) {
if (this._aUVDraw) {
this._aUVDraw.bindFloatArrayBuffer(this.core2.uvBuf);
}

if (this._aUV2Draw && !ctx.uvBuf2) {
if (this._aUV2Draw) {
this._aUV2Draw.bindFloatArrayBuffer(this.core2.uvBuf2);
}

if (this._aColorDraw && !ctx.colorBuf) {
if (this._aColorDraw) {
this._aColorDraw.bindFloatArrayBuffer(this.core2.colorBuf);
}
}

this.core2.indexBuf.bind();

},

morphPick:function (ctx) {
}

var targets = this.core.targets;
this.core2.indexBuf.bind();

if (!targets || targets.length == 0) {
ctx.vertexBuf = false;
ctx.normalBuf = false;
ctx.uvBuf = false;
ctx.uvBuf2 = false;
ctx.colorBuf = false;
return;
}
},

var gl = this.program.gl;
morphPick:function () {

var target1 = targets[this.core.key1]; // Keys will update
var target2 = targets[this.core.key2];
var target1 = this.core.targets[this.core.key1]; // Keys will update
var target2 = this.core.targets[this.core.key2];

if (this._aMorphVertexPick) {
this._aVertexPick.bindFloatArrayBuffer(target1.vertexBuf);
this._aMorphVertexPick.bindFloatArrayBuffer(target2.vertexBuf);
ctx.vertexBuf = true;
} else {
ctx.vertexBuf = false;
} else if (this._aVertexPick) {
this._aVertexPick.bindFloatArrayBuffer(this.core2.vertexBuf);
}

if (this._aMorphNormalPick) {
this._aNormalPick.bindFloatArrayBuffer(target1.normalBuf);
this._aMorphNormalPick.bindFloatArrayBuffer(target2.normalBuf);
ctx.normalBuf = true;
} else {
ctx.normalBuf = false;
} else if (this._aNormalPick) {
this._aNormalPick.bindFloatArrayBuffer(this.core2.normalBuf);
}

if (this._aMorphUVPick) {
this._aUVPick.bindFloatArrayBuffer(target1.uvBuf);
this._aMorphUVPick.bindFloatArrayBuffer(target2.uvBuf);
ctx.uvBuf = true;
} else {
ctx.uvBuf = false;
} else if (this._aUVPick) {
this._aUVPick.bindFloatArrayBuffer(this.core2.uvBuf);
}

if (this._aMorphUV2Pick) {
this._aUV2Pick.bindFloatArrayBuffer(target1.uvBuf2);
this._aMorphUV2Pick.bindFloatArrayBuffer(target2.uvBuf2);
ctx.uvBuf2 = true;
} else {
ctx.uvBuf2 = false;
} else if (this._aUV2Pick) {
this._aUV2Pick.bindFloatArrayBuffer(this.core2.uvBuf2);
}

if (this._aMorphColorPick) {
this._aColorPick.bindFloatArrayBuffer(target1.colorBuf);
this._aMorphColorPick.bindFloatArrayBuffer(target2.colorBuf);
ctx.colorBuf = true;
} else {
ctx.colorBuf = false;
} else if (this._aColorPick) {
this._aColorPick.bindFloatArrayBuffer(this.core2.colorBuf);
}

if (this._uMorphFactorPick) {
gl.uniform1f(this._uMorphFactorPick, this.core.factor); // Bind LERP factor
this.program.gl.uniform1f(this._uMorphFactorPick, this.core.factor); // Bind LERP factor
}

},

pick:function (ctx) {

this.morphPick(ctx);

var gl = this.program.gl;
if (this.core.targets && this.core.targets.length) {
this.morphPick();
} else {

if (this._aVertexPick && !ctx.vertexBuf) {
if (this._aVertexPick) {
this._aVertexPick.bindFloatArrayBuffer(this.core2.vertexBuf);
}

if (this._aNormalPick && !ctx.normalBuf) {
if (this._aNormalPick) {
this._aNormalPick.bindFloatArrayBuffer(this.core2.normalBuf);
}

if (this._aUVPick && !ctx.uvBuf) {
if (this._aUVPick) {
this._aUVPick.bindFloatArrayBuffer(this.core2.uvBuf);
}

if (this._aUV2Pick && !ctx.uvBuf2) {
if (this._aUV2Pick) {
this._aUV2Pick.bindFloatArrayBuffer(this.core2.uvBuf2);
}

this.core2.indexBuf.bind();
}

this.core2.indexBuf.bind();
}
});
16 changes: 0 additions & 16 deletions src/core/display/chunks/programChunk.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,6 @@ SceneJS_ChunkFactory.createChunkType({

drawProgram.bind();

/*
* HACK until we have distinct chunk for each VBO (maybe)
*/
frameCtx.vertexBuf = false;
frameCtx.normalBuf = false;
frameCtx.uvBuf = false;
frameCtx.uvBuf2 = false;
frameCtx.colorBuf = false;
frameCtx.textureUnit = 0;

var gl = this.program.gl;
Expand All @@ -39,14 +31,6 @@ SceneJS_ChunkFactory.createChunkType({

gl.uniform1i(this._rayPickMode, frameCtx.rayPick);

/*
* HACK until we have distinct chunk for each VBO (maybe)
*/
frameCtx.vertexBuf = false;
frameCtx.normalBuf = false;
frameCtx.uvBuf = false;
frameCtx.uvBuf2 = false;
frameCtx.colorBuf = false;
frameCtx.textureUnit = 0;

for (var i = 0; i < 10; i++) {
Expand Down
5 changes: 0 additions & 5 deletions src/core/display/display.js
Original file line number Diff line number Diff line change
Expand Up @@ -920,11 +920,6 @@ SceneJS_Display.prototype._doDrawList = function (pick, rayPick) {

frameCtx.blendEnabled = false;

frameCtx.vertexBuf = false;
frameCtx.normalBuf = false;
frameCtx.uvBuf = false;
frameCtx.uvBuf2 = false;
frameCtx.colorBuf = false;
frameCtx.backfaces = true;
frameCtx.frontface = "ccw";
frameCtx.pick = !!pick;
Expand Down

0 comments on commit 2796367

Please sign in to comment.