-
-
Notifications
You must be signed in to change notification settings - Fork 35.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This approach prettifies the API a bit, and the performance seems to be on par with raw access to the typedarray.
- Loading branch information
Showing
11 changed files
with
247 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
/** | ||
* @author mrdoob / http://mrdoob.com/ | ||
*/ | ||
|
||
THREE.BufferAttribute = function () {}; | ||
|
||
THREE.BufferAttribute.prototype = { | ||
|
||
constructor: THREE.BufferAttribute, | ||
|
||
set: function ( value ) { | ||
|
||
this.array.set( value ); | ||
|
||
}, | ||
|
||
setX: function ( index, x ) { | ||
|
||
this.array[ index * this.itemSize ] = x; | ||
|
||
}, | ||
|
||
setY: function ( index, y ) { | ||
|
||
this.array[ index * this.itemSize + 1 ] = y; | ||
|
||
}, | ||
|
||
setZ: function ( index, z ) { | ||
|
||
this.array[ index * this.itemSize + 2 ] = z; | ||
|
||
}, | ||
|
||
setXY: function ( index, x, y ) { | ||
|
||
index *= this.itemSize; | ||
|
||
this.array[ index ] = x; | ||
this.array[ index + 1 ] = y; | ||
|
||
}, | ||
|
||
setXYZ: function ( index, x, y, z ) { | ||
|
||
index *= this.itemSize; | ||
|
||
this.array[ index ] = x; | ||
this.array[ index + 1 ] = y; | ||
this.array[ index + 2 ] = z; | ||
|
||
} | ||
|
||
}; | ||
|
||
// | ||
|
||
THREE.Int8Attribute = function ( size, itemSize ) { | ||
|
||
this.array = new Int8Array( size * itemSize ); | ||
this.itemSize = itemSize; | ||
|
||
}; | ||
|
||
THREE.Int8Attribute.prototype = Object.create( THREE.BufferAttribute.prototype ); | ||
|
||
THREE.Uint8Attribute = function ( size, itemSize ) { | ||
|
||
this.array = new Uint8Array( size * itemSize ); | ||
this.itemSize = itemSize; | ||
|
||
}; | ||
|
||
THREE.Uint8Attribute.prototype = Object.create( THREE.BufferAttribute.prototype ); | ||
|
||
THREE.Uint8ClampedAttribute = function ( size, itemSize ) { | ||
|
||
this.array = new Uint8ClampedArray( size * itemSize ); | ||
this.itemSize = itemSize; | ||
|
||
}; | ||
|
||
THREE.Uint8ClampedAttribute.prototype = Object.create( THREE.BufferAttribute.prototype ); | ||
|
||
THREE.Int16Attribute = function ( size, itemSize ) { | ||
|
||
this.array = new Int16Array( size * itemSize ); | ||
this.itemSize = itemSize; | ||
|
||
}; | ||
|
||
THREE.Int16Attribute.prototype = Object.create( THREE.BufferAttribute.prototype ); | ||
|
||
THREE.Uint16Attribute = function ( size, itemSize ) { | ||
|
||
this.array = new Uint16Array( size * itemSize ); | ||
this.itemSize = itemSize; | ||
|
||
}; | ||
|
||
THREE.Uint16Attribute.prototype = Object.create( THREE.BufferAttribute.prototype ); | ||
|
||
THREE.Int32Attribute = function ( size, itemSize ) { | ||
|
||
this.array = new Int32Array( size * itemSize ); | ||
this.itemSize = itemSize; | ||
|
||
}; | ||
|
||
THREE.Int32Attribute.prototype = Object.create( THREE.BufferAttribute.prototype ); | ||
|
||
THREE.Uint32Attribute = function ( size, itemSize ) { | ||
|
||
this.array = new Uint32Array( size * itemSize ); | ||
this.itemSize = itemSize; | ||
|
||
}; | ||
|
||
THREE.Uint32Attribute.prototype = Object.create( THREE.BufferAttribute.prototype ); | ||
|
||
THREE.Float32Attribute = function ( size, itemSize ) { | ||
|
||
this.array = new Float32Array( size * itemSize ); | ||
this.itemSize = itemSize; | ||
|
||
}; | ||
|
||
THREE.Float32Attribute.prototype = Object.create( THREE.BufferAttribute.prototype ); | ||
|
||
THREE.Float64Attribute = function ( size, itemSize ) { | ||
|
||
this.array = new Float64Array( size * itemSize ); | ||
this.itemSize = itemSize; | ||
|
||
}; | ||
|
||
THREE.Float64Attribute.prototype = Object.create( THREE.BufferAttribute.prototype ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/** | ||
* @author mrdoob / http://mrdoob.com/ | ||
* based on http://papervision3d.googlecode.com/svn/trunk/as3/trunk/src/org/papervision3d/objects/primitives/Plane.as | ||
*/ | ||
|
||
THREE.PlaneGeometry2b = function ( width, height, widthSegments, heightSegments ) { | ||
|
||
THREE.Geometry2.call( this, ( widthSegments * heightSegments ) * 2 * 3 ); | ||
|
||
var vertices = this.vertices; | ||
var normals = this.normals; | ||
var uvs = this.uvs; | ||
|
||
this.width = width; | ||
this.height = height; | ||
|
||
this.widthSegments = widthSegments || 1; | ||
this.heightSegments = heightSegments || 1; | ||
|
||
var widthHalf = width / 2; | ||
var heightHalf = height / 2; | ||
|
||
var gridX = this.widthSegments; | ||
var gridY = this.heightSegments; | ||
|
||
var segmentWidth = this.width / gridX; | ||
var segmentHeight = this.height / gridY; | ||
|
||
var index = 0; | ||
|
||
for ( var iy = 0; iy < gridY; iy ++ ) { | ||
|
||
var y1 = iy * segmentHeight - heightHalf; | ||
var y2 = ( iy + 1 ) * segmentHeight - heightHalf; | ||
|
||
for ( var ix = 0; ix < gridX; ix ++ ) { | ||
|
||
var x1 = ix * segmentWidth - widthHalf; | ||
var x2 = ( ix + 1 ) * segmentWidth - widthHalf; | ||
|
||
this.vertices.setXY( index + 0, x1, y1 ); | ||
this.vertices.setXY( index + 1, x2, y1 ); | ||
this.vertices.setXY( index + 2, x1, y2 ); | ||
|
||
this.vertices.setXY( index + 3, x2, y1 ); | ||
this.vertices.setXY( index + 4, x2, y2 ); | ||
this.vertices.setXY( index + 5, x1, y2 ); | ||
|
||
this.normals.setZ( index + 0, 1 ); | ||
this.normals.setZ( index + 1, 1 ); | ||
this.normals.setZ( index + 2, 1 ); | ||
|
||
this.normals.setZ( index + 3, 1 ); | ||
this.normals.setZ( index + 4, 1 ); | ||
this.normals.setZ( index + 5, 1 ); | ||
|
||
index += 6; | ||
|
||
} | ||
|
||
} | ||
|
||
}; | ||
|
||
THREE.PlaneGeometry2b.prototype = Object.create( THREE.Geometry2.prototype ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
f549fed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
interesting... but this breaks buffergeometries examples again 😿
should i update the gpu birds examples again?
f549fed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Haha... Sorry!
It's hard to design this stuff... This kind of feels good though!
Let me fix it for you.
f549fed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks! 🐹 i like the way you don't have to repeat the size number now :)