@@ -883,7 +883,6 @@ Texture.loadTexture=function(name, textureCache){
883883 } ) ;
884884}
885885
886-
887886/**
888887* Creates a texture from a byte array specifying the texture data.
889888* @param {Uint8Array } array A byte array containing the texture data,
@@ -1689,18 +1688,25 @@ Scene3D.prototype.loadTexture=function(name){
16891688/**
16901689* Loads a texture from an image URL and uploads it
16911690* to a texture buffer object.
1692- * @param {string } name URL of the image to load.
1691+ * @param {string|glutil.Texture } texture String giving the
1692+ * URL of the image to load, or
1693+ * a Texture object whose data may or may not be loaded.
16931694* @return {Promise } A promise that is resolved when
16941695* the image is loaded successfully and uploaded
16951696* to a texture buffer (the result will be a Texture
16961697* object), and is rejected when an error occurs.
16971698*/
1698- Scene3D . prototype . loadAndMapTexture = function ( name ) {
1699+ Scene3D . prototype . loadAndMapTexture = function ( texture ) {
16991700 var context = this . context ;
1700- return Texture . loadTexture (
1701- name , this . context , this . textureCache ) . then ( function ( texture ) {
1702- texture . loadedTexture = new LoadedTexture ( texture , context ) ;
1703- return texture ;
1701+ var tex = null ;
1702+ if ( texture . constructor == Texture ) {
1703+ tex = texture . loadImage ( ) ;
1704+ } else {
1705+ tex = Texture . loadTexture ( texture , this . context , this . textureCache )
1706+ }
1707+ return tex . then ( function ( textureInner ) {
1708+ textureInner . loadedTexture = new LoadedTexture ( textureInner , context ) ;
1709+ return textureInner ;
17041710 } ) ;
17051711}
17061712/**
@@ -2058,10 +2064,19 @@ ShapeGroup.prototype.getTransform=function(){
20582064 * Not documented yet.
20592065 */
20602066ShapeGroup . prototype . getMatrix = function ( ) {
2061- var mat = this . getTransform ( ) . getMatrix ( ) ;
2067+ var xform = this . getTransform ( ) ;
2068+ var thisIdentity = xform . isIdentity ( ) ;
20622069 if ( this . parent != null ) {
20632070 var pmat = this . parent . getMatrix ( ) ;
2064- mat = GLMath . mat4multiply ( pmat , mat ) ;
2071+ if ( thisIdentity ) {
2072+ mat = GLMath . mat4multiply ( pmat , xform . getMatrix ( ) ) ;
2073+ } else if ( GLMath . mat4isIdentity ( pmat ) ) {
2074+ mat = xform . getMatrix ( ) ;
2075+ } else {
2076+ mat = pmat ;
2077+ }
2078+ } else {
2079+ mat = xform . getMatrix ( ) ;
20652080 }
20662081 return mat ;
20672082}
@@ -2289,10 +2304,19 @@ Shape.prototype.setQuaternion=function(quat){
22892304 * @return {Array<number> } The current transformation matrix.
22902305 */
22912306Shape . prototype . getMatrix = function ( ) {
2292- var mat = this . getTransform ( ) . getMatrix ( ) ;
2307+ var xform = this . getTransform ( ) ;
2308+ var thisIdentity = xform . isIdentity ( ) ;
22932309 if ( this . parent != null ) {
22942310 var pmat = this . parent . getMatrix ( ) ;
2295- mat = GLMath . mat4multiply ( pmat , mat ) ;
2311+ if ( thisIdentity ) {
2312+ mat = pmat ;
2313+ } else if ( GLMath . mat4isIdentity ( pmat ) ) {
2314+ mat = xform . getMatrix ( ) ;
2315+ } else {
2316+ mat = GLMath . mat4multiply ( pmat , xform . getMatrix ( ) ) ;
2317+ }
2318+ } else {
2319+ mat = xform . getMatrix ( ) ;
22962320 }
22972321 return mat ;
22982322}
0 commit comments