提交 1be08e8a 编写于 作者: M Mr.doob

WebGLRenderer: Added `deallocateObject` and `deallocateTexture` methods.

上级 42c62641
因为 它太大了无法显示 source diff 。你可以改为 查看blob
此差异已折叠。
此差异已折叠。
......@@ -37,7 +37,7 @@ this.getPrevKeyWith("pos",p,g.index-1).pos,this.points[1]=f,this.points[2]=h,thi
THREE.Animation.prototype.interpolateCatmullRom=function(a,b){var c=[],e=[],f,h,g,j,k,l;f=(a.length-1)*b;h=Math.floor(f);f-=h;c[0]=h==0?h:h-1;c[1]=h;c[2]=h>a.length-2?h:h+1;c[3]=h>a.length-3?h:h+2;h=a[c[0]];j=a[c[1]];k=a[c[2]];l=a[c[3]];c=f*f;g=f*c;e[0]=this.interpolate(h[0],j[0],k[0],l[0],f,c,g);e[1]=this.interpolate(h[1],j[1],k[1],l[1],f,c,g);e[2]=this.interpolate(h[2],j[2],k[2],l[2],f,c,g);return e};
THREE.Animation.prototype.interpolate=function(a,b,c,e,f,h,g){a=(c-a)*0.5;e=(e-b)*0.5;return(2*(b-c)+a+e)*g+(-3*(b-c)-2*a-e)*h+a*f+b};THREE.Animation.prototype.getNextKeyWith=function(a,b,c){var e=this.data.hierarchy[b].keys;for(this.interpolationType===THREE.AnimationHandler.CATMULLROM||this.interpolationType===THREE.AnimationHandler.CATMULLROM_FORWARD?c=c<e.length-1?c:e.length-1:c%=e.length;c<e.length;c++)if(e[c][a]!==void 0)return e[c];return this.data.hierarchy[b].keys[0]};
THREE.Animation.prototype.getPrevKeyWith=function(a,b,c){for(var e=this.data.hierarchy[b].keys,c=this.interpolationType===THREE.AnimationHandler.CATMULLROM||this.interpolationType===THREE.AnimationHandler.CATMULLROM_FORWARD?c>0?c:0:c>=0?c:c+e.length;c>=0;c--)if(e[c][a]!==void 0)return e[c];return this.data.hierarchy[b].keys[e.length-1]};
THREE.FirstPersonCamera=function(a){function b(a,b){return function(){b.apply(a,arguments)}}THREE.Camera.call(this,a.fov,a.aspect,a.near,a.far,a.target);this.movementSpeed=1;this.lookSpeed=0.0050;this.noFly=!1;this.lookVertical=!0;this.autoForward=!1;this.activeLook=!0;this.heightSpeed=!1;this.heightCoef=1;this.heightMin=0;this.constrainVertical=!1;this.verticalMin=0;this.verticalMax=3.14;this.domElement=document;this.lastUpdate=(new Date).getTime();this.tdiff=0;if(a){if(a.movementSpeed!==void 0)this.movementSpeed=
THREE.FirstPersonCamera=function(a){function b(a,b){return function(){b.apply(a,arguments)}}THREE.Camera.call(this,a.fov,a.aspect,a.near,a.far,a.target);this.movementSpeed=1;this.lookSpeed=0.005;this.noFly=!1;this.lookVertical=!0;this.autoForward=!1;this.activeLook=!0;this.heightSpeed=!1;this.heightCoef=1;this.heightMin=0;this.constrainVertical=!1;this.verticalMin=0;this.verticalMax=3.14;this.domElement=document;this.lastUpdate=(new Date).getTime();this.tdiff=0;if(a){if(a.movementSpeed!==void 0)this.movementSpeed=
a.movementSpeed;if(a.lookSpeed!==void 0)this.lookSpeed=a.lookSpeed;if(a.noFly!==void 0)this.noFly=a.noFly;if(a.lookVertical!==void 0)this.lookVertical=a.lookVertical;if(a.autoForward!==void 0)this.autoForward=a.autoForward;if(a.activeLook!==void 0)this.activeLook=a.activeLook;if(a.heightSpeed!==void 0)this.heightSpeed=a.heightSpeed;if(a.heightCoef!==void 0)this.heightCoef=a.heightCoef;if(a.heightMin!==void 0)this.heightMin=a.heightMin;if(a.heightMax!==void 0)this.heightMax=a.heightMax;if(a.constrainVertical!==
void 0)this.constrainVertical=a.constrainVertical;if(a.verticalMin!==void 0)this.verticalMin=a.verticalMin;if(a.verticalMax!==void 0)this.verticalMax=a.verticalMax;if(a.domElement!==void 0)this.domElement=a.domElement}this.theta=this.phi=this.lon=this.lat=this.mouseY=this.mouseX=this.autoSpeedFactor=0;this.mouseDragOn=this.freeze=this.moveRight=this.moveLeft=this.moveBackward=this.moveForward=!1;this.windowHalfX=window.innerWidth/2;this.windowHalfY=window.innerHeight/2;this.onMouseDown=function(a){a.preventDefault();
a.stopPropagation();if(this.activeLook)switch(a.button){case 0:this.moveForward=!0;break;case 2:this.moveBackward=!0}this.mouseDragOn=!0};this.onMouseUp=function(a){a.preventDefault();a.stopPropagation();if(this.activeLook)switch(a.button){case 0:this.moveForward=!1;break;case 2:this.moveBackward=!1}this.mouseDragOn=!1};this.onMouseMove=function(a){this.mouseX=a.clientX-this.windowHalfX;this.mouseY=a.clientY-this.windowHalfY};this.onKeyDown=function(a){switch(a.keyCode){case 38:case 87:this.moveForward=
......@@ -49,7 +49,7 @@ Math.sin(this.theta);this.supr.update.call(this)};this.domElement.addEventListen
THREE.FirstPersonCamera.prototype=new THREE.Camera;THREE.FirstPersonCamera.prototype.constructor=THREE.FirstPersonCamera;THREE.FirstPersonCamera.prototype.supr=THREE.Camera.prototype;THREE.FirstPersonCamera.prototype.translate=function(a,b){this.matrix.rotateAxis(b);if(this.noFly)b.y=0;this.position.addSelf(b.multiplyScalar(a));this.target.position.addSelf(b.multiplyScalar(a))};
THREE.PathCamera=function(a){function b(a,c,b,e){var g={name:b,fps:0.6,length:e,hierarchy:[]},h,f=c.getControlPointsArray(),j=c.getLength(),k=f.length,x=0;h=k-1;c={parent:-1,keys:[]};c.keys[0]={time:0,pos:f[0],rot:[0,0,0,1],scl:[1,1,1]};c.keys[h]={time:e,pos:f[h],rot:[0,0,0,1],scl:[1,1,1]};for(h=1;h<k-1;h++)x=e*j.chunks[h]/j.total,c.keys[h]={time:x,pos:f[h]};g.hierarchy[0]=c;THREE.AnimationHandler.add(g);return new THREE.Animation(a,b,THREE.AnimationHandler.CATMULLROM_FORWARD,!1)}function c(a,c){var b,
e,g=new THREE.Geometry;for(b=0;b<a.points.length*c;b++)e=b/(a.points.length*c),e=a.getPoint(e),g.vertices[b]=new THREE.Vertex(new THREE.Vector3(e.x,e.y,e.z));return g}function e(a,b){var e=c(b,10),g=c(b,10),h=new THREE.LineBasicMaterial({color:16711680,linewidth:3});lineObj=new THREE.Line(e,h);particleObj=new THREE.ParticleSystem(g,new THREE.ParticleBasicMaterial({color:16755200,size:3}));lineObj.scale.set(1,1,1);a.addChild(lineObj);particleObj.scale.set(1,1,1);a.addChild(particleObj);g=new THREE.SphereGeometry(1,
16,8);h=new THREE.MeshBasicMaterial({color:65280});for(i=0;i<b.points.length;i++)e=new THREE.Mesh(g,h),e.position.copy(b.points[i]),e.updateMatrix(),a.addChild(e)}THREE.Camera.call(this,a.fov,a.aspect,a.near,a.far,a.target);this.id="PathCamera"+THREE.PathCameraIdCounter++;this.duration=1E4;this.waypoints=[];this.useConstantSpeed=!0;this.resamplingCoef=50;this.debugPath=new THREE.Object3D;this.debugDummy=new THREE.Object3D;this.animationParent=new THREE.Object3D;this.lookSpeed=0.0050;this.lookHorizontal=
16,8);h=new THREE.MeshBasicMaterial({color:65280});for(i=0;i<b.points.length;i++)e=new THREE.Mesh(g,h),e.position.copy(b.points[i]),e.updateMatrix(),a.addChild(e)}THREE.Camera.call(this,a.fov,a.aspect,a.near,a.far,a.target);this.id="PathCamera"+THREE.PathCameraIdCounter++;this.duration=1E4;this.waypoints=[];this.useConstantSpeed=!0;this.resamplingCoef=50;this.debugPath=new THREE.Object3D;this.debugDummy=new THREE.Object3D;this.animationParent=new THREE.Object3D;this.lookSpeed=0.005;this.lookHorizontal=
this.lookVertical=!0;this.verticalAngleMap={srcRange:[0,6.28],dstRange:[0,6.28]};this.horizontalAngleMap={srcRange:[0,6.28],dstRange:[0,6.28]};this.domElement=document;if(a){if(a.duration!==void 0)this.duration=a.duration*1E3;if(a.waypoints!==void 0)this.waypoints=a.waypoints;if(a.useConstantSpeed!==void 0)this.useConstantSpeed=a.useConstantSpeed;if(a.resamplingCoef!==void 0)this.resamplingCoef=a.resamplingCoef;if(a.createDebugPath!==void 0)this.createDebugPath=a.createDebugPath;if(a.createDebugDummy!==
void 0)this.createDebugDummy=a.createDebugDummy;if(a.lookSpeed!==void 0)this.lookSpeed=a.lookSpeed;if(a.lookVertical!==void 0)this.lookVertical=a.lookVertical;if(a.lookHorizontal!==void 0)this.lookHorizontal=a.lookHorizontal;if(a.verticalAngleMap!==void 0)this.verticalAngleMap=a.verticalAngleMap;if(a.horizontalAngleMap!==void 0)this.horizontalAngleMap=a.horizontalAngleMap;if(a.domElement!==void 0)this.domElement=a.domElement}this.theta=this.phi=this.lon=this.lat=this.mouseY=this.mouseX=0;this.windowHalfX=
window.innerWidth/2;this.windowHalfY=window.innerHeight/2;var f=Math.PI*2,h=Math.PI/180;this.update=function(a,c,b){var e,g;this.lookHorizontal&&(this.lon+=this.mouseX*this.lookSpeed);this.lookVertical&&(this.lat-=this.mouseY*this.lookSpeed);this.lon=Math.max(0,Math.min(360,this.lon));this.lat=Math.max(-85,Math.min(85,this.lat));this.phi=(90-this.lat)*h;this.theta=this.lon*h;e=this.phi%f;this.phi=e>=0?e:e+f;e=this.verticalAngleMap.srcRange;g=this.verticalAngleMap.dstRange;var j=g[1]-g[0];this.phi=
......@@ -57,7 +57,7 @@ TWEEN.Easing.Quadratic.EaseInOut(((this.phi-e[0])*(g[1]-g[0])/(e[1]-e[0])+g[0]-g
a.clientX-this.windowHalfX;this.mouseY=a.clientY-this.windowHalfY};this.spline=new THREE.Spline;this.spline.initFromArray(this.waypoints);this.useConstantSpeed&&this.spline.reparametrizeByArcLength(this.resamplingCoef);if(this.createDebugDummy){var a=new THREE.MeshLambertMaterial({color:30719}),g=new THREE.MeshLambertMaterial({color:65280}),j=new THREE.CubeGeometry(10,10,20),k=new THREE.CubeGeometry(2,2,10);this.animationParent=new THREE.Mesh(j,a);a=new THREE.Mesh(k,g);a.position.set(0,10,0);this.animation=
b(this.animationParent,this.spline,this.id,this.duration);this.animationParent.addChild(this);this.animationParent.addChild(this.target);this.animationParent.addChild(a)}else this.animation=b(this.animationParent,this.spline,this.id,this.duration),this.animationParent.addChild(this.target),this.animationParent.addChild(this);this.createDebugPath&&e(this.debugPath,this.spline);this.domElement.addEventListener("mousemove",function(a,c){return function(){c.apply(a,arguments)}}(this,this.onMouseMove),
!1)};THREE.PathCamera.prototype=new THREE.Camera;THREE.PathCamera.prototype.constructor=THREE.PathCamera;THREE.PathCamera.prototype.supr=THREE.Camera.prototype;THREE.PathCameraIdCounter=0;
THREE.FlyCamera=function(a){function b(a,b){return function(){b.apply(a,arguments)}}THREE.Camera.call(this,a.fov,a.aspect,a.near,a.far,a.target);this.tmpQuaternion=new THREE.Quaternion;this.movementSpeed=1;this.rollSpeed=0.0050;this.autoForward=this.dragToLook=!1;this.domElement=document;if(a){if(a.movementSpeed!==void 0)this.movementSpeed=a.movementSpeed;if(a.rollSpeed!==void 0)this.rollSpeed=a.rollSpeed;if(a.dragToLook!==void 0)this.dragToLook=a.dragToLook;if(a.autoForward!==void 0)this.autoForward=
THREE.FlyCamera=function(a){function b(a,b){return function(){b.apply(a,arguments)}}THREE.Camera.call(this,a.fov,a.aspect,a.near,a.far,a.target);this.tmpQuaternion=new THREE.Quaternion;this.movementSpeed=1;this.rollSpeed=0.005;this.autoForward=this.dragToLook=!1;this.domElement=document;if(a){if(a.movementSpeed!==void 0)this.movementSpeed=a.movementSpeed;if(a.rollSpeed!==void 0)this.rollSpeed=a.rollSpeed;if(a.dragToLook!==void 0)this.dragToLook=a.dragToLook;if(a.autoForward!==void 0)this.autoForward=
a.autoForward;if(a.domElement!==void 0)this.domElement=a.domElement}this.useTarget=!1;this.useQuaternion=!0;this.mouseStatus=0;this.moveState={up:0,down:0,left:0,right:0,forward:0,back:0,pitchUp:0,pitchDown:0,yawLeft:0,yawRight:0,rollLeft:0,rollRight:0};this.moveVector=new THREE.Vector3(0,0,0);this.rotationVector=new THREE.Vector3(0,0,0);this.lastUpdate=-1;this.tdiff=0;this.handleEvent=function(a){if(typeof this[a.type]=="function")this[a.type](a)};this.keydown=function(a){if(!a.altKey){switch(a.keyCode){case 16:this.movementSpeedMultiplier=
0.1;break;case 87:this.moveState.forward=1;break;case 83:this.moveState.back=1;break;case 65:this.moveState.left=1;break;case 68:this.moveState.right=1;break;case 82:this.moveState.up=1;break;case 70:this.moveState.down=1;break;case 38:this.moveState.pitchUp=1;break;case 40:this.moveState.pitchDown=1;break;case 37:this.moveState.yawLeft=1;break;case 39:this.moveState.yawRight=1;break;case 81:this.moveState.rollLeft=1;break;case 69:this.moveState.rollRight=1}this.updateMovementVector();this.updateRotationVector()}};
this.keyup=function(a){switch(a.keyCode){case 16:this.movementSpeedMultiplier=1;break;case 87:this.moveState.forward=0;break;case 83:this.moveState.back=0;break;case 65:this.moveState.left=0;break;case 68:this.moveState.right=0;break;case 82:this.moveState.up=0;break;case 70:this.moveState.down=0;break;case 38:this.moveState.pitchUp=0;break;case 40:this.moveState.pitchDown=0;break;case 37:this.moveState.yawLeft=0;break;case 39:this.moveState.yawRight=0;break;case 81:this.moveState.rollLeft=0;break;
......@@ -149,7 +149,7 @@ THREE.ExtrudeGeometry.__v3=new THREE.Vector2;THREE.ExtrudeGeometry.__v4=new THRE
THREE.IcosahedronGeometry=function(a){function b(a,b,c){var e=Math.sqrt(a*a+b*b+c*c);return f.vertices.push(new THREE.Vertex(new THREE.Vector3(a/e,b/e,c/e)))-1}function c(a,b,c,e){e.faces.push(new THREE.Face3(a,b,c))}function e(a,c){var e=f.vertices[a].position,g=f.vertices[c].position;return b((e.x+g.x)/2,(e.y+g.y)/2,(e.z+g.z)/2)}var f=this,h=new THREE.Geometry;this.subdivisions=a||0;THREE.Geometry.call(this);a=(1+Math.sqrt(5))/2;b(-1,a,0);b(1,a,0);b(-1,-a,0);b(1,-a,0);b(0,-1,a);b(0,1,a);b(0,-1,
-a);b(0,1,-a);b(a,0,-1);b(a,0,1);b(-a,0,-1);b(-a,0,1);c(0,11,5,h);c(0,5,1,h);c(0,1,7,h);c(0,7,10,h);c(0,10,11,h);c(1,5,9,h);c(5,11,4,h);c(11,10,2,h);c(10,7,6,h);c(7,1,8,h);c(3,9,4,h);c(3,4,2,h);c(3,2,6,h);c(3,6,8,h);c(3,8,9,h);c(4,9,5,h);c(2,4,11,h);c(6,2,10,h);c(8,6,7,h);c(9,8,1,h);for(var g=0;g<this.subdivisions;g++){var a=new THREE.Geometry,j;for(j in h.faces){var k=e(h.faces[j].a,h.faces[j].b),l=e(h.faces[j].b,h.faces[j].c),m=e(h.faces[j].c,h.faces[j].a);c(h.faces[j].a,k,m,a);c(h.faces[j].b,l,
k,a);c(h.faces[j].c,m,l,a);c(k,l,m,a)}h.faces=a.faces}f.faces=h.faces;this.computeCentroids();this.computeFaceNormals();this.computeVertexNormals()};THREE.IcosahedronGeometry.prototype=new THREE.Geometry;THREE.IcosahedronGeometry.prototype.constructor=THREE.IcosahedronGeometry;
THREE.LatheGeometry=function(a,b,c){THREE.Geometry.call(this);this.steps=b||12;this.angle=c||2*Math.PI;for(var b=this.angle/this.steps,c=[],e=[],f=[],h=[],g=(new THREE.Matrix4).setRotationZ(b),j=0;j<a.length;j++)this.vertices.push(new THREE.Vertex(a[j])),c[j]=a[j].clone(),e[j]=this.vertices.length-1;for(var k=0;k<=this.angle+0.0010;k+=b){for(j=0;j<c.length;j++)k<this.angle?(c[j]=g.multiplyVector3(c[j].clone()),this.vertices.push(new THREE.Vertex(c[j])),f[j]=this.vertices.length-1):f=h;k==0&&(h=e);
THREE.LatheGeometry=function(a,b,c){THREE.Geometry.call(this);this.steps=b||12;this.angle=c||2*Math.PI;for(var b=this.angle/this.steps,c=[],e=[],f=[],h=[],g=(new THREE.Matrix4).setRotationZ(b),j=0;j<a.length;j++)this.vertices.push(new THREE.Vertex(a[j])),c[j]=a[j].clone(),e[j]=this.vertices.length-1;for(var k=0;k<=this.angle+0.001;k+=b){for(j=0;j<c.length;j++)k<this.angle?(c[j]=g.multiplyVector3(c[j].clone()),this.vertices.push(new THREE.Vertex(c[j])),f[j]=this.vertices.length-1):f=h;k==0&&(h=e);
for(j=0;j<e.length-1;j++)this.faces.push(new THREE.Face4(f[j],f[j+1],e[j+1],e[j])),this.faceVertexUvs[0].push([new THREE.UV(1-k/this.angle,j/a.length),new THREE.UV(1-k/this.angle,(j+1)/a.length),new THREE.UV(1-(k-b)/this.angle,(j+1)/a.length),new THREE.UV(1-(k-b)/this.angle,j/a.length)]);e=f;f=[]}this.computeCentroids();this.computeFaceNormals();this.computeVertexNormals()};THREE.LatheGeometry.prototype=new THREE.Geometry;THREE.LatheGeometry.prototype.constructor=THREE.LatheGeometry;
THREE.PlaneGeometry=function(a,b,c,e){THREE.Geometry.call(this);var f,h=a/2,g=b/2,c=c||1,e=e||1,j=c+1,k=e+1;a/=c;var l=b/e;for(f=0;f<k;f++)for(b=0;b<j;b++)this.vertices.push(new THREE.Vertex(new THREE.Vector3(b*a-h,-(f*l-g),0)));for(f=0;f<e;f++)for(b=0;b<c;b++)this.faces.push(new THREE.Face4(b+j*f,b+j*(f+1),b+1+j*(f+1),b+1+j*f)),this.faceVertexUvs[0].push([new THREE.UV(b/c,f/e),new THREE.UV(b/c,(f+1)/e),new THREE.UV((b+1)/c,(f+1)/e),new THREE.UV((b+1)/c,f/e)]);this.computeCentroids();this.computeFaceNormals()};
THREE.PlaneGeometry.prototype=new THREE.Geometry;THREE.PlaneGeometry.prototype.constructor=THREE.PlaneGeometry;
......
此差异已折叠。
因为 它太大了无法显示 source diff 。你可以改为 查看blob
<!DOCTYPE HTML>
<html lang="en">
<head>
<title>three.js - webgl</title>
<meta charset="utf-8">
<style type="text/css">
body {
background:#fff;
padding:0;
margin:0;
overflow:hidden;
}
</style>
</head>
<body>
<script type="text/javascript" src="../build/Three.js"></script>
<script type="text/javascript">
var container;
var camera, scene, renderer;
init();
setInterval( render, 1000 / 60 );
function init() {
container = document.createElement( 'div' );
document.body.appendChild( container );
camera = new THREE.Camera( 60, window.innerWidth / window.innerHeight, 1, 10000 );
camera.position.z = 200;
scene = new THREE.Scene();
renderer = new THREE.WebGLRenderer();
renderer.setSize( window.innerWidth, window.innerHeight );
container.appendChild( renderer.domElement );
}
function createImage() {
var canvas = document.createElement( 'canvas' );
canvas.width = 256;
canvas.height = 256;
var context = canvas.getContext( '2d' );
context.fillStyle = 'rgb(' + Math.floor( Math.random() * 256 ) + ',' + Math.floor( Math.random() * 256 ) + ',' + Math.floor( Math.random() * 256 ) + ')';
context.fillRect( 0, 0, 256, 256 );
return canvas;
}
//
function animate() {
requestAnimationFrame( animate );
render();
}
function render() {
var geometry = new THREE.SphereGeometry( 50, Math.random() * 64, Math.random() * 32 );
var texture = new THREE.Texture( createImage() );
texture.needsUpdate = true;
var material = new THREE.MeshBasicMaterial( { map: texture, wireframe: true } )
var mesh = new THREE.Mesh( geometry, material );
scene.addObject( mesh );
renderer.render( scene, camera );
scene.removeObject( mesh );
renderer.deallocateObject( mesh );
renderer.deallocateTexture( texture );
}
</script>
</body>
</html>
......@@ -295,6 +295,53 @@ THREE.WebGLRenderer = function ( parameters ) {
};
this.deallocateObject = function ( object ) {
if ( ! object.__webglInit ) return;
object.__webglInit = false;
delete object._modelViewMatrix;
delete object._normalMatrixArray;
delete object._modelViewMatrixArray;
delete object._objectMatrixArray;
if ( object instanceof THREE.Mesh ) {
for ( g in object.geometry.geometryGroups ) {
deleteMeshBuffers( object.geometry.geometryGroups[ g ] );
}
} else if ( object instanceof THREE.Ribbon ) {
deleteRibbonBuffers( object.geometry );
} else if ( object instanceof THREE.Line ) {
deleteLineBuffers( object.geometry );
} else if ( object instanceof THREE.ParticleSystem ) {
deleteParticleBuffers( object.geometry );
}
};
this.deallocateTexture = function ( texture ) {
if ( ! texture.__webglInit ) return;
texture.__webglInit = false;
_gl.deleteTexture( texture.__webglTexture );
};
//
function setupLights ( program, lights ) {
var l, ll, light, n,
......@@ -396,7 +443,9 @@ THREE.WebGLRenderer = function ( parameters ) {
};
function createParticleBuffers ( geometry ) {
// Buffer allocation
function createParticleBuffers( geometry ) {
geometry.__webglVertexBuffer = _gl.createBuffer();
geometry.__webglColorBuffer = _gl.createBuffer();
......@@ -450,6 +499,64 @@ THREE.WebGLRenderer = function ( parameters ) {
};
// Buffer deallocation
function deleteParticleBuffers( geometry ) {
_gl.deleteBuffer( geometry.__webglVertexBuffer );
_gl.deleteBuffer( geometry.__webglColorBuffer );
};
function deleteLineBuffers( geometry ) {
_gl.deleteBuffer( geometry.__webglVertexBuffer );
_gl.deleteBuffer( geometry.__webglColorBuffer );
};
function deleteRibbonBuffers( geometry ) {
_gl.deleteBuffer( geometry.__webglVertexBuffer );
_gl.deleteBuffer( geometry.__webglColorBuffer );
};
function deleteMeshBuffers( geometryGroup ) {
_gl.deleteBuffer( geometryGroup.__webglVertexBuffer );
_gl.deleteBuffer( geometryGroup.__webglNormalBuffer );
_gl.deleteBuffer( geometryGroup.__webglTangentBuffer );
_gl.deleteBuffer( geometryGroup.__webglColorBuffer );
_gl.deleteBuffer( geometryGroup.__webglUVBuffer );
_gl.deleteBuffer( geometryGroup.__webglUV2Buffer );
_gl.deleteBuffer( geometryGroup.__webglSkinVertexABuffer );
_gl.deleteBuffer( geometryGroup.__webglSkinVertexBBuffer );
_gl.deleteBuffer( geometryGroup.__webglSkinIndicesBuffer );
_gl.deleteBuffer( geometryGroup.__webglSkinWeightsBuffer );
_gl.deleteBuffer( geometryGroup.__webglFaceBuffer );
_gl.deleteBuffer( geometryGroup.__webglLineBuffer );
if ( geometryGroup.numMorphTargets ) {
var m, ml;
geometryGroup.__webglMorphTargetsBuffers = [];
for ( m = 0, ml = geometryGroup.numMorphTargets; m < ml; m ++ ) {
_gl.deleteBuffer( geometryGroup.__webglMorphTargetsBuffers[ m ] );
}
}
};
//
function initLineBuffers ( geometry ) {
var nvertices = geometry.vertices.length;
......@@ -3951,7 +4058,9 @@ THREE.WebGLRenderer = function ( parameters ) {
var g, geometry, geometryGroup;
if ( object._modelViewMatrix == undefined ) {
if ( ! object.__webglInit ) {
object.__webglInit = true;
object._modelViewMatrix = new THREE.Matrix4();
......@@ -3961,106 +4070,107 @@ THREE.WebGLRenderer = function ( parameters ) {
object.matrixWorld.flattenToArray( object._objectMatrixArray );
}
if ( object instanceof THREE.Mesh ) {
if ( object instanceof THREE.Mesh ) {
geometry = object.geometry;
geometry = object.geometry;
if ( geometry.geometryGroups == undefined ) {
if ( geometry.geometryGroups == undefined ) {
sortFacesByMaterial( geometry );
sortFacesByMaterial( geometry );
}
}
// create separate VBOs per geometry chunk
// create separate VBOs per geometry chunk
for ( g in geometry.geometryGroups ) {
for ( g in geometry.geometryGroups ) {
geometryGroup = geometry.geometryGroups[ g ];
geometryGroup = geometry.geometryGroups[ g ];
// initialise VBO on the first access
// initialise VBO on the first access
if ( ! geometryGroup.__webglVertexBuffer ) {
if ( ! geometryGroup.__webglVertexBuffer ) {
createMeshBuffers( geometryGroup );
initMeshBuffers( geometryGroup, object );
createMeshBuffers( geometryGroup );
initMeshBuffers( geometryGroup, object );
geometry.__dirtyVertices = true;
geometry.__dirtyMorphTargets = true;
geometry.__dirtyElements = true;
geometry.__dirtyUvs = true;
geometry.__dirtyNormals = true;
geometry.__dirtyTangents = true;
geometry.__dirtyColors = true;
geometry.__dirtyVertices = true;
geometry.__dirtyMorphTargets = true;
geometry.__dirtyElements = true;
geometry.__dirtyUvs = true;
geometry.__dirtyNormals = true;
geometry.__dirtyTangents = true;
geometry.__dirtyColors = true;
}
}
addBuffer( scene.__webglObjects, geometryGroup, object );
addBuffer( scene.__webglObjects, geometryGroup, object );
}
}
} else if ( object instanceof THREE.Ribbon ) {
} else if ( object instanceof THREE.Ribbon ) {
geometry = object.geometry;
geometry = object.geometry;
if( ! geometry.__webglVertexBuffer ) {
if( ! geometry.__webglVertexBuffer ) {
createRibbonBuffers( geometry );
initRibbonBuffers( geometry );
createRibbonBuffers( geometry );
initRibbonBuffers( geometry );
geometry.__dirtyVertices = true;
geometry.__dirtyColors = true;
geometry.__dirtyVertices = true;
geometry.__dirtyColors = true;
}
}
addBuffer( scene.__webglObjects, geometry, object );
addBuffer( scene.__webglObjects, geometry, object );
} else if ( object instanceof THREE.Line ) {
} else if ( object instanceof THREE.Line ) {
geometry = object.geometry;
geometry = object.geometry;
if( ! geometry.__webglVertexBuffer ) {
if( ! geometry.__webglVertexBuffer ) {
createLineBuffers( geometry );
initLineBuffers( geometry );
createLineBuffers( geometry );
initLineBuffers( geometry );
geometry.__dirtyVertices = true;
geometry.__dirtyColors = true;
geometry.__dirtyVertices = true;
geometry.__dirtyColors = true;
}
}
addBuffer( scene.__webglObjects, geometry, object );
addBuffer( scene.__webglObjects, geometry, object );
} else if ( object instanceof THREE.ParticleSystem ) {
} else if ( object instanceof THREE.ParticleSystem ) {
geometry = object.geometry;
geometry = object.geometry;
if ( ! geometry.__webglVertexBuffer ) {
if ( ! geometry.__webglVertexBuffer ) {
createParticleBuffers( geometry );
initParticleBuffers( geometry, object );
createParticleBuffers( geometry );
initParticleBuffers( geometry, object );
geometry.__dirtyVertices = true;
geometry.__dirtyColors = true;
geometry.__dirtyVertices = true;
geometry.__dirtyColors = true;
}
}
addBuffer( scene.__webglObjects, geometry, object );
addBuffer( scene.__webglObjects, geometry, object );
} else if ( THREE.MarchingCubes !== undefined && object instanceof THREE.MarchingCubes ) {
} else if ( THREE.MarchingCubes !== undefined && object instanceof THREE.MarchingCubes ) {
addBufferImmediate( scene.__webglObjectsImmediate, object );
addBufferImmediate( scene.__webglObjectsImmediate, object );
} else if ( object instanceof THREE.Sprite ) {
} else if ( object instanceof THREE.Sprite ) {
scene.__webglSprites.push( object );
scene.__webglSprites.push( object );
}
}
/*else if ( object instanceof THREE.Particle ) {
/*else if ( object instanceof THREE.Particle ) {
}*/
}*/
}
};
......@@ -4893,8 +5003,8 @@ THREE.WebGLRenderer = function ( parameters ) {
if ( ! texture.__webglInit ) {
texture.__webglTexture = _gl.createTexture();
texture.__webglInit = true;
texture.__webglTexture = _gl.createTexture();
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册