提交 098d3eda 编写于 作者: A alteredq

Added dynamic updating of BufferGeometry. Added BufferGeometry.applyMatrix....

Added dynamic updating of BufferGeometry. Added BufferGeometry.applyMatrix. Added Matrix4.multiplyVector3Array.

CTMLoader now keeps references to typed arrays used to initialize GL buffers. These are later on deleted in WebGLRenderer (by default, if BufferGeometry.dynamic flag is not set).

Fixes #2166

(this commit should go to `unflipped` branch, it assumes straightforward UVs)
上级 525b91e2
因为 它太大了无法显示 source diff 。你可以改为 查看blob
此差异已折叠。
此差异已折叠。
此差异已折叠。
......@@ -30,9 +30,9 @@ THREE.CTMLoader.prototype.loadParts = function( url, callback, useWorker, useBuf
xhr.onreadystatechange = function() {
if ( xhr.readyState == 4 ) {
if ( xhr.readyState === 4 ) {
if ( xhr.status == 200 || xhr.status == 0 ) {
if ( xhr.status === 200 || xhr.status === 0 ) {
var jsonObject = JSON.parse( xhr.responseText );
......@@ -97,9 +97,9 @@ THREE.CTMLoader.prototype.load = function( url, callback, useWorker, useBuffers,
xhr.onreadystatechange = function() {
if ( xhr.readyState == 4 ) {
if ( xhr.readyState === 4 ) {
if ( xhr.status == 200 || xhr.status == 0 ) {
if ( xhr.status === 200 || xhr.status === 0 ) {
var binaryData = xhr.responseText;
......@@ -169,11 +169,11 @@ THREE.CTMLoader.prototype.load = function( url, callback, useWorker, useBuffers,
}
} else if ( xhr.readyState == 3 ) {
} else if ( xhr.readyState === 3 ) {
if ( callbackProgress ) {
if ( length == 0 ) {
if ( length === 0 ) {
length = xhr.getResponseHeader( "Content-Length" );
......@@ -183,7 +183,7 @@ THREE.CTMLoader.prototype.load = function( url, callback, useWorker, useBuffers,
}
} else if ( xhr.readyState == 2 ) {
} else if ( xhr.readyState === 2 ) {
length = xhr.getResponseHeader( "Content-Length" );
......@@ -206,7 +206,7 @@ THREE.CTMLoader.prototype.createModelBuffers = function ( file, callback ) {
var scope = this;
var dynamic = false,
var keepArrays = true,
computeNormals = true,
normalizeNormals = true,
reorderVertices = true;
......@@ -461,9 +461,11 @@ THREE.CTMLoader.prototype.createModelBuffers = function ( file, callback ) {
// indices
var vertexIndexArray16 = new Uint16Array( vertexIndexArray );
scope.vertexIndexBuffer = gl.createBuffer();
gl.bindBuffer( gl.ELEMENT_ARRAY_BUFFER, scope.vertexIndexBuffer );
gl.bufferData( gl.ELEMENT_ARRAY_BUFFER, new Uint16Array( vertexIndexArray ), gl.STATIC_DRAW );
gl.bufferData( gl.ELEMENT_ARRAY_BUFFER, vertexIndexArray16, gl.STATIC_DRAW );
scope.vertexIndexBuffer.itemSize = 1;
scope.vertexIndexBuffer.numItems = vertexIndexArray.length;
......@@ -583,9 +585,9 @@ THREE.CTMLoader.prototype.createModelBuffers = function ( file, callback ) {
// keep references to typed arrays
if ( dynamic ) {
if ( keepArrays ) {
scope.vertexIndexArray = vertexIndexArray;
scope.vertexIndexArray = vertexIndexArray16;
scope.vertexPositionArray = vertexPositionArray;
scope.vertexNormalArray = vertexNormalArray;
scope.vertexUvArray = vertexUvArray;
......
......@@ -34,7 +34,7 @@ THREE.Geometry = function () {
this.hasTangents = false;
this.dynamic = false; // unless set to true the *Arrays will be deleted once sent to a buffer.
this.dynamic = false; // unless set to true the *Arrays will be deleted once sent to a buffer
};
......@@ -629,7 +629,7 @@ THREE.Geometry.prototype = {
u = this.faceVertexUvs[j][i];
if (u) u.splice(k, 1);
}
break;
}
}
......
......@@ -213,6 +213,28 @@ THREE.Matrix4.prototype = {
},
multiplyVector3Array: function ( a ) {
var tmp = THREE.Matrix4.__v1;
for ( var i = 0, il = a.length; i < il; i += 3 ) {
tmp.x = a[ i ];
tmp.y = a[ i + 1 ];
tmp.z = a[ i + 2 ];
this.multiplyVector3( tmp );
a[ i ] = tmp.x;
a[ i + 1 ] = tmp.y;
a[ i + 2 ] = tmp.z;
}
return a;
},
rotateAxis: function ( v ) {
var te = this.elements;
......
......@@ -39,6 +39,27 @@ THREE.BufferGeometry.prototype = {
constructor : THREE.BufferGeometry,
applyMatrix: function ( matrix ) {
if ( this.vertexPositionArray !== undefined ) {
matrix.multiplyVector3Array( this.vertexPositionArray );
this.verticesNeedUpdate = true;
}
if ( this.vertexNormalArray !== undefined ) {
var matrixRotation = new THREE.Matrix4();
matrixRotation.extractRotation( matrix );
matrixRotation.multiplyVector3Array( this.vertexNormalArray );
this.normalsNeedUpdate = true;
}
},
// for compatibility
computeBoundingBox: function () {
......
......@@ -2878,6 +2878,56 @@ THREE.WebGLRenderer = function ( parameters ) {
};
function setDirectBuffers ( geometry, hint, dispose ) {
if ( geometry.elementsNeedUpdate && geometry.vertexIndexArray !== undefined ) {
_gl.bindBuffer( _gl.ELEMENT_ARRAY_BUFFER, geometry.vertexIndexBuffer );
_gl.bufferData( _gl.ELEMENT_ARRAY_BUFFER, geometry.vertexIndexArray, hint );
}
if ( geometry.verticesNeedUpdate && geometry.vertexPositionArray !== undefined ) {
_gl.bindBuffer( _gl.ARRAY_BUFFER, geometry.vertexPositionBuffer );
_gl.bufferData( _gl.ARRAY_BUFFER, geometry.vertexPositionArray, hint );
}
if ( geometry.normalsNeedUpdate && geometry.vertexNormalArray !== undefined ) {
_gl.bindBuffer( _gl.ARRAY_BUFFER, geometry.vertexNormalBuffer );
_gl.bufferData( _gl.ARRAY_BUFFER, geometry.vertexNormalArray, hint );
}
if ( geometry.uvsNeedUpdate && geometry.vertexUvArray !== undefined ) {
_gl.bindBuffer( _gl.ARRAY_BUFFER, geometry.vertexUvBuffer );
_gl.bufferData( _gl.ARRAY_BUFFER, geometry.vertexUvArray, hint );
}
if ( geometry.colorsNeedUpdate && geometry.vertexColorArray !== undefined ) {
_gl.bindBuffer( _gl.ARRAY_BUFFER, geometry.vertexColorBuffer );
_gl.bufferData( _gl.ARRAY_BUFFER, geometry.vertexColorArray, hint );
}
if ( dispose ) {
delete geometry.vertexIndexArray;
delete geometry.vertexPositionArray;
delete geometry.vertexNormalArray;
delete geometry.vertexUvArray;
delete geometry.vertexColorArray;
}
};
// Buffer rendering
this.renderBufferImmediate = function ( object, program, material ) {
......@@ -4154,16 +4204,13 @@ THREE.WebGLRenderer = function ( parameters ) {
if ( geometry instanceof THREE.BufferGeometry ) {
/*
if ( geometry.verticesNeedUpdate || geometry.elementsNeedUpdate ||
geometry.uvsNeedUpdate || geometry.normalsNeedUpdate ||
geometry.colorsNeedUpdate ) {
// TODO
// set buffers from typed arrays
setDirectBuffers( geometry, _gl.DYNAMIC_DRAW, !geometry.dynamic );
}
*/
geometry.verticesNeedUpdate = false;
geometry.elementsNeedUpdate = false;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册