Skip to content

Commit

Permalink
Merge geometry and morphGeometry into one chunk
Browse files Browse the repository at this point in the history
This is done in the simplest possible way in this commit, further changes
will refine the code.
  • Loading branch information
Olli Etuaho committed Jun 30, 2014
1 parent f16f442 commit ab1075e
Show file tree
Hide file tree
Showing 6 changed files with 180 additions and 197 deletions.
3 changes: 1 addition & 2 deletions build.js
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,6 @@
"src/core/display/chunks/listenersChunk.js",
"src/core/display/chunks/lookAtChunk.js",
"src/core/display/chunks/materialChunk.js",
"src/core/display/chunks/morphGeometryChunk.js",
"src/core/display/chunks/nameChunk.js",
"src/core/display/chunks/programChunk.js",
"src/core/display/chunks/rendererChunk.js",
Expand Down Expand Up @@ -318,4 +317,4 @@
});
});

})();
})();
4 changes: 3 additions & 1 deletion src/core/display/chunks/chunk.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,14 @@ var SceneJS_Chunk = function() {};
* @param {String} id Chunk ID
* @param {SceneJS_Program} program Program to render the chunk
* @param {SceneJS_Core} core The state core rendered by this chunk
* @param {SceneJS_Core} core2 Another state core rendered by this chunk, only used for geometry
*/
SceneJS_Chunk.prototype.init = function(id, program, core) {
SceneJS_Chunk.prototype.init = function(id, program, core, core2) {

this.id = id;
this.program = program;
this.core = core;
this.core2 = core2;

if (this.build) {
this.build();
Expand Down
7 changes: 4 additions & 3 deletions src/core/display/chunks/chunkFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ SceneJS_ChunkFactory.createChunkType = function(params) {
/**
*
*/
SceneJS_ChunkFactory.prototype.getChunk = function(chunkId, type, program, core) {
SceneJS_ChunkFactory.prototype.getChunk = function(chunkId, type, program, core, core2) {

var chunkClass = SceneJS_ChunkFactory.chunkTypes[type]; // Check type supported

Expand All @@ -85,11 +85,12 @@ SceneJS_ChunkFactory.prototype.getChunk = function(chunkId, type, program, core)

if (chunk) { // Reinitialise the recycled chunk

chunk.init(chunkId, program, core);
chunk.init(chunkId, program, core, core2);

} else { // Instantiate a fresh chunk

chunk = new chunkClass(chunkId, program, core); // Create new chunk
chunk = new chunkClass(chunkId, program, core, core2); // Create new chunk

}

chunk.useCount = 1;
Expand Down
180 changes: 162 additions & 18 deletions src/core/display/chunks/geometryChunk.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,82 +15,226 @@ SceneJS_ChunkFactory.createChunkType({
this._aUV2Draw = draw.getAttribute("SCENEJS_aUVCoord2");
this._aColorDraw = draw.getAttribute("SCENEJS_aVertexColor");

this._aMorphVertexDraw = draw.getAttribute("SCENEJS_aMorphVertex");
this._aMorphNormalDraw = draw.getAttribute("SCENEJS_aMorphNormal");
this._aMorphUVDraw = draw.getAttribute("SCENEJS_aMorphUVCoord");
this._aMorphUV2Draw = draw.getAttribute("SCENEJS_aMorphUVCoord2");
this._aMorphColorDraw = draw.getAttribute("SCENEJS_aMorphColor");
this._uMorphFactorDraw = draw.getUniformLocation("SCENEJS_uMorphFactor");

var pick = this.program.pick;

this._aVertexPick = pick.getAttribute("SCENEJS_aVertex");
this._aNormalPick = pick.getAttribute("SCENEJS_aNormal");
this._aUVPick = pick.getAttribute("SCENEJS_aUVCoord");
this._aUV2Pick = pick.getAttribute("SCENEJS_aUVCoord2");
this._aColorPick = pick.getAttribute("SCENEJS_aVertexColor");

this._aMorphVertexPick = pick.getAttribute("SCENEJS_aMorphVertex");
this._aMorphNormalPick = pick.getAttribute("SCENEJS_aMorphNormal");
this._aMorphUVPick = pick.getAttribute("SCENEJS_aMorphUVCoord");
this._aMorphUV2Pick = pick.getAttribute("SCENEJS_aMorphUVCoord2");
this._aMorphColorPick = pick.getAttribute("SCENEJS_aMorphColor");
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;

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;
}

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

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

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

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

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

draw:function (ctx) {

this.morphDraw(ctx);

var gl = this.program.gl;

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

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

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

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

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

this.core.indexBuf.bind();
this.core2.indexBuf.bind();

},

morphPick: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;

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

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

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

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

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

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

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

pick:function (ctx) {

this.morphPick(ctx);

var gl = this.program.gl;

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

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

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

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

this.core.indexBuf.bind();
this.core2.indexBuf.bind();
}
});
Loading

0 comments on commit ab1075e

Please sign in to comment.