提交 34a42e26 编写于 作者: A alteredq

Fixed BufferGeometry sharing for large multi-chunk geometries.

Also extended CTMLoader example to test geometry sharing plus few other tweaks.

Fixes issue raised in comment to #2166
上级 bf56324e
......@@ -351,13 +351,13 @@ false,a=0;for(c=P.length;a<c;a++){d=P[a];if(d.program===b){d.usedTimes--;d.usedT
i.createBuffer();if(a.hasUvs&&!a.__webglUvBuffer)a.__webglUvBuffer=i.createBuffer();if(a.hasColors&&!a.__webglColorBuffer)a.__webglColorBuffer=i.createBuffer();if(a.hasPositions){i.bindBuffer(i.ARRAY_BUFFER,a.__webglVertexBuffer);i.bufferData(i.ARRAY_BUFFER,a.positionArray,i.DYNAMIC_DRAW);i.enableVertexAttribArray(b.attributes.position);i.vertexAttribPointer(b.attributes.position,3,i.FLOAT,false,0,0)}if(a.hasNormals){i.bindBuffer(i.ARRAY_BUFFER,a.__webglNormalBuffer);if(c.shading===THREE.FlatShading){var d,
e,f,g,h,k,j,l,m,n,o,r=a.count*3;for(o=0;o<r;o=o+9){n=a.normalArray;d=n[o];e=n[o+1];f=n[o+2];g=n[o+3];k=n[o+4];l=n[o+5];h=n[o+6];j=n[o+7];m=n[o+8];d=(d+g+h)/3;e=(e+k+j)/3;f=(f+l+m)/3;n[o]=d;n[o+1]=e;n[o+2]=f;n[o+3]=d;n[o+4]=e;n[o+5]=f;n[o+6]=d;n[o+7]=e;n[o+8]=f}}i.bufferData(i.ARRAY_BUFFER,a.normalArray,i.DYNAMIC_DRAW);i.enableVertexAttribArray(b.attributes.normal);i.vertexAttribPointer(b.attributes.normal,3,i.FLOAT,false,0,0)}if(a.hasUvs&&c.map){i.bindBuffer(i.ARRAY_BUFFER,a.__webglUvBuffer);i.bufferData(i.ARRAY_BUFFER,
a.uvArray,i.DYNAMIC_DRAW);i.enableVertexAttribArray(b.attributes.uv);i.vertexAttribPointer(b.attributes.uv,2,i.FLOAT,false,0,0)}if(a.hasColors&&c.vertexColors!==THREE.NoColors){i.bindBuffer(i.ARRAY_BUFFER,a.__webglColorBuffer);i.bufferData(i.ARRAY_BUFFER,a.colorArray,i.DYNAMIC_DRAW);i.enableVertexAttribArray(b.attributes.color);i.vertexAttribPointer(b.attributes.color,3,i.FLOAT,false,0,0)}i.drawArrays(i.TRIANGLES,0,a.count);a.count=0};this.renderBufferDirect=function(a,b,c,d,e,f){if(d.visible!==false){c=
q(a,b,c,d,f);a=c.attributes;b=false;d=e.id*16777215+c.id*2+(d.wireframe?1:0);if(d!==ca){ca=d;b=true}if(f instanceof THREE.Mesh){f=e.offsets;d=0;for(c=f.length;d<c;++d){if(b){var g=e.vertexPositionBuffer.itemSize;i.bindBuffer(i.ARRAY_BUFFER,e.vertexPositionBuffer);i.vertexAttribPointer(a.position,g,i.FLOAT,false,0,f[d].index*g*4);if(a.normal>=0&&e.vertexNormalBuffer){g=e.vertexNormalBuffer.itemSize;i.bindBuffer(i.ARRAY_BUFFER,e.vertexNormalBuffer);i.vertexAttribPointer(a.normal,g,i.FLOAT,false,0,f[d].index*
g*4)}if(a.uv>=0&&e.vertexUvBuffer)if(e.vertexUvBuffer){g=e.vertexUvBuffer.itemSize;i.bindBuffer(i.ARRAY_BUFFER,e.vertexUvBuffer);i.vertexAttribPointer(a.uv,g,i.FLOAT,false,0,f[d].index*g*4);i.enableVertexAttribArray(a.uv)}else i.disableVertexAttribArray(a.uv);if(a.color>=0&&e.vertexColorBuffer){g=e.vertexColorBuffer.itemSize;i.bindBuffer(i.ARRAY_BUFFER,e.vertexColorBuffer);i.vertexAttribPointer(a.color,g,i.FLOAT,false,0,f[d].index*g*4)}i.bindBuffer(i.ELEMENT_ARRAY_BUFFER,e.vertexIndexBuffer)}i.drawElements(i.TRIANGLES,
f[d].count,i.UNSIGNED_SHORT,f[d].start*2);D.info.render.calls++;D.info.render.vertices=D.info.render.vertices+f[d].count;D.info.render.faces=D.info.render.faces+f[d].count/3}}}};this.renderBuffer=function(a,b,c,d,e,f){if(d.visible!==false){var g,k,c=q(a,b,c,d,f),b=c.attributes,a=false,c=e.id*16777215+c.id*2+(d.wireframe?1:0);if(c!==ca){ca=c;a=true}if(!d.morphTargets&&b.position>=0){if(a){i.bindBuffer(i.ARRAY_BUFFER,e.__webglVertexBuffer);i.vertexAttribPointer(b.position,3,i.FLOAT,false,0,0)}}else if(f.morphTargetBase){c=
d.program.attributes;if(f.morphTargetBase!==-1){i.bindBuffer(i.ARRAY_BUFFER,e.__webglMorphTargetsBuffers[f.morphTargetBase]);i.vertexAttribPointer(c.position,3,i.FLOAT,false,0,0)}else if(c.position>=0){i.bindBuffer(i.ARRAY_BUFFER,e.__webglVertexBuffer);i.vertexAttribPointer(c.position,3,i.FLOAT,false,0,0)}if(f.morphTargetForcedOrder.length){var j=0;k=f.morphTargetForcedOrder;for(g=f.morphTargetInfluences;j<d.numSupportedMorphTargets&&j<k.length;){i.bindBuffer(i.ARRAY_BUFFER,e.__webglMorphTargetsBuffers[k[j]]);
i.vertexAttribPointer(c["morphTarget"+j],3,i.FLOAT,false,0,0);if(d.morphNormals){i.bindBuffer(i.ARRAY_BUFFER,e.__webglMorphNormalsBuffers[k[j]]);i.vertexAttribPointer(c["morphNormal"+j],3,i.FLOAT,false,0,0)}f.__webglMorphTargetInfluences[j]=g[k[j]];j++}}else{k=[];g=f.morphTargetInfluences;var l,m=g.length;for(l=0;l<m;l++){j=g[l];j>0&&k.push([l,j])}if(k.length>d.numSupportedMorphTargets){k.sort(h);k.length=d.numSupportedMorphTargets}else k.length>d.numSupportedMorphNormals?k.sort(h):k.length===0&&
k.push([0,0]);for(j=0;j<d.numSupportedMorphTargets;){if(k[j]){l=k[j][0];i.bindBuffer(i.ARRAY_BUFFER,e.__webglMorphTargetsBuffers[l]);i.vertexAttribPointer(c["morphTarget"+j],3,i.FLOAT,false,0,0);if(d.morphNormals){i.bindBuffer(i.ARRAY_BUFFER,e.__webglMorphNormalsBuffers[l]);i.vertexAttribPointer(c["morphNormal"+j],3,i.FLOAT,false,0,0)}f.__webglMorphTargetInfluences[j]=g[l]}else{i.vertexAttribPointer(c["morphTarget"+j],3,i.FLOAT,false,0,0);d.morphNormals&&i.vertexAttribPointer(c["morphNormal"+j],3,
i.FLOAT,false,0,0);f.__webglMorphTargetInfluences[j]=0}j++}}d.program.uniforms.morphTargetInfluences!==null&&i.uniform1fv(d.program.uniforms.morphTargetInfluences,f.__webglMorphTargetInfluences)}if(a){if(e.__webglCustomAttributesList){g=0;for(k=e.__webglCustomAttributesList.length;g<k;g++){c=e.__webglCustomAttributesList[g];if(b[c.buffer.belongsToAttribute]>=0){i.bindBuffer(i.ARRAY_BUFFER,c.buffer);i.vertexAttribPointer(b[c.buffer.belongsToAttribute],c.size,i.FLOAT,false,0,0)}}}if(b.color>=0){i.bindBuffer(i.ARRAY_BUFFER,
q(a,b,c,d,f);a=c.attributes;b=false;d=e.id*16777215+c.id*2+(d.wireframe?1:0);if(d!==ca){ca=d;b=true}if(f instanceof THREE.Mesh){f=e.offsets;f.length>1&&(b=true);d=0;for(c=f.length;d<c;++d){if(b){var g=e.vertexPositionBuffer.itemSize;i.bindBuffer(i.ARRAY_BUFFER,e.vertexPositionBuffer);i.vertexAttribPointer(a.position,g,i.FLOAT,false,0,f[d].index*g*4);if(a.normal>=0&&e.vertexNormalBuffer){g=e.vertexNormalBuffer.itemSize;i.bindBuffer(i.ARRAY_BUFFER,e.vertexNormalBuffer);i.vertexAttribPointer(a.normal,
g,i.FLOAT,false,0,f[d].index*g*4)}if(a.uv>=0&&e.vertexUvBuffer)if(e.vertexUvBuffer){g=e.vertexUvBuffer.itemSize;i.bindBuffer(i.ARRAY_BUFFER,e.vertexUvBuffer);i.vertexAttribPointer(a.uv,g,i.FLOAT,false,0,f[d].index*g*4);i.enableVertexAttribArray(a.uv)}else i.disableVertexAttribArray(a.uv);if(a.color>=0&&e.vertexColorBuffer){g=e.vertexColorBuffer.itemSize;i.bindBuffer(i.ARRAY_BUFFER,e.vertexColorBuffer);i.vertexAttribPointer(a.color,g,i.FLOAT,false,0,f[d].index*g*4)}i.bindBuffer(i.ELEMENT_ARRAY_BUFFER,
e.vertexIndexBuffer)}i.drawElements(i.TRIANGLES,f[d].count,i.UNSIGNED_SHORT,f[d].start*2);D.info.render.calls++;D.info.render.vertices=D.info.render.vertices+f[d].count;D.info.render.faces=D.info.render.faces+f[d].count/3}}}};this.renderBuffer=function(a,b,c,d,e,f){if(d.visible!==false){var g,k,c=q(a,b,c,d,f),b=c.attributes,a=false,c=e.id*16777215+c.id*2+(d.wireframe?1:0);if(c!==ca){ca=c;a=true}if(!d.morphTargets&&b.position>=0){if(a){i.bindBuffer(i.ARRAY_BUFFER,e.__webglVertexBuffer);i.vertexAttribPointer(b.position,
3,i.FLOAT,false,0,0)}}else if(f.morphTargetBase){c=d.program.attributes;if(f.morphTargetBase!==-1){i.bindBuffer(i.ARRAY_BUFFER,e.__webglMorphTargetsBuffers[f.morphTargetBase]);i.vertexAttribPointer(c.position,3,i.FLOAT,false,0,0)}else if(c.position>=0){i.bindBuffer(i.ARRAY_BUFFER,e.__webglVertexBuffer);i.vertexAttribPointer(c.position,3,i.FLOAT,false,0,0)}if(f.morphTargetForcedOrder.length){var j=0;k=f.morphTargetForcedOrder;for(g=f.morphTargetInfluences;j<d.numSupportedMorphTargets&&j<k.length;){i.bindBuffer(i.ARRAY_BUFFER,
e.__webglMorphTargetsBuffers[k[j]]);i.vertexAttribPointer(c["morphTarget"+j],3,i.FLOAT,false,0,0);if(d.morphNormals){i.bindBuffer(i.ARRAY_BUFFER,e.__webglMorphNormalsBuffers[k[j]]);i.vertexAttribPointer(c["morphNormal"+j],3,i.FLOAT,false,0,0)}f.__webglMorphTargetInfluences[j]=g[k[j]];j++}}else{k=[];g=f.morphTargetInfluences;var l,m=g.length;for(l=0;l<m;l++){j=g[l];j>0&&k.push([l,j])}if(k.length>d.numSupportedMorphTargets){k.sort(h);k.length=d.numSupportedMorphTargets}else k.length>d.numSupportedMorphNormals?
k.sort(h):k.length===0&&k.push([0,0]);for(j=0;j<d.numSupportedMorphTargets;){if(k[j]){l=k[j][0];i.bindBuffer(i.ARRAY_BUFFER,e.__webglMorphTargetsBuffers[l]);i.vertexAttribPointer(c["morphTarget"+j],3,i.FLOAT,false,0,0);if(d.morphNormals){i.bindBuffer(i.ARRAY_BUFFER,e.__webglMorphNormalsBuffers[l]);i.vertexAttribPointer(c["morphNormal"+j],3,i.FLOAT,false,0,0)}f.__webglMorphTargetInfluences[j]=g[l]}else{i.vertexAttribPointer(c["morphTarget"+j],3,i.FLOAT,false,0,0);d.morphNormals&&i.vertexAttribPointer(c["morphNormal"+
j],3,i.FLOAT,false,0,0);f.__webglMorphTargetInfluences[j]=0}j++}}d.program.uniforms.morphTargetInfluences!==null&&i.uniform1fv(d.program.uniforms.morphTargetInfluences,f.__webglMorphTargetInfluences)}if(a){if(e.__webglCustomAttributesList){g=0;for(k=e.__webglCustomAttributesList.length;g<k;g++){c=e.__webglCustomAttributesList[g];if(b[c.buffer.belongsToAttribute]>=0){i.bindBuffer(i.ARRAY_BUFFER,c.buffer);i.vertexAttribPointer(b[c.buffer.belongsToAttribute],c.size,i.FLOAT,false,0,0)}}}if(b.color>=0){i.bindBuffer(i.ARRAY_BUFFER,
e.__webglColorBuffer);i.vertexAttribPointer(b.color,3,i.FLOAT,false,0,0)}if(b.normal>=0){i.bindBuffer(i.ARRAY_BUFFER,e.__webglNormalBuffer);i.vertexAttribPointer(b.normal,3,i.FLOAT,false,0,0)}if(b.tangent>=0){i.bindBuffer(i.ARRAY_BUFFER,e.__webglTangentBuffer);i.vertexAttribPointer(b.tangent,4,i.FLOAT,false,0,0)}if(b.uv>=0)if(e.__webglUVBuffer){i.bindBuffer(i.ARRAY_BUFFER,e.__webglUVBuffer);i.vertexAttribPointer(b.uv,2,i.FLOAT,false,0,0);i.enableVertexAttribArray(b.uv)}else i.disableVertexAttribArray(b.uv);
if(b.uv2>=0)if(e.__webglUV2Buffer){i.bindBuffer(i.ARRAY_BUFFER,e.__webglUV2Buffer);i.vertexAttribPointer(b.uv2,2,i.FLOAT,false,0,0);i.enableVertexAttribArray(b.uv2)}else i.disableVertexAttribArray(b.uv2);if(d.skinning&&b.skinVertexA>=0&&b.skinVertexB>=0&&b.skinIndex>=0&&b.skinWeight>=0){i.bindBuffer(i.ARRAY_BUFFER,e.__webglSkinVertexABuffer);i.vertexAttribPointer(b.skinVertexA,4,i.FLOAT,false,0,0);i.bindBuffer(i.ARRAY_BUFFER,e.__webglSkinVertexBBuffer);i.vertexAttribPointer(b.skinVertexB,4,i.FLOAT,
false,0,0);i.bindBuffer(i.ARRAY_BUFFER,e.__webglSkinIndicesBuffer);i.vertexAttribPointer(b.skinIndex,4,i.FLOAT,false,0,0);i.bindBuffer(i.ARRAY_BUFFER,e.__webglSkinWeightsBuffer);i.vertexAttribPointer(b.skinWeight,4,i.FLOAT,false,0,0)}}if(f instanceof THREE.Mesh){if(d.wireframe){d=d.wireframeLinewidth;if(d!==$a){i.lineWidth(d);$a=d}a&&i.bindBuffer(i.ELEMENT_ARRAY_BUFFER,e.__webglLineBuffer);i.drawElements(i.LINES,e.__webglLineCount,i.UNSIGNED_SHORT,0)}else{a&&i.bindBuffer(i.ELEMENT_ARRAY_BUFFER,e.__webglFaceBuffer);
......
......@@ -313,13 +313,13 @@ false,a=0;for(c=X.length;a<c;a++){d=X[a];if(d.program===b){d.usedTimes--;d.usedT
g.createBuffer();if(a.hasUvs&&!a.__webglUvBuffer)a.__webglUvBuffer=g.createBuffer();if(a.hasColors&&!a.__webglColorBuffer)a.__webglColorBuffer=g.createBuffer();if(a.hasPositions){g.bindBuffer(g.ARRAY_BUFFER,a.__webglVertexBuffer);g.bufferData(g.ARRAY_BUFFER,a.positionArray,g.DYNAMIC_DRAW);g.enableVertexAttribArray(b.attributes.position);g.vertexAttribPointer(b.attributes.position,3,g.FLOAT,false,0,0)}if(a.hasNormals){g.bindBuffer(g.ARRAY_BUFFER,a.__webglNormalBuffer);if(c.shading===THREE.FlatShading){var d,
e,f,h,i,j,l,k,m,n,o,r=a.count*3;for(o=0;o<r;o=o+9){n=a.normalArray;d=n[o];e=n[o+1];f=n[o+2];h=n[o+3];j=n[o+4];k=n[o+5];i=n[o+6];l=n[o+7];m=n[o+8];d=(d+h+i)/3;e=(e+j+l)/3;f=(f+k+m)/3;n[o]=d;n[o+1]=e;n[o+2]=f;n[o+3]=d;n[o+4]=e;n[o+5]=f;n[o+6]=d;n[o+7]=e;n[o+8]=f}}g.bufferData(g.ARRAY_BUFFER,a.normalArray,g.DYNAMIC_DRAW);g.enableVertexAttribArray(b.attributes.normal);g.vertexAttribPointer(b.attributes.normal,3,g.FLOAT,false,0,0)}if(a.hasUvs&&c.map){g.bindBuffer(g.ARRAY_BUFFER,a.__webglUvBuffer);g.bufferData(g.ARRAY_BUFFER,
a.uvArray,g.DYNAMIC_DRAW);g.enableVertexAttribArray(b.attributes.uv);g.vertexAttribPointer(b.attributes.uv,2,g.FLOAT,false,0,0)}if(a.hasColors&&c.vertexColors!==THREE.NoColors){g.bindBuffer(g.ARRAY_BUFFER,a.__webglColorBuffer);g.bufferData(g.ARRAY_BUFFER,a.colorArray,g.DYNAMIC_DRAW);g.enableVertexAttribArray(b.attributes.color);g.vertexAttribPointer(b.attributes.color,3,g.FLOAT,false,0,0)}g.drawArrays(g.TRIANGLES,0,a.count);a.count=0};this.renderBufferDirect=function(a,b,c,d,e,f){if(d.visible!==false){c=
q(a,b,c,d,f);a=c.attributes;b=false;d=e.id*16777215+c.id*2+(d.wireframe?1:0);if(d!==ca){ca=d;b=true}if(f instanceof THREE.Mesh){f=e.offsets;d=0;for(c=f.length;d<c;++d){if(b){var h=e.vertexPositionBuffer.itemSize;g.bindBuffer(g.ARRAY_BUFFER,e.vertexPositionBuffer);g.vertexAttribPointer(a.position,h,g.FLOAT,false,0,f[d].index*h*4);if(a.normal>=0&&e.vertexNormalBuffer){h=e.vertexNormalBuffer.itemSize;g.bindBuffer(g.ARRAY_BUFFER,e.vertexNormalBuffer);g.vertexAttribPointer(a.normal,h,g.FLOAT,false,0,f[d].index*
h*4)}if(a.uv>=0&&e.vertexUvBuffer)if(e.vertexUvBuffer){h=e.vertexUvBuffer.itemSize;g.bindBuffer(g.ARRAY_BUFFER,e.vertexUvBuffer);g.vertexAttribPointer(a.uv,h,g.FLOAT,false,0,f[d].index*h*4);g.enableVertexAttribArray(a.uv)}else g.disableVertexAttribArray(a.uv);if(a.color>=0&&e.vertexColorBuffer){h=e.vertexColorBuffer.itemSize;g.bindBuffer(g.ARRAY_BUFFER,e.vertexColorBuffer);g.vertexAttribPointer(a.color,h,g.FLOAT,false,0,f[d].index*h*4)}g.bindBuffer(g.ELEMENT_ARRAY_BUFFER,e.vertexIndexBuffer)}g.drawElements(g.TRIANGLES,
f[d].count,g.UNSIGNED_SHORT,f[d].start*2);F.info.render.calls++;F.info.render.vertices=F.info.render.vertices+f[d].count;F.info.render.faces=F.info.render.faces+f[d].count/3}}}};this.renderBuffer=function(a,b,c,d,e,f){if(d.visible!==false){var h,i,c=q(a,b,c,d,f),b=c.attributes,a=false,c=e.id*16777215+c.id*2+(d.wireframe?1:0);if(c!==ca){ca=c;a=true}if(!d.morphTargets&&b.position>=0){if(a){g.bindBuffer(g.ARRAY_BUFFER,e.__webglVertexBuffer);g.vertexAttribPointer(b.position,3,g.FLOAT,false,0,0)}}else if(f.morphTargetBase){c=
d.program.attributes;if(f.morphTargetBase!==-1){g.bindBuffer(g.ARRAY_BUFFER,e.__webglMorphTargetsBuffers[f.morphTargetBase]);g.vertexAttribPointer(c.position,3,g.FLOAT,false,0,0)}else if(c.position>=0){g.bindBuffer(g.ARRAY_BUFFER,e.__webglVertexBuffer);g.vertexAttribPointer(c.position,3,g.FLOAT,false,0,0)}if(f.morphTargetForcedOrder.length){var j=0;i=f.morphTargetForcedOrder;for(h=f.morphTargetInfluences;j<d.numSupportedMorphTargets&&j<i.length;){g.bindBuffer(g.ARRAY_BUFFER,e.__webglMorphTargetsBuffers[i[j]]);
g.vertexAttribPointer(c["morphTarget"+j],3,g.FLOAT,false,0,0);if(d.morphNormals){g.bindBuffer(g.ARRAY_BUFFER,e.__webglMorphNormalsBuffers[i[j]]);g.vertexAttribPointer(c["morphNormal"+j],3,g.FLOAT,false,0,0)}f.__webglMorphTargetInfluences[j]=h[i[j]];j++}}else{i=[];h=f.morphTargetInfluences;var k,m=h.length;for(k=0;k<m;k++){j=h[k];j>0&&i.push([k,j])}if(i.length>d.numSupportedMorphTargets){i.sort(l);i.length=d.numSupportedMorphTargets}else i.length>d.numSupportedMorphNormals?i.sort(l):i.length===0&&
i.push([0,0]);for(j=0;j<d.numSupportedMorphTargets;){if(i[j]){k=i[j][0];g.bindBuffer(g.ARRAY_BUFFER,e.__webglMorphTargetsBuffers[k]);g.vertexAttribPointer(c["morphTarget"+j],3,g.FLOAT,false,0,0);if(d.morphNormals){g.bindBuffer(g.ARRAY_BUFFER,e.__webglMorphNormalsBuffers[k]);g.vertexAttribPointer(c["morphNormal"+j],3,g.FLOAT,false,0,0)}f.__webglMorphTargetInfluences[j]=h[k]}else{g.vertexAttribPointer(c["morphTarget"+j],3,g.FLOAT,false,0,0);d.morphNormals&&g.vertexAttribPointer(c["morphNormal"+j],3,
g.FLOAT,false,0,0);f.__webglMorphTargetInfluences[j]=0}j++}}d.program.uniforms.morphTargetInfluences!==null&&g.uniform1fv(d.program.uniforms.morphTargetInfluences,f.__webglMorphTargetInfluences)}if(a){if(e.__webglCustomAttributesList){h=0;for(i=e.__webglCustomAttributesList.length;h<i;h++){c=e.__webglCustomAttributesList[h];if(b[c.buffer.belongsToAttribute]>=0){g.bindBuffer(g.ARRAY_BUFFER,c.buffer);g.vertexAttribPointer(b[c.buffer.belongsToAttribute],c.size,g.FLOAT,false,0,0)}}}if(b.color>=0){g.bindBuffer(g.ARRAY_BUFFER,
q(a,b,c,d,f);a=c.attributes;b=false;d=e.id*16777215+c.id*2+(d.wireframe?1:0);if(d!==ca){ca=d;b=true}if(f instanceof THREE.Mesh){f=e.offsets;f.length>1&&(b=true);d=0;for(c=f.length;d<c;++d){if(b){var h=e.vertexPositionBuffer.itemSize;g.bindBuffer(g.ARRAY_BUFFER,e.vertexPositionBuffer);g.vertexAttribPointer(a.position,h,g.FLOAT,false,0,f[d].index*h*4);if(a.normal>=0&&e.vertexNormalBuffer){h=e.vertexNormalBuffer.itemSize;g.bindBuffer(g.ARRAY_BUFFER,e.vertexNormalBuffer);g.vertexAttribPointer(a.normal,
h,g.FLOAT,false,0,f[d].index*h*4)}if(a.uv>=0&&e.vertexUvBuffer)if(e.vertexUvBuffer){h=e.vertexUvBuffer.itemSize;g.bindBuffer(g.ARRAY_BUFFER,e.vertexUvBuffer);g.vertexAttribPointer(a.uv,h,g.FLOAT,false,0,f[d].index*h*4);g.enableVertexAttribArray(a.uv)}else g.disableVertexAttribArray(a.uv);if(a.color>=0&&e.vertexColorBuffer){h=e.vertexColorBuffer.itemSize;g.bindBuffer(g.ARRAY_BUFFER,e.vertexColorBuffer);g.vertexAttribPointer(a.color,h,g.FLOAT,false,0,f[d].index*h*4)}g.bindBuffer(g.ELEMENT_ARRAY_BUFFER,
e.vertexIndexBuffer)}g.drawElements(g.TRIANGLES,f[d].count,g.UNSIGNED_SHORT,f[d].start*2);F.info.render.calls++;F.info.render.vertices=F.info.render.vertices+f[d].count;F.info.render.faces=F.info.render.faces+f[d].count/3}}}};this.renderBuffer=function(a,b,c,d,e,f){if(d.visible!==false){var h,i,c=q(a,b,c,d,f),b=c.attributes,a=false,c=e.id*16777215+c.id*2+(d.wireframe?1:0);if(c!==ca){ca=c;a=true}if(!d.morphTargets&&b.position>=0){if(a){g.bindBuffer(g.ARRAY_BUFFER,e.__webglVertexBuffer);g.vertexAttribPointer(b.position,
3,g.FLOAT,false,0,0)}}else if(f.morphTargetBase){c=d.program.attributes;if(f.morphTargetBase!==-1){g.bindBuffer(g.ARRAY_BUFFER,e.__webglMorphTargetsBuffers[f.morphTargetBase]);g.vertexAttribPointer(c.position,3,g.FLOAT,false,0,0)}else if(c.position>=0){g.bindBuffer(g.ARRAY_BUFFER,e.__webglVertexBuffer);g.vertexAttribPointer(c.position,3,g.FLOAT,false,0,0)}if(f.morphTargetForcedOrder.length){var j=0;i=f.morphTargetForcedOrder;for(h=f.morphTargetInfluences;j<d.numSupportedMorphTargets&&j<i.length;){g.bindBuffer(g.ARRAY_BUFFER,
e.__webglMorphTargetsBuffers[i[j]]);g.vertexAttribPointer(c["morphTarget"+j],3,g.FLOAT,false,0,0);if(d.morphNormals){g.bindBuffer(g.ARRAY_BUFFER,e.__webglMorphNormalsBuffers[i[j]]);g.vertexAttribPointer(c["morphNormal"+j],3,g.FLOAT,false,0,0)}f.__webglMorphTargetInfluences[j]=h[i[j]];j++}}else{i=[];h=f.morphTargetInfluences;var k,m=h.length;for(k=0;k<m;k++){j=h[k];j>0&&i.push([k,j])}if(i.length>d.numSupportedMorphTargets){i.sort(l);i.length=d.numSupportedMorphTargets}else i.length>d.numSupportedMorphNormals?
i.sort(l):i.length===0&&i.push([0,0]);for(j=0;j<d.numSupportedMorphTargets;){if(i[j]){k=i[j][0];g.bindBuffer(g.ARRAY_BUFFER,e.__webglMorphTargetsBuffers[k]);g.vertexAttribPointer(c["morphTarget"+j],3,g.FLOAT,false,0,0);if(d.morphNormals){g.bindBuffer(g.ARRAY_BUFFER,e.__webglMorphNormalsBuffers[k]);g.vertexAttribPointer(c["morphNormal"+j],3,g.FLOAT,false,0,0)}f.__webglMorphTargetInfluences[j]=h[k]}else{g.vertexAttribPointer(c["morphTarget"+j],3,g.FLOAT,false,0,0);d.morphNormals&&g.vertexAttribPointer(c["morphNormal"+
j],3,g.FLOAT,false,0,0);f.__webglMorphTargetInfluences[j]=0}j++}}d.program.uniforms.morphTargetInfluences!==null&&g.uniform1fv(d.program.uniforms.morphTargetInfluences,f.__webglMorphTargetInfluences)}if(a){if(e.__webglCustomAttributesList){h=0;for(i=e.__webglCustomAttributesList.length;h<i;h++){c=e.__webglCustomAttributesList[h];if(b[c.buffer.belongsToAttribute]>=0){g.bindBuffer(g.ARRAY_BUFFER,c.buffer);g.vertexAttribPointer(b[c.buffer.belongsToAttribute],c.size,g.FLOAT,false,0,0)}}}if(b.color>=0){g.bindBuffer(g.ARRAY_BUFFER,
e.__webglColorBuffer);g.vertexAttribPointer(b.color,3,g.FLOAT,false,0,0)}if(b.normal>=0){g.bindBuffer(g.ARRAY_BUFFER,e.__webglNormalBuffer);g.vertexAttribPointer(b.normal,3,g.FLOAT,false,0,0)}if(b.tangent>=0){g.bindBuffer(g.ARRAY_BUFFER,e.__webglTangentBuffer);g.vertexAttribPointer(b.tangent,4,g.FLOAT,false,0,0)}if(b.uv>=0)if(e.__webglUVBuffer){g.bindBuffer(g.ARRAY_BUFFER,e.__webglUVBuffer);g.vertexAttribPointer(b.uv,2,g.FLOAT,false,0,0);g.enableVertexAttribArray(b.uv)}else g.disableVertexAttribArray(b.uv);
if(b.uv2>=0)if(e.__webglUV2Buffer){g.bindBuffer(g.ARRAY_BUFFER,e.__webglUV2Buffer);g.vertexAttribPointer(b.uv2,2,g.FLOAT,false,0,0);g.enableVertexAttribArray(b.uv2)}else g.disableVertexAttribArray(b.uv2);if(d.skinning&&b.skinVertexA>=0&&b.skinVertexB>=0&&b.skinIndex>=0&&b.skinWeight>=0){g.bindBuffer(g.ARRAY_BUFFER,e.__webglSkinVertexABuffer);g.vertexAttribPointer(b.skinVertexA,4,g.FLOAT,false,0,0);g.bindBuffer(g.ARRAY_BUFFER,e.__webglSkinVertexBBuffer);g.vertexAttribPointer(b.skinVertexB,4,g.FLOAT,
false,0,0);g.bindBuffer(g.ARRAY_BUFFER,e.__webglSkinIndicesBuffer);g.vertexAttribPointer(b.skinIndex,4,g.FLOAT,false,0,0);g.bindBuffer(g.ARRAY_BUFFER,e.__webglSkinWeightsBuffer);g.vertexAttribPointer(b.skinWeight,4,g.FLOAT,false,0,0)}}if(f instanceof THREE.Mesh){if(d.wireframe){d=d.wireframeLinewidth;if(d!==Ib){g.lineWidth(d);Ib=d}a&&g.bindBuffer(g.ELEMENT_ARRAY_BUFFER,e.__webglLineBuffer);g.drawElements(g.LINES,e.__webglLineCount,g.UNSIGNED_SHORT,0)}else{a&&g.bindBuffer(g.ELEMENT_ARRAY_BUFFER,e.__webglFaceBuffer);
......
......@@ -90,12 +90,23 @@
// LIGHTS
var ambient = new THREE.AmbientLight( 0x050505 );
scene.add( ambient );
var ambient = new THREE.AmbientLight( 0x080808 );
//scene.add( ambient );
var directionalLight = new THREE.DirectionalLight( 0xffeedd );
directionalLight.position.set( 0, 0, 1 ).normalize();
scene.add( directionalLight );
var light = new THREE.SpotLight( 0xffeedd, 1.2, 650, 2.5, 3 );
light.position.set( 0, -100, 500 );
light.castShadow = true;
light.shadowMapWidth = 2048;
light.shadowMapHeight = 2048;
light.shadowCameraFov = 45;
//light.shadowCameraVisible = true;
scene.add( light );
var light = new THREE.DirectionalLight( 0xffeedd, 0.25 );
light.position.set( 0, -50, 200 );
//scene.add( light );
// RENDERER
......@@ -111,6 +122,9 @@
renderer.gammaInput = true;
renderer.gammaOutput = true;
renderer.physicallyBasedShading = true;
renderer.shadowMapEnabled = true;
// STATS
......@@ -120,6 +134,10 @@
stats.domElement.style.zIndex = 100;
container.appendChild( stats.domElement );
stats.domElement.children[ 0 ].children[ 0 ].style.color = "#aaa";
stats.domElement.children[ 0 ].style.background = "transparent";
stats.domElement.children[ 0 ].children[ 1 ].style.display = "none";
// EVENTS
window.addEventListener( 'resize', onWindowResize, false );
......@@ -158,15 +176,22 @@
//geometry.computeVertexNormals();
var material = new THREE.MeshLambertMaterial( { color: 0xffffff, envMaps: reflectionCube, combine: THREE.MixOperation, reflectivity: 0.3 } );
callbackModel( geometry, 5, material, -200, 0, 0, 0, 0 );
var material1 = new THREE.MeshLambertMaterial( { color: 0xffffff } );
var material2 = new THREE.MeshPhongMaterial( { color: 0xff4400, specular: 0x333333, shininess: 100 } );
var material3 = new THREE.MeshPhongMaterial( { color: 0x00ff44, specular: 0x333333, shininess: 100 } );
callbackModel( geometry, 5, material1, -200, 0, 0, 0, 0 );
callbackModel( geometry, 2, material2, 100, 0, 125, 0, 0 );
callbackModel( geometry, 2, material3, -100, 0, 125, 0, 0 );
checkTime();
}, useWorker, useBuffers );
loader.load( "models/ctm/LeePerry.ctm", function( geometry ) {
var material = new THREE.MeshPhongMaterial( { color: 0xffffff, specular: 0x444444, shininess: 30, map: THREE.ImageUtils.loadTexture( "obj/leeperrysmith/Map-COL.jpg" ), envMaps: reflectionCube, combine: THREE.MixOperation, reflectivity: 0.3 } );
var material = new THREE.MeshPhongMaterial( { wrapAround: true, color: 0xffffff, specular: 0x232323, shininess: 50, map: THREE.ImageUtils.loadTexture( "obj/leeperrysmith/Map-COL.jpg" ) } );
material.wrapRGB.set( 0.65, 0.5, 0.5 );
callbackModel( geometry, 1300, material, 200, 50, 0, 0, 0 );
checkTime();
......@@ -182,7 +207,9 @@
mesh.scale.set( s, s, s );
mesh.rotation.x = rx;
mesh.rotation.z = ry;
//mesh.flipSided = true;
mesh.castShadow = true;
mesh.receiveShadow = true;
scene.add( mesh );
......
......@@ -3050,6 +3050,12 @@ THREE.WebGLRenderer = function ( parameters ) {
var offsets = geometryGroup.offsets;
// if there is more than 1 chunk
// must set vertexAttribPointer to use new offsets for each chunk
// even if geometry and materials didn't change
if ( offsets.length > 1 ) updateBuffers = true;
for ( var i = 0, il = offsets.length; i < il; ++ i ) {
if ( updateBuffers ) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册