Skip to content

Commit 2e1581f

Browse files
Brunni132mrdoob
authored andcommitted
BoxHelper set color in constructor (mrdoob#8896) (mrdoob#8971)
* BoxHelper set color in constructor (mrdoob#8896) * Added unit test for BoxHelper.
1 parent 2590f6e commit 2e1581f

File tree

4 files changed

+47
-4
lines changed

4 files changed

+47
-4
lines changed

docs/api/extras/helpers/BoxHelper.html

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<!DOCTYPE html>
22
<html lang="en">
33
<head>
4-
<meta charset="utf-8" />
4+
<meta charset="utf-8" />
55
<base href="../../../" />
66
<script src="list.js"></script>
77
<script src="page.js"></script>
@@ -26,7 +26,11 @@ <h2>Example</h2>
2626

2727
<h2>Constructor</h2>
2828

29-
<h3>[name]( [page:Object3D object] )</h3>
29+
<h3>[name]( [page:Object3D object], [page:Number hex] )</h3>
30+
<div>
31+
object -- Object3D -- the object3D to show the world-axis-aligned boundingbox.<br />
32+
hex -- hexadecimal value to define color ex:0xffff00
33+
</div>
3034
<div>Creates a new wireframe box matching the size of the passed box.</div>
3135

3236
<h2>Properties</h2>

src/extras/helpers/BoxHelper.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,17 @@
22
* @author mrdoob / http://mrdoob.com/
33
*/
44

5-
THREE.BoxHelper = function ( object ) {
5+
THREE.BoxHelper = function ( object, hex ) {
66

77
var indices = new Uint16Array( [ 0, 1, 1, 2, 2, 3, 3, 0, 4, 5, 5, 6, 6, 7, 7, 4, 0, 4, 1, 5, 2, 6, 3, 7 ] );
88
var positions = new Float32Array( 8 * 3 );
9+
var color = ( hex !== undefined ) ? hex : 0xffff00;
910

1011
var geometry = new THREE.BufferGeometry();
1112
geometry.setIndex( new THREE.BufferAttribute( indices, 1 ) );
1213
geometry.addAttribute( 'position', new THREE.BufferAttribute( positions, 3 ) );
1314

14-
THREE.LineSegments.call( this, geometry, new THREE.LineBasicMaterial( { color: 0xffff00 } ) );
15+
THREE.LineSegments.call( this, geometry, new THREE.LineBasicMaterial( { color: color } ) );
1516

1617
if ( object !== undefined ) {
1718

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
(function () {
2+
3+
'use strict';
4+
5+
var parameters = {
6+
diameter: 10,
7+
};
8+
9+
var geometries;
10+
11+
QUnit.module( "Extras - Helpers - BoxHelper", {
12+
13+
beforeEach: function() {
14+
var greenMaterial = new THREE.MeshBasicMaterial( {color: 0x00ff00} );
15+
16+
// Test with a normal cube and a box helper
17+
var boxGeometry = new THREE.BoxGeometry( parameters.diameter );
18+
var box = new THREE.Mesh( boxGeometry, greenMaterial );
19+
var boxHelper = new THREE.BoxHelper( box );
20+
21+
// The same should happen with a comparable sphere
22+
var sphereGeometry = new THREE.SphereGeometry( parameters.diameter / 2 );
23+
var sphere = new THREE.Mesh( sphereGeometry, greenMaterial );
24+
var sphereBoxHelper = new THREE.BoxHelper( sphere );
25+
26+
// Note that unlike what I'd like to, these doesn't check the equivalency of the two generated geometries
27+
geometries = [ boxHelper.geometry, sphereBoxHelper.geometry ];
28+
}
29+
30+
});
31+
32+
QUnit.test( "standard geometry tests", function( assert ) {
33+
runStdGeometryTests( assert, geometries );
34+
});
35+
36+
})();

test/unit/unittests_three.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@
9191
<script src="extras/geometries/TubeGeometry.tests.js"></script>
9292
<script src="extras/geometries/WireframeGeometry.tests.js"></script>
9393

94+
<script src="extras/helpers/BoxHelper.tests.js"></script>
95+
9496

9597
<!-- for debug output -->
9698
<!--

0 commit comments

Comments
 (0)