提交 9662c39e 编写于 作者: S simonThiele

add tests for InstancedBufferAttribute, InstancedBufferGeometry,...

add tests for InstancedBufferAttribute, InstancedBufferGeometry, InstancedInterleavedBuffer, InterleavedBuffer and InterleavedBufferAttribute
上级 87eba598
/**
* @author simonThiele / https://github.com/simonThiele
*/
module( "InstancedBufferAttribute" );
test( "can be created", function() {
var instance = new THREE.InstancedBufferAttribute(new Float32Array(10), 2);
ok( instance.meshPerAttribute === 1, "ok" );
instance = new THREE.InstancedBufferAttribute(new Float32Array(10), 2, 123);
ok( instance.meshPerAttribute === 123, "ok" );
});
test( "copy", function() {
var array = new Float32Array([1, 2, 3, 7, 8, 9]);
var instance = new THREE.InstancedBufferAttribute(array, 2, 123);
var copiedInstance = instance.copy(instance);
ok( copiedInstance instanceof THREE.InstancedBufferAttribute, "the clone has the correct type" );
ok( copiedInstance.itemSize === 2, "itemSize was copied" );
ok( copiedInstance.meshPerAttribute === 123, "meshPerAttribute was copied" );
for (var i = 0; i < array.length; i++) {
ok( copiedInstance.array[i] === array[i], "array was copied" );
}
});
/**
* @author simonThiele / https://github.com/simonThiele
*/
module( "InstancedBufferGeometry" );
function createClonableMock() {
return {
callCount: 0,
clone: function() {
this.callCount++;
return this;
}
}
}
test( "copy", function() {
var instanceMock1 = {};
var instanceMock2 = {};
var indexMock = createClonableMock();
var attributeMock1 = {};
var attributeMock2 = {};
var instance = new THREE.InstancedBufferGeometry();
instance.addGroup(0, 10, instanceMock1);
instance.addGroup(10, 5, instanceMock2);
instance.setIndex(indexMock);
instance.addAttribute('attributeMock1', attributeMock1);
instance.addAttribute('attributeMock2', attributeMock2);
var copiedInstance = instance.copy(instance);
ok( copiedInstance instanceof THREE.InstancedBufferGeometry, "the clone has the correct type" );
ok( copiedInstance.index === indexMock, "index was copied" );
ok( copiedInstance.index.callCount === 1, "index.clone was called once" );
ok( copiedInstance.attributes['attributeMock1'] instanceof THREE.BufferAttribute, "attribute was created" );
// the given attribute mock was passed to the array property of the created buffer attribute
ok( copiedInstance.attributes['attributeMock1'].array === attributeMock1, "attribute was copied" );
ok( copiedInstance.attributes['attributeMock2'].array === attributeMock2, "attribute was copied" );
ok( copiedInstance.groups[0].start === 0, "group was copied" );
ok( copiedInstance.groups[0].count === 10, "group was copied" );
ok( copiedInstance.groups[0].instances === instanceMock1, "group was copied" );
ok( copiedInstance.groups[1].start === 10, "group was copied" );
ok( copiedInstance.groups[1].count === 5, "group was copied" );
ok( copiedInstance.groups[1].instances === instanceMock2, "group was copied" );
});
/**
* @author simonThiele / https://github.com/simonThiele
*/
module( "InstancedInterleavedBuffer" );
test( "can be created", function() {
var array = new Float32Array( [1, 2, 3, 7, 8, 9] );
var instance = new THREE.InstancedInterleavedBuffer( array, 3 );
ok( instance.meshPerAttribute === 1, "ok" );
});
test( "copy", function() {
var array = new Float32Array( [1, 2, 3, 7, 8, 9] );
var instance = new THREE.InstancedInterleavedBuffer( array, 3 );
var copiedInstance = instance.copy( instance );
ok( copiedInstance.meshPerAttribute === 1, "additional attribute was copied" );
});
/**
* @author simonThiele / https://github.com/simonThiele
*/
module( "InterleavedBuffer" );
function checkInstanceAgainstCopy(instance, copiedInstance) {
ok( copiedInstance instanceof THREE.InterleavedBuffer, "the clone has the correct type" );
for (var i = 0; i < instance.array.length; i++) {
ok( copiedInstance.array[i] === instance.array[i], "array was copied" );
}
ok( copiedInstance.stride === instance.stride, "stride was copied" );
ok( copiedInstance.dynamic === true, "dynamic was copied" );
}
test( "length and count", function() {
var instance = new THREE.InterleavedBuffer( new Float32Array( [1, 2, 3, 7, 8 ,9] ), 3 );
ok( instance.length === 6, "length is calculated via array length" );
ok( instance.count === 2, "count is calculated via array length / stride" );
});
test( "copy", function() {
var array = new Float32Array( [1, 2, 3, 7, 8 ,9] );
var instance = new THREE.InterleavedBuffer( array, 3 );
instance.setDynamic( true );
checkInstanceAgainstCopy(instance, instance.copy( instance ) );
});
test( "clone", function() {
var array = new Float32Array( [1, 2, 3, 7, 8 ,9] );
var instance = new THREE.InterleavedBuffer( array, 3 );
instance.setDynamic( true );
checkInstanceAgainstCopy( instance, instance.clone() );
});
test( "set", function() {
var instance = new THREE.InterleavedBuffer( new Float32Array( [1, 2, 3, 7, 8 ,9] ), 3 );
instance.set( [0, -1] );
ok( instance.array[0] === 0 && instance.array[1] === -1, "replace at first by default" );
});
/**
* @author simonThiele / https://github.com/simonThiele
*/
module( "InterleavedBufferAttribute" );
test( "length and count", function() {
var buffer = new THREE.InterleavedBuffer( new Float32Array( [1, 2, 3, 7, 8 ,9] ), 3 );
var instance = new THREE.InterleavedBufferAttribute( buffer, 2, 0 );
ok( instance.count === 2, "count is calculated via array length / stride" );
});
test( "setX", function() {
var buffer = new THREE.InterleavedBuffer( new Float32Array( [1, 2, 3, 7, 8 ,9] ), 3 );
var instance = new THREE.InterleavedBufferAttribute( buffer, 2, 0 );
instance.setX( 0, 123 );
instance.setX( 1, 321 );
ok( instance.data.array[0] === 123 &&
instance.data.array[3] === 321, "x was calculated correct based on index and default offset" );
buffer = new THREE.InterleavedBuffer( new Float32Array( [1, 2, 3, 7, 8 ,9] ), 3 );
instance = new THREE.InterleavedBufferAttribute( buffer, 2, 1 );
instance.setX( 0, 123 );
instance.setX( 1, 321 );
// the offset was defined as 1, so go one step futher in the array
ok( instance.data.array[1] === 123 &&
instance.data.array[4] === 321, "x was calculated correct based on index and default offset" );
});
// setY, setZ and setW are calculated in the same way so not testing this
......@@ -22,6 +22,12 @@
<script src="cameras/OrthographicCamera.js"></script>
<script src="cameras/PerspectiveCamera.js"></script>
<script src="core/InstancedBufferAttribute.js"></script>
<script src="core/InstancedBufferGeometry.js"></script>
<script src="core/InstancedInterleavedBuffer.js"></script>
<script src="core/InterleavedBuffer.js"></script>
<script src="core/InterleavedBufferAttribute.js"></script>
<script src="core/BufferAttribute.js"></script>
<script src="core/BufferGeometry.js"></script>
<script src="core/Clock.js"></script>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册