Skip to content

Commit

Permalink
Merge pull request #502 from virtual-world-framework/branch/canvas-ma…
Browse files Browse the repository at this point in the history
…terial

Canvas Textures
  • Loading branch information
BrettASwift committed Jun 5, 2015
2 parents 6d61407 + 6ecb32a commit f038814
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 5 deletions.
48 changes: 43 additions & 5 deletions support/client/lib/vwf/model/threejs.js
Original file line number Diff line number Diff line change
Expand Up @@ -2631,6 +2631,16 @@ define( [ "module",

callingMethod: function( nodeID, methodName, parameters /* [, parameter1, parameter2, ... ] */ ) { // TODO: parameters

var node = this.state.nodes[ nodeID ];
if ( !node ) {
node = this.state.scenes[ nodeID ];
}

var threeObject;
if ( node ) {
threeObject = node.threeObject || node.threeScene;
}

if ( methodName === "raycast" ) {

var origin, direction, near, far, recursive, objectIDs;
Expand Down Expand Up @@ -2763,6 +2773,20 @@ define( [ "module",

}

if ( threeObject instanceof THREE.ShaderMaterial ) {
if ( methodName === "updateTexture" ) {
var textureName = parameters[ 0 ];
var texture = threeObject.uniforms[ textureName ];
if ( texture ) {
texture.value.needsUpdate = true;
threeObject.needsUpdate = true;
} else {
this.logger.warnx( nodeID + ".updateTexture", "Texture \""
+ textureName + "\" not found!" );
}
}
}

return undefined;
},

Expand Down Expand Up @@ -5695,14 +5719,21 @@ define( [ "module",
//console.log( [ "loadTexture: ", JSON.stringify( def ) ] );

if ( utility.isString( def ) ) {
url = def;
url = def;
} else {
url = def.url;
if ( def.canvasID ) {
var canvas = document.getElementById( def.canvasID );
url = canvas;
} else {
url = def.url;
}
mapping = def.mapping;
wrapTexture = Boolean( def.wrapTexture );
}

if ( mat === undefined ) {
if ( url instanceof HTMLElement && url.nodeName === "CANVAS" ) {
txt = new THREE.Texture( url );
} else if ( mat === undefined ) {
if ( mapping === undefined ) {
txt = THREE.ImageUtils.loadTexture( url );
} else {
Expand All @@ -5712,6 +5743,13 @@ define( [ "module",
txt = THREE.ImageUtils.loadTexture( url, mapping, onLoad, onError );
}

if ( def instanceof Object ) {
var keys = Object.keys( def );
for ( var i = 0; i < keys.length; i++ ) {
setTextureProperty( txt, keys[ i ], def[ keys[ i ] ], true );
}
}

if ( wrapTexture ) {
txt.wrapS = txt.wrapT = THREE.RepeatWrapping;
}
Expand Down Expand Up @@ -5945,7 +5983,7 @@ define( [ "module",
return value;
}

function setTextureProperty( texture, propertyName, propertyValue ) {
function setTextureProperty( texture, propertyName, propertyValue, suppressUpdate ) {
var value = propertyValue;

if ( texture === undefined ) {
Expand Down Expand Up @@ -6127,7 +6165,7 @@ define( [ "module",

}

if ( value !== undefined ) {
if ( value !== undefined && !suppressUpdate ) {
texture.needsUpdate = true;
}

Expand Down
3 changes: 3 additions & 0 deletions support/proxy/vwf.example.com/shaderMaterial.vwf.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,6 @@ methods:
var defines = this.defines;
defines[ name ] = value;
this.defines = defines;
updateTexture:
parameters:
- textureName

0 comments on commit f038814

Please sign in to comment.