Skip to content
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

Clean up multiple UVs, morphing normals, remove decals #467

Merged
merged 1 commit into from
Mar 16, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions dev-scripts.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@
"src/core/scene/tag.js",
"src/core/scene/_texture.js",
"src/core/scene/texture.js",
"src/core/scene/decal.js",
"src/core/scene/fresnel.js",
"src/core/scene/reflect.js",
"src/core/scene/regionMap.js",
Expand Down Expand Up @@ -102,7 +101,6 @@
"src/core/display/chunks/shaderParamsChunk.js",
"src/core/display/chunks/styleChunk.js",
"src/core/display/chunks/textureChunk.js",
"src/core/display/chunks/decalChunk.js",
"src/core/display/chunks/fresnelChunk.js",
"src/core/display/chunks/cubemapChunk.js",
"src/core/display/chunks/xformChunk.js"
Expand Down
399 changes: 399 additions & 0 deletions examples/geometry_morphTargets_normalMap.html

Large diffs are not rendered by default.

18 changes: 6 additions & 12 deletions examples/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -315,17 +315,15 @@ <h1><a href="../index.html">SceneJS</a> / Examples</h1>

"#morphing",
"geometry_morphTargets",
"geometry_morphTargets_normalMap",
"geometry_morphTargets_typedArrays",

"#automatic goodness",
"geometry_autoNormals",

"#optimization",
"optimization_vertexSharing",
"optimization_uintIndex",

"#editing",
"geometry_editing_indices"
"optimization_uintIndex"
],


Expand Down Expand Up @@ -419,14 +417,14 @@ <h1><a href="../index.html">SceneJS</a> / Examples</h1>
"#canvas textures",
"texture_canvas",
"texture_canvas_draw",
"texture_canvas_draw2",
"texture_canvas_interactive",
"texture_canvas_alpha",

"#shader-generated textures",
"texture_procedural_color",
"texture_procedural_color_mold",
"texture_procedural_color_water",
"texture_procedural_color_grid",
"texture_procedural_specular",
"texture_procedural_alpha",
"texture_procedural_emit",
Expand Down Expand Up @@ -455,11 +453,6 @@ <h1><a href="../index.html">SceneJS</a> / Examples</h1>
"configs_maxTextureSize"
],

"Decals": [
"#drawing onto surfaces",
"decals_emissive"
],

"Fresnel": [
"#fresnel effects",
"fresnel_diffuse",
Expand Down Expand Up @@ -592,6 +585,7 @@ <h1><a href="../index.html">SceneJS</a> / Examples</h1>
"picking_regions_highlight",
"picking_regions_hide",
"picking_regions_isolate",
"picking_regions_multiTexture",
"picking_emptyPixels"
],

Expand All @@ -600,8 +594,8 @@ <h1><a href="../index.html">SceneJS</a> / Examples</h1>
"importing_3ds_comet",
"importing_md2_lion",
"importing_obj_duck",
"importing_obj_raptor",
"importing_obj_hand"
"importing_obj_raptor"

],

"Optimization": [
Expand Down
428 changes: 428 additions & 0 deletions examples/picking_regions_multiTexture.html

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
-webkit-user-select: none;
}
</style>
<script src="../api/latest/scenejs.js"></script>
<script src="../api/latest/scenejs.min.js"></script>
<link href="css/styles.css" rel="stylesheet"/>
<body>

Expand Down Expand Up @@ -56,8 +56,8 @@

// The decal
{
type: "decal",
id: "myDecal",
type: "texture",
id: "myDrawingTexture",
image: image,
applyFrom: "uv",
applyTo: "emit",
Expand Down Expand Up @@ -95,10 +95,10 @@
});

// ---------------------------------------------------------------
// Logic for writing to the "decal" node's image
// Logic for writing to the drawing texture's node's image
// ---------------------------------------------------------------

scene.getNode("myDecal",
scene.getNode("myDrawingTexture",
function (decalNode) {

// Create hidden drawingCanvas to draw to
Expand All @@ -118,7 +118,7 @@

var down = false; // True when mouse is down

var needBlit = false; // True when drawingCanvas needs to be copied into the "decal" node
var needBlit = false; // True when drawingCanvas needs to be copied into the drawing texture node

// On each scene tick, copy the canvas into the decal node if dirty

Expand Down Expand Up @@ -158,7 +158,7 @@
down = false;
}

// Clears the "decal" node's image
// Clears the drawing texture node's image
function clear() {
context.rect(0, 0, drawingCanvas.width, drawingCanvas.height);
context.fillStyle = "black";
Expand Down
Binary file added examples/textures/earthWaterRegionMap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
44 changes: 0 additions & 44 deletions src/core/display/chunks/decalChunk.js

This file was deleted.

84 changes: 60 additions & 24 deletions src/core/display/chunks/geometryChunk.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ SceneJS_ChunkFactory.createChunkType({

this._aMorphVertexDraw = draw.getAttribute("SCENEJS_aMorphVertex");
this._aMorphNormalDraw = draw.getAttribute("SCENEJS_aMorphNormal");
this._aMorphTangentDraw = draw.getAttribute("SCENEJS_aMorphTangent");
this._uMorphFactorDraw = draw.getUniform("SCENEJS_uMorphFactor");

var pick = this.program.pick;
Expand All @@ -55,12 +56,16 @@ SceneJS_ChunkFactory.createChunkType({
}
},

morphDraw: function () {
morphDraw: function (frameCtx) {

this.VAOMorphKey1 = this.core.key1;
this.VAOMorphKey2 = this.core.key2;

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

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

if (this._aMorphVertexDraw) {
this._aVertexDraw.bindFloatArrayBuffer(target1.vertexBuf);
Expand All @@ -76,16 +81,38 @@ SceneJS_ChunkFactory.createChunkType({
this._aNormalDraw.bindFloatArrayBuffer(this.core2.normalBuf);
}

if (this._aUVDraw) {
this._aUVDraw.bindFloatArrayBuffer(this.core2.uvBuf);
}
if (this._aMorphTangentDraw || this._aTangentDraw) {

// Bind tangent arrays from geometry and morphGeometry

// In the texture chunk we remembered which UV layer we're using for the normal
// map so that we can lazy-generate the tangents from the appropriate UV layer
// in the geometry chunk.

// Note that only one normal map is allowed per drawable, so there
// will be only one UV layer used for normal mapping.

if (this._aUV2Draw) {
this._aUV2Draw.bindFloatArrayBuffer(this.core2.uvBuf2);
var normalMapUVLayerIdx = frameCtx.normalMapUVLayerIdx;
if (normalMapUVLayerIdx >= 0) {
if (this._aMorphTangentDraw) {
this._aTangentDraw.bindFloatArrayBuffer(this.core.getTangents(key1, this.core2.arrays.indices, this.core2.arrays.uvs[normalMapUVLayerIdx]));
this._aMorphTangentDraw.bindFloatArrayBuffer(this.core.getTangents(key2, this.core2.arrays.indices, this.core2.arrays.uvs[normalMapUVLayerIdx]));
} else if (this._aTangentDraw) {

// TODO: What's this for?
//this._aTangentDraw.bindFloatArrayBuffer(this.core2.tangentBuf);
}
}
}

if (this._aUV3Draw) {
this._aUV3Draw.bindFloatArrayBuffer(this.core2.uvBuf3);
// Bind UV layer from geometry

var uvBuf;
for (var i = 0, len = this._aUVDraw.length; i < len; i++) {
uvBuf = this.core2.uvBufs[i];
if (uvBuf) {
this._aUVDraw[i].bindFloatArrayBuffer(uvBuf);
}
}

if (this._aColorDraw) {
Expand All @@ -107,7 +134,7 @@ SceneJS_ChunkFactory.createChunkType({
var doMorph = this.core.targets && this.core.targets.length;
var cleanInterleavedBuf = this.core2.interleavedBuf && !this.core2.interleavedBuf.dirty;

if (this.VAO) {
if (this.VAO && frameCtx.VAO) { // Workaround for https://github.com/xeolabs/scenejs/issues/459
frameCtx.VAO.bindVertexArrayOES(this.VAO);
if (doMorph) {
if (this.VAOMorphKey1 == this.core.key1 && this.VAOMorphKey2 == this.core.key2) {
Expand All @@ -125,7 +152,7 @@ SceneJS_ChunkFactory.createChunkType({
}

if (doMorph) {
this.morphDraw();
this.morphDraw(frameCtx);
} else {
if (cleanInterleavedBuf) {
this.VAOHasInterleavedBuf = true;
Expand All @@ -142,12 +169,6 @@ SceneJS_ChunkFactory.createChunkType({
if (this._aColorDraw) {
this._aColorDraw.bindInterleavedFloatArrayBuffer(4, this.core2.interleavedStride, this.core2.interleavedColorOffset);
}
if (this._aTangentDraw) {

// Lazy-compute tangents as soon as needed.
// Unfortunately we can't include them in interleaving because that happened earlier.
this._aTangentDraw.bindFloatArrayBuffer(this.core2.tangentBuf || this.core2.getTangents());
}
} else {
this.VAOHasInterleavedBuf = false;
if (this._aVertexDraw) {
Expand All @@ -166,20 +187,35 @@ SceneJS_ChunkFactory.createChunkType({
if (this._aColorDraw) {
this._aColorDraw.bindFloatArrayBuffer(this.core2.colorBuf);
}
if (this._aTangentDraw) {
}

if (this._aTangentDraw) {

// Lazy-compute tangents
this._aTangentDraw.bindFloatArrayBuffer(this.core2.tangentBuf || this.core2.getTangents());
// In the texture chunk we remembered which UV layer we're using for the normal
// map so that we can lazy-generate the tangents from the appropriate UV layer
// in the geometry chunk.

// Note that only one normal map is allowed per drawable, so there
// will be only one UV layer used for normal mapping.

var normalMapUVLayerIdx = frameCtx.normalMapUVLayerIdx;
if (normalMapUVLayerIdx >= 0) {
this._aTangentDraw.bindFloatArrayBuffer(this.core2.getTangents(normalMapUVLayerIdx));
}
}
}

if (this._aRegionMapUVDraw) {
this._aRegionMapUVDraw.bindFloatArrayBuffer(this.core2.uvBufs[0]); // TODO: Make region maps work with all UV layers
var regionMapUVLayerIdx = frameCtx.regionMapUVLayerIdx; // Set by regionMapChunk
if (regionMapUVLayerIdx >= 0) {
var uvBufs = this.core2.uvBufs;
if (regionMapUVLayerIdx < uvBufs.length) {
this._aRegionMapUVDraw.bindFloatArrayBuffer(uvBufs[regionMapUVLayerIdx]);
}
}
}

this.core2.indexBuf.bind();

},

morphPick: function (frameCtx) {
Expand Down Expand Up @@ -257,7 +293,7 @@ SceneJS_ChunkFactory.createChunkType({
}

if (this._aRegionMapUVPick) {
this._aRegionMapUVPick.bindFloatArrayBuffer(core2.uvBufs[0]); // TODO: Make region maps work with all UV layers
this._aRegionMapUVPick.bindFloatArrayBuffer(core2.uvBufs[frameCtx.regionMapUVLayerIdx]); // Set by regionMapChunk
}

core2.indexBuf.bind();
Expand Down
31 changes: 22 additions & 9 deletions src/core/display/chunks/regionMapChunk.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ SceneJS_ChunkFactory.createChunkType({

this.program.draw.bindTexture(this._uRegionMapSampler, texture, frameCtx.textureUnit);
frameCtx.textureUnit = (frameCtx.textureUnit + 1) % SceneJS.WEBGL_INFO.MAX_TEXTURE_UNITS;

}

var gl = this.program.gl;
Expand All @@ -44,16 +43,25 @@ SceneJS_ChunkFactory.createChunkType({
frameCtx.transparent = transparent;
}

if (this._uRegionMapRegionColor) {
this._uRegionMapRegionColor.setValue(this.core.regionColor);
}
if (texture) {

if (this._uRegionMapHighlightFactor) {
this._uRegionMapHighlightFactor.setValue(this.core.highlightFactor);
}
if (this._uRegionMapRegionColor) {
this._uRegionMapRegionColor.setValue(this.core.regionColor);
}

if (this._uRegionMapHighlightFactor) {
this._uRegionMapHighlightFactor.setValue(this.core.highlightFactor);
}

if (this._uRegionMapHideAlpha) {
this._uRegionMapHideAlpha.setValue(this.core.hideAlpha);
if (this._uRegionMapHideAlpha) {
this._uRegionMapHideAlpha.setValue(this.core.hideAlpha);
}

frameCtx.regionMapUVLayerIdx = this.core.uvLayerIdx;

} else {

frameCtx.regionMapUVLayerIdx = -1;
}
},

Expand All @@ -70,6 +78,11 @@ SceneJS_ChunkFactory.createChunkType({
this.program.pick.bindTexture(this._uRegionMapSampler, texture, frameCtx.textureUnit);
frameCtx.textureUnit = (frameCtx.textureUnit + 1) % SceneJS.WEBGL_INFO.MAX_TEXTURE_UNITS;

frameCtx.regionMapUVLayerIdx = this.core.uvLayerIdx;

} else {

frameCtx.regionMapUVLayerIdx = -1;
}
}
});
Loading