From 230d39e4d0be311ff17afff1fcbe895bc147c8f4 Mon Sep 17 00:00:00 2001 From: alteredq Date: Tue, 24 Jul 2012 20:39:18 +0200 Subject: [PATCH] Made it possible to enforce use of uniforms instead of float texture for bones. --- build/Three.js | 26 ++++----- build/custom/ThreeWebGL.js | 76 +++++++++++++------------- examples/webgl_animation_skinning.html | 2 +- src/objects/SkinnedMesh.js | 4 +- src/renderers/WebGLRenderer.js | 9 +-- 5 files changed, 59 insertions(+), 58 deletions(-) diff --git a/build/Three.js b/build/Three.js index 3183e8ba7f..a782c3751d 100644 --- a/build/Three.js +++ b/build/Three.js @@ -215,9 +215,9 @@ THREE.Line=function(a,b,c){THREE.Object3D.call(this);this.geometry=a;this.materi THREE.Mesh=function(a,b){THREE.Object3D.call(this);this.geometry=a;this.material=b!==void 0?b:new THREE.MeshBasicMaterial({color:Math.random()*16777215,wireframe:true});if(this.geometry){this.geometry.boundingSphere||this.geometry.computeBoundingSphere();this.boundRadius=a.boundingSphere.radius;if(this.geometry.morphTargets.length){this.morphTargetBase=-1;this.morphTargetForcedOrder=[];this.morphTargetInfluences=[];this.morphTargetDictionary={};for(var c=0;c256?64:c>64?32:c>16?16:8;this.boneMatrices=new Float32Array(this.boneTextureWidth*this.boneTextureHeight*4);this.boneTexture=new THREE.DataTexture(this.boneMatrices,this.boneTextureWidth,this.boneTextureHeight,THREE.RGBAFormat,THREE.FloatType);this.boneTexture.minFilter=THREE.NearestFilter;this.boneTexture.magFilter= -THREE.NearestFilter;this.boneTexture.generateMipmaps=false;this.boneTexture.flipY=false}else this.boneMatrices=new Float32Array(16*c);this.pose()}};THREE.SkinnedMesh.prototype=Object.create(THREE.Mesh.prototype);THREE.SkinnedMesh.prototype.addBone=function(a){a===void 0&&(a=new THREE.Bone(this));this.bones.push(a);return a}; +THREE.SkinnedMesh=function(a,b,c){THREE.Mesh.call(this,a,b);this.useVertexTexture=c!==void 0?c:true;this.identityMatrix=new THREE.Matrix4;this.bones=[];this.boneMatrices=[];var d,e,f;if(this.geometry.bones!==void 0){for(a=0;a256?64:a>64?32:a>16?16:8;this.boneMatrices=new Float32Array(this.boneTextureWidth*this.boneTextureHeight*4);this.boneTexture=new THREE.DataTexture(this.boneMatrices,this.boneTextureWidth,this.boneTextureHeight,THREE.RGBAFormat,THREE.FloatType);this.boneTexture.minFilter=THREE.NearestFilter;this.boneTexture.magFilter= +THREE.NearestFilter;this.boneTexture.generateMipmaps=false;this.boneTexture.flipY=false}else this.boneMatrices=new Float32Array(16*a);this.pose()}};THREE.SkinnedMesh.prototype=Object.create(THREE.Mesh.prototype);THREE.SkinnedMesh.prototype.addBone=function(a){a===void 0&&(a=new THREE.Bone(this));this.bones.push(a);return a}; THREE.SkinnedMesh.prototype.updateMatrixWorld=function(a){this.matrixAutoUpdate&&this.updateMatrix();if(this.matrixWorldNeedsUpdate||a){this.parent?this.matrixWorld.multiply(this.parent.matrixWorld,this.matrix):this.matrixWorld.copy(this.matrix);this.matrixWorldNeedsUpdate=false}for(var a=0,b=this.children.length;a=0&&k.enableVertexAttribArray(r.position);r.color>=0&&k.enableVertexAttribArray(r.color);r.normal>=0&&k.enableVertexAttribArray(r.normal);r.tangent>=0&&k.enableVertexAttribArray(r.tangent);if(a.skinning&&r.skinVertexA>=0&&r.skinVertexB>=0&&r.skinIndex>=0&&r.skinWeight>=0){k.enableVertexAttribArray(r.skinVertexA);k.enableVertexAttribArray(r.skinVertexB);k.enableVertexAttribArray(r.skinIndex);k.enableVertexAttribArray(r.skinWeight)}if(a.attributes)for(i in a.attributes)r[i]!== +e=t("fragment",e+p);d=t("vertex",d+n);k.attachShader(q,d);k.attachShader(q,e);k.linkProgram(q);k.getProgramParameter(q,k.LINK_STATUS)||console.error("Could not initialise shader\nVALIDATE_STATUS: "+k.getProgramParameter(q,k.VALIDATE_STATUS)+", gl error ["+k.getError()+"]");k.deleteShader(e);k.deleteShader(d);q.uniforms={};q.attributes={};var s,d=["viewMatrix","modelViewMatrix","projectionMatrix","normalMatrix","objectMatrix","cameraPosition","morphTargetInfluences"];c.useVertexTexture?d.push("boneTexture"): +d.push("boneGlobalMatrices");for(s in o)d.push(s);s=d;d=0;for(o=s.length;d=0&&k.enableVertexAttribArray(r.position);r.color>=0&&k.enableVertexAttribArray(r.color);r.normal>=0&&k.enableVertexAttribArray(r.normal);r.tangent>=0&&k.enableVertexAttribArray(r.tangent);if(a.skinning&&r.skinVertexA>=0&&r.skinVertexB>=0&&r.skinIndex>=0&&r.skinWeight>=0){k.enableVertexAttribArray(r.skinVertexA);k.enableVertexAttribArray(r.skinVertexB);k.enableVertexAttribArray(r.skinIndex);k.enableVertexAttribArray(r.skinWeight)}if(a.attributes)for(i in a.attributes)r[i]!== void 0&&r[i]>=0&&k.enableVertexAttribArray(r[i]);if(a.morphTargets){a.numSupportedMorphTargets=0;q="morphTarget";for(i=0;i=0){k.enableVertexAttribArray(r[s]);a.numSupportedMorphTargets++}}}if(a.morphNormals){a.numSupportedMorphNormals=0;q="morphNormal";for(i=0;i=0){k.enableVertexAttribArray(r[s]);a.numSupportedMorphNormals++}}}a.uniformsList=[];for(h in a.uniforms)a.uniformsList.push([a.uniforms[h],h])};this.setFaceCulling= function(a,b){if(a){!b||b==="ccw"?k.frontFace(k.CCW):k.frontFace(k.CW);a==="back"?k.cullFace(k.BACK):a==="front"?k.cullFace(k.FRONT):k.cullFace(k.FRONT_AND_BACK);k.enable(k.CULL_FACE)}else k.disable(k.CULL_FACE)};this.setObjectFaces=function(a){if(L!==a.doubleSided){a.doubleSided?k.disable(k.CULL_FACE):k.enable(k.CULL_FACE);L=a.doubleSided}if(X!==a.flipSided){a.flipSided?k.frontFace(k.CW):k.frontFace(k.CCW);X=a.flipSided}};this.setDepthTest=function(a){if(za!==a){a?k.enable(k.DEPTH_TEST):k.disable(k.DEPTH_TEST); za=a}};this.setDepthWrite=function(a){if(Ga!==a){k.depthMask(a);Ga=a}};this.setBlending=function(a,b,c,d){if(a!==S){if(a===THREE.NoBlending)k.disable(k.BLEND);else if(a===THREE.AdditiveBlending){k.enable(k.BLEND);k.blendEquation(k.FUNC_ADD);k.blendFunc(k.SRC_ALPHA,k.ONE)}else if(a===THREE.SubtractiveBlending){k.enable(k.BLEND);k.blendEquation(k.FUNC_ADD);k.blendFunc(k.ZERO,k.ONE_MINUS_SRC_COLOR)}else if(a===THREE.MultiplyBlending){k.enable(k.BLEND);k.blendEquation(k.FUNC_ADD);k.blendFunc(k.ZERO,k.SRC_COLOR)}else if(a=== diff --git a/build/custom/ThreeWebGL.js b/build/custom/ThreeWebGL.js index 3fe9891fa8..973abf2cd4 100644 --- a/build/custom/ThreeWebGL.js +++ b/build/custom/ThreeWebGL.js @@ -114,9 +114,9 @@ T.cross(e.vertexNormals[d],N);f=T.dot(H[f]);f=f<0?-1:1;e.vertexTangents[d]=new T a.x;if(a.yc.y)c.y=a.y;if(a.zc.z)c.z=a.z}}else{this.boundingBox.min.set(0,0,0);this.boundingBox.max.set(0,0,0)}},computeBoundingSphere:function(){if(!this.boundingSphere)this.boundingSphere={radius:0};for(var a,b=0,c=0,d=this.vertices.length;cb&&(b=a)}this.boundingSphere.radius=b},mergeVertices:function(){var a={},b=[],c=[],d,f=Math.pow(10,4),e,h,j,l;e=0;for(h=this.vertices.length;e0;f--)if(d.indexOf(a["abcd"[f]])!==f){d.splice(f,1);this.faces[e]=new THREE.Face3(d[0],d[1],d[2],a.normal,a.color,a.materialIndex); d=0;for(j=this.faceVertexUvs.length;dthis.points.length-2?this.points.length-1:e+1;c[3]=e>this.points.length-3?this.points.length-1: -e+2;k=this.points[c[0]];i=this.points[c[1]];n=this.points[c[2]];m=this.points[c[3]];j=h*h;l=h*j;d.x=b(k.x,i.x,n.x,m.x,h,j,l);d.y=b(k.y,i.y,n.y,m.y,h,j,l);d.z=b(k.z,i.z,n.z,m.z,h,j,l);return d};this.getControlPointsArray=function(){var a,b,c=this.points.length,d=[];for(a=0;athis.points.length-2?this.points.length-1:e+1;c[3]=e>this.points.length-3?this.points.length-1: +e+2;k=this.points[c[0]];i=this.points[c[1]];n=this.points[c[2]];m=this.points[c[3]];j=h*h;l=h*j;d.x=b(k.x,i.x,n.x,m.x,h,j,l);d.y=b(k.y,i.y,n.y,m.y,h,j,l);d.z=b(k.z,i.z,n.z,m.z,h,j,l);return d};this.getControlPointsArray=function(){var a,b,c=this.points.length,d=[];for(a=0;a256?64:c>64?32:c>16?16:8;this.boneMatrices=new Float32Array(this.boneTextureWidth*this.boneTextureHeight*4);this.boneTexture=new THREE.DataTexture(this.boneMatrices,this.boneTextureWidth,this.boneTextureHeight,THREE.RGBAFormat,THREE.FloatType);this.boneTexture.minFilter=THREE.NearestFilter;this.boneTexture.magFilter= -THREE.NearestFilter;this.boneTexture.generateMipmaps=false;this.boneTexture.flipY=false}else this.boneMatrices=new Float32Array(16*c);this.pose()}};THREE.SkinnedMesh.prototype=Object.create(THREE.Mesh.prototype);THREE.SkinnedMesh.prototype.addBone=function(a){a===void 0&&(a=new THREE.Bone(this));this.bones.push(a);return a}; +THREE.SkinnedMesh=function(a,b,c){THREE.Mesh.call(this,a,b);this.useVertexTexture=c!==void 0?c:true;this.identityMatrix=new THREE.Matrix4;this.bones=[];this.boneMatrices=[];var d,f,e;if(this.geometry.bones!==void 0){for(a=0;a256?64:a>64?32:a>16?16:8;this.boneMatrices=new Float32Array(this.boneTextureWidth*this.boneTextureHeight*4);this.boneTexture=new THREE.DataTexture(this.boneMatrices,this.boneTextureWidth,this.boneTextureHeight,THREE.RGBAFormat,THREE.FloatType);this.boneTexture.minFilter=THREE.NearestFilter;this.boneTexture.magFilter= +THREE.NearestFilter;this.boneTexture.generateMipmaps=false;this.boneTexture.flipY=false}else this.boneMatrices=new Float32Array(16*a);this.pose()}};THREE.SkinnedMesh.prototype=Object.create(THREE.Mesh.prototype);THREE.SkinnedMesh.prototype.addBone=function(a){a===void 0&&(a=new THREE.Bone(this));this.bones.push(a);return a}; THREE.SkinnedMesh.prototype.updateMatrixWorld=function(a){this.matrixAutoUpdate&&this.updateMatrix();if(this.matrixWorldNeedsUpdate||a){this.parent?this.matrixWorld.multiply(this.parent.matrixWorld,this.matrix):this.matrixWorld.copy(this.matrix);this.matrixWorldNeedsUpdate=false}for(var a=0,b=this.children.length;a=0)return a.geometry.materials[b.materialIndex]}function d(a){return a instanceof THREE.MeshBasicMaterial&&!a.envMap||a instanceof THREE.MeshDepthMaterial?false:a&&a.shading!==void 0&&a.shading===THREE.SmoothShading?THREE.SmoothShading:THREE.FlatShading}function f(a){return a.map||a.lightMap||a instanceof THREE.ShaderMaterial?true:false}function e(a,b,c){var d,e,f,h,i=a.vertices;h=i.length; -var j=a.colors,k=j.length,n=a.__vertexArray,l=a.__colorArray,m=a.__sortArray,o=a.verticesNeedUpdate,q=a.colorsNeedUpdate,r=a.__webglCustomAttributesList;if(c.sortParticles){Vb.copy(Mb);Vb.multiplySelf(c.matrixWorld);for(d=0;d0,Wb=ic&&a;this.getContext=function(){return g};this.supportsVertexTextures= -function(){return ic};this.setSize=function(a,b){N.width=a;N.height=b;this.setViewport(0,0,N.width,N.height)};this.setViewport=function(a,b,c,d){Ub=a;Lb=b;hc=c;Nb=d;g.viewport(Ub,Lb,hc,Nb)};this.setScissor=function(a,b,c,d){g.scissor(a,b,c,d)};this.enableScissorTest=function(a){a?g.enable(g.SCISSOR_TEST):g.disable(g.SCISSOR_TEST)};this.setClearColorHex=function(a,b){z.setHex(a);K=b;g.clearColor(z.r,z.g,z.b,K)};this.setClearColor=function(a,b){z.copy(a);K=b;g.clearColor(z.r,z.g,z.b,K)};this.getClearColor= +g.clearColor(0,0,0,1);g.clearDepth(1);g.clearStencil(0);g.enable(g.DEPTH_TEST);g.depthFunc(g.LEQUAL);g.frontFace(g.CCW);g.cullFace(g.BACK);g.enable(g.CULL_FACE);g.enable(g.BLEND);g.blendEquation(g.FUNC_ADD);g.blendFunc(g.SRC_ALPHA,g.ONE_MINUS_SRC_ALPHA);g.clearColor(z.r,z.g,z.b,K);this.context=g;H=g.getParameter(g.MAX_VERTEX_TEXTURE_IMAGE_UNITS);g.getParameter(g.MAX_TEXTURE_SIZE);var Nc=g.getParameter(g.MAX_CUBE_MAP_TEXTURE_SIZE),ic=H>0,Vb=ic&&a;this.getContext=function(){return g};this.supportsVertexTextures= +function(){return ic};this.setSize=function(a,b){N.width=a;N.height=b;this.setViewport(0,0,N.width,N.height)};this.setViewport=function(a,b,c,d){Ub=a;fc=b;hc=c;Nb=d;g.viewport(Ub,fc,hc,Nb)};this.setScissor=function(a,b,c,d){g.scissor(a,b,c,d)};this.enableScissorTest=function(a){a?g.enable(g.SCISSOR_TEST):g.disable(g.SCISSOR_TEST)};this.setClearColorHex=function(a,b){z.setHex(a);K=b;g.clearColor(z.r,z.g,z.b,K)};this.setClearColor=function(a,b){z.copy(a);K=b;g.clearColor(z.r,z.g,z.b,K)};this.getClearColor= function(){return z};this.getClearAlpha=function(){return K};this.clear=function(a,b,c){var d=0;if(a===void 0||a)d=d|g.COLOR_BUFFER_BIT;if(b===void 0||b)d=d|g.DEPTH_BUFFER_BIT;if(c===void 0||c)d=d|g.STENCIL_BUFFER_BIT;g.clear(d)};this.clearTarget=function(a,b,c,d){this.setRenderTarget(a);this.clear(b,c,d)};this.addPostPlugin=function(a){a.init(this);this.renderPluginsPost.push(a)};this.addPrePlugin=function(a){a.init(this);this.renderPluginsPre.push(a)};this.deallocateObject=function(a){if(a.__webglInit){a.__webglInit= false;delete a._modelViewMatrix;delete a._normalMatrix;delete a._normalMatrixArray;delete a._modelViewMatrixArray;delete a._objectMatrixArray;if(a instanceof THREE.Mesh)for(var b in a.geometry.geometryGroups){var c=a.geometry.geometryGroups[b];g.deleteBuffer(c.__webglVertexBuffer);g.deleteBuffer(c.__webglNormalBuffer);g.deleteBuffer(c.__webglTangentBuffer);g.deleteBuffer(c.__webglColorBuffer);g.deleteBuffer(c.__webglUVBuffer);g.deleteBuffer(c.__webglUV2Buffer);g.deleteBuffer(c.__webglSkinVertexABuffer); g.deleteBuffer(c.__webglSkinVertexBBuffer);g.deleteBuffer(c.__webglSkinIndicesBuffer);g.deleteBuffer(c.__webglSkinWeightsBuffer);g.deleteBuffer(c.__webglFaceBuffer);g.deleteBuffer(c.__webglLineBuffer);var d=void 0,e=void 0;if(c.numMorphTargets){d=0;for(e=c.numMorphTargets;d0){g.bindBuffer(g.ARRAY_BUFFER,Y.__webglSkinVertexABuffer);g.bufferData(g.ARRAY_BUFFER,la,Ma);g.bindBuffer(g.ARRAY_BUFFER,Y.__webglSkinVertexBBuffer);g.bufferData(g.ARRAY_BUFFER,ma,Ma);g.bindBuffer(g.ARRAY_BUFFER,Y.__webglSkinIndicesBuffer);g.bufferData(g.ARRAY_BUFFER,na,Ma);g.bindBuffer(g.ARRAY_BUFFER,Y.__webglSkinWeightsBuffer);g.bufferData(g.ARRAY_BUFFER,oa,Ma)}}if(rd&&Wc){y=0;for(M=da.length;y0){g.bindBuffer(g.ARRAY_BUFFER,Y.__webglColorBuffer);g.bufferData(g.ARRAY_BUFFER,Ea,Ma)}}if(qd&&Ja.hasTangents){y=0;for(M=da.length;y0){g.bindBuffer(g.ARRAY_BUFFER,Y.__webglUVBuffer);g.bufferData(g.ARRAY_BUFFER,qc,Ma)}}if(hd&&ad&&ed){y=0;for(M=da.length;y0){g.bindBuffer(g.ARRAY_BUFFER,Y.__webglUV2Buffer);g.bufferData(g.ARRAY_BUFFER,rc,Ma)}}if(od){y=0;for(M=da.length;y0){g.bindBuffer(g.ARRAY_BUFFER,Y.__webglUVBuffer);g.bufferData(g.ARRAY_BUFFER,qc,Ma)}}if(hd&&ad&&ed){y=0;for(M=da.length;y0){g.bindBuffer(g.ARRAY_BUFFER,Y.__webglUV2Buffer);g.bufferData(g.ARRAY_BUFFER,rc,Ma)}}if(od){y=0;for(M=da.length;y=0&&g.enableVertexAttribArray(p.position);p.color>=0&&g.enableVertexAttribArray(p.color);p.normal>=0&&g.enableVertexAttribArray(p.normal);p.tangent>=0&&g.enableVertexAttribArray(p.tangent);if(a.skinning&&p.skinVertexA>=0&&p.skinVertexB>=0&&p.skinIndex>=0&&p.skinWeight>=0){g.enableVertexAttribArray(p.skinVertexA);g.enableVertexAttribArray(p.skinVertexB);g.enableVertexAttribArray(p.skinIndex);g.enableVertexAttribArray(p.skinWeight)}if(a.attributes)for(j in a.attributes)p[j]!== +e=x("fragment",e+q);d=x("vertex",d+o);g.attachShader(r,d);g.attachShader(r,e);g.linkProgram(r);g.getProgramParameter(r,g.LINK_STATUS)||console.error("Could not initialise shader\nVALIDATE_STATUS: "+g.getProgramParameter(r,g.VALIDATE_STATUS)+", gl error ["+g.getError()+"]");g.deleteShader(e);g.deleteShader(d);r.uniforms={};r.attributes={};var s,d=["viewMatrix","modelViewMatrix","projectionMatrix","normalMatrix","objectMatrix","cameraPosition","morphTargetInfluences"];c.useVertexTexture?d.push("boneTexture"): +d.push("boneGlobalMatrices");for(s in m)d.push(s);s=d;d=0;for(m=s.length;d=0&&g.enableVertexAttribArray(p.position);p.color>=0&&g.enableVertexAttribArray(p.color);p.normal>=0&&g.enableVertexAttribArray(p.normal);p.tangent>=0&&g.enableVertexAttribArray(p.tangent);if(a.skinning&&p.skinVertexA>=0&&p.skinVertexB>=0&&p.skinIndex>=0&&p.skinWeight>=0){g.enableVertexAttribArray(p.skinVertexA);g.enableVertexAttribArray(p.skinVertexB);g.enableVertexAttribArray(p.skinIndex);g.enableVertexAttribArray(p.skinWeight)}if(a.attributes)for(j in a.attributes)p[j]!== void 0&&p[j]>=0&&g.enableVertexAttribArray(p[j]);if(a.morphTargets){a.numSupportedMorphTargets=0;r="morphTarget";for(j=0;j=0){g.enableVertexAttribArray(p[s]);a.numSupportedMorphTargets++}}}if(a.morphNormals){a.numSupportedMorphNormals=0;r="morphNormal";for(j=0;j=0){g.enableVertexAttribArray(p[s]);a.numSupportedMorphNormals++}}}a.uniformsList=[];for(i in a.uniforms)a.uniformsList.push([a.uniforms[i],i])};this.setFaceCulling= function(a,b){if(a){!b||b==="ccw"?g.frontFace(g.CCW):g.frontFace(g.CW);a==="back"?g.cullFace(g.BACK):a==="front"?g.cullFace(g.FRONT):g.cullFace(g.FRONT_AND_BACK);g.enable(g.CULL_FACE)}else g.disable(g.CULL_FACE)};this.setObjectFaces=function(a){if(L!==a.doubleSided){a.doubleSided?g.disable(g.CULL_FACE):g.enable(g.CULL_FACE);L=a.doubleSided}if(qa!==a.flipSided){a.flipSided?g.frontFace(g.CW):g.frontFace(g.CCW);qa=a.flipSided}};this.setDepthTest=function(a){if(Ba!==a){a?g.enable(g.DEPTH_TEST):g.disable(g.DEPTH_TEST); Ba=a}};this.setDepthWrite=function(a){if(Qa!==a){g.depthMask(a);Qa=a}};this.setBlending=function(a,b,c,d){if(a!==xa){if(a===THREE.NoBlending)g.disable(g.BLEND);else if(a===THREE.AdditiveBlending){g.enable(g.BLEND);g.blendEquation(g.FUNC_ADD);g.blendFunc(g.SRC_ALPHA,g.ONE)}else if(a===THREE.SubtractiveBlending){g.enable(g.BLEND);g.blendEquation(g.FUNC_ADD);g.blendFunc(g.ZERO,g.ONE_MINUS_SRC_COLOR)}else if(a===THREE.MultiplyBlending){g.enable(g.BLEND);g.blendEquation(g.FUNC_ADD);g.blendFunc(g.ZERO, @@ -403,7 +403,7 @@ b);g.bindTexture(g.TEXTURE_2D,a.__webglTexture);g.pixelStorei(g.UNPACK_FLIP_Y_WE b);g.bindTexture(g.TEXTURE_2D,a.__webglTexture)}};this.setRenderTarget=function(a){var b=a instanceof THREE.WebGLRenderTargetCube;if(a&&!a.__webglFramebuffer){if(a.depthBuffer===void 0)a.depthBuffer=true;if(a.stencilBuffer===void 0)a.stencilBuffer=true;a.__webglTexture=g.createTexture();var c=(a.width&a.width-1)===0&&(a.height&a.height-1)===0,d=A(a.format),e=A(a.type);if(b){a.__webglFramebuffer=[];a.__webglRenderbuffer=[];g.bindTexture(g.TEXTURE_CUBE_MAP,a.__webglTexture);F(g.TEXTURE_CUBE_MAP,a,c); for(var f=0;f<6;f++){a.__webglFramebuffer[f]=g.createFramebuffer();a.__webglRenderbuffer[f]=g.createRenderbuffer();g.texImage2D(g.TEXTURE_CUBE_MAP_POSITIVE_X+f,0,d,a.width,a.height,0,d,e,null);var h=a,i=g.TEXTURE_CUBE_MAP_POSITIVE_X+f;g.bindFramebuffer(g.FRAMEBUFFER,a.__webglFramebuffer[f]);g.framebufferTexture2D(g.FRAMEBUFFER,g.COLOR_ATTACHMENT0,i,h.__webglTexture,0);s(a.__webglRenderbuffer[f],a)}c&&g.generateMipmap(g.TEXTURE_CUBE_MAP)}else{a.__webglFramebuffer=g.createFramebuffer();a.__webglRenderbuffer= g.createRenderbuffer();g.bindTexture(g.TEXTURE_2D,a.__webglTexture);F(g.TEXTURE_2D,a,c);g.texImage2D(g.TEXTURE_2D,0,d,a.width,a.height,0,d,e,null);d=g.TEXTURE_2D;g.bindFramebuffer(g.FRAMEBUFFER,a.__webglFramebuffer);g.framebufferTexture2D(g.FRAMEBUFFER,g.COLOR_ATTACHMENT0,d,a.__webglTexture,0);s(a.__webglRenderbuffer,a);c&&g.generateMipmap(g.TEXTURE_2D)}b?g.bindTexture(g.TEXTURE_CUBE_MAP,null):g.bindTexture(g.TEXTURE_2D,null);g.bindRenderbuffer(g.RENDERBUFFER,null);g.bindFramebuffer(g.FRAMEBUFFER, -null)}if(a){b=b?a.__webglFramebuffer[a.activeCubeFace]:a.__webglFramebuffer;c=a.width;a=a.height;e=d=0}else{b=null;c=hc;a=Nb;d=Ub;e=Lb}if(b!==ra){g.bindFramebuffer(g.FRAMEBUFFER,b);g.viewport(d,e,c,a);ra=b}wc=c;gc=a};this.shadowMapPlugin=new THREE.ShadowMapPlugin;this.addPrePlugin(this.shadowMapPlugin);this.addPostPlugin(new THREE.SpritePlugin);this.addPostPlugin(new THREE.LensFlarePlugin)}; +null)}if(a){b=b?a.__webglFramebuffer[a.activeCubeFace]:a.__webglFramebuffer;c=a.width;a=a.height;e=d=0}else{b=null;c=hc;a=Nb;d=Ub;e=fc}if(b!==ra){g.bindFramebuffer(g.FRAMEBUFFER,b);g.viewport(d,e,c,a);ra=b}wc=c;gc=a};this.shadowMapPlugin=new THREE.ShadowMapPlugin;this.addPrePlugin(this.shadowMapPlugin);this.addPostPlugin(new THREE.SpritePlugin);this.addPostPlugin(new THREE.LensFlarePlugin)}; THREE.WebGLRenderTarget=function(a,b,c){this.width=a;this.height=b;c=c||{};this.wrapS=c.wrapS!==void 0?c.wrapS:THREE.ClampToEdgeWrapping;this.wrapT=c.wrapT!==void 0?c.wrapT:THREE.ClampToEdgeWrapping;this.magFilter=c.magFilter!==void 0?c.magFilter:THREE.LinearFilter;this.minFilter=c.minFilter!==void 0?c.minFilter:THREE.LinearMipMapLinearFilter;this.offset=new THREE.Vector2(0,0);this.repeat=new THREE.Vector2(1,1);this.format=c.format!==void 0?c.format:THREE.RGBAFormat;this.type=c.type!==void 0?c.type: THREE.UnsignedByteType;this.depthBuffer=c.depthBuffer!==void 0?c.depthBuffer:true;this.stencilBuffer=c.stencilBuffer!==void 0?c.stencilBuffer:true;this.generateMipmaps=true}; THREE.WebGLRenderTarget.prototype.clone=function(){var a=new THREE.WebGLRenderTarget(this.width,this.height);a.wrapS=this.wrapS;a.wrapT=this.wrapT;a.magFilter=this.magFilter;a.minFilter=this.minFilter;a.offset.copy(this.offset);a.repeat.copy(this.repeat);a.format=this.format;a.type=this.type;a.depthBuffer=this.depthBuffer;a.stencilBuffer=this.stencilBuffer;return a};THREE.WebGLRenderTargetCube=function(a,b,c){THREE.WebGLRenderTarget.call(this,a,b,c);this.activeCubeFace=0}; diff --git a/examples/webgl_animation_skinning.html b/examples/webgl_animation_skinning.html index ff88b9aab7..e26fc278b0 100644 --- a/examples/webgl_animation_skinning.html +++ b/examples/webgl_animation_skinning.html @@ -165,7 +165,7 @@ for( z = 0; z < gridz; z ++ ) { - buffalo = new THREE.SkinnedMesh( geometry, material ); + buffalo = new THREE.SkinnedMesh( geometry, material, false ); //buffalo.doubleSided = true; diff --git a/src/objects/SkinnedMesh.js b/src/objects/SkinnedMesh.js index efb3f5884e..b2f490f3be 100644 --- a/src/objects/SkinnedMesh.js +++ b/src/objects/SkinnedMesh.js @@ -3,13 +3,13 @@ * @author alteredq / http://alteredqualia.com/ */ -THREE.SkinnedMesh = function ( geometry, material ) { +THREE.SkinnedMesh = function ( geometry, material, useVertexTexture ) { THREE.Mesh.call( this, geometry, material ); // - this.useVertexTexture = true; + this.useVertexTexture = useVertexTexture !== undefined ? useVertexTexture : true; // init bones diff --git a/src/renderers/WebGLRenderer.js b/src/renderers/WebGLRenderer.js index c781680cea..bb49428ed7 100644 --- a/src/renderers/WebGLRenderer.js +++ b/src/renderers/WebGLRenderer.js @@ -4526,6 +4526,7 @@ THREE.WebGLRenderer = function ( parameters ) { skinning: material.skinning, maxBones: maxBones, + useVertexTexture: _supportsBoneTextures && object.useVertexTexture, boneTextureWidth: object.boneTextureWidth, boneTextureHeight: object.boneTextureHeight, @@ -4799,7 +4800,7 @@ THREE.WebGLRenderer = function ( parameters ) { if ( material.skinning ) { - if ( _supportsBoneTextures ) { + if ( _supportsBoneTextures && object.useVertexTexture ) { if ( p_uniforms.boneTexture !== null ) { @@ -5698,7 +5699,7 @@ THREE.WebGLRenderer = function ( parameters ) { parameters.vertexColors ? "#define USE_COLOR" : "", parameters.skinning ? "#define USE_SKINNING" : "", - _supportsBoneTextures ? "#define BONE_TEXTURE" : "", + parameters.useVertexTexture ? "#define BONE_TEXTURE" : "", parameters.boneTextureWidth ? "#define N_BONE_PIXEL_X " + parameters.boneTextureWidth.toFixed( 1 ) : "", parameters.boneTextureHeight ? "#define N_BONE_PIXEL_Y " + parameters.boneTextureHeight.toFixed( 1 ) : "", @@ -5847,7 +5848,7 @@ THREE.WebGLRenderer = function ( parameters ) { ]; - if ( _supportsBoneTextures ) { + if ( parameters.useVertexTexture ) { identifiers.push( 'boneTexture' ); @@ -6390,7 +6391,7 @@ THREE.WebGLRenderer = function ( parameters ) { function allocateBones ( object ) { - if ( _supportsBoneTextures ) { + if ( _supportsBoneTextures && object.useVertexTexture ) { return 1024; -- GitLab