How to use the BoxGeometry function from three
Find comprehensive JavaScript three.BoxGeometry code examples handpicked from public code repositorys.
34 35 36 37 38 39 40 41 42 43
} catch (err) { console.log(err) } } const geometry = new THREE.BoxGeometry(entity.width, entity.height, entity.width) geometry.translate(0, entity.height / 2, 0) const material = new THREE.MeshBasicMaterial({ color: 0xff00ff }) const cube = new THREE.Mesh(geometry, material) return cube
57
163
0
+ 3 other calls in file
GitHub: whos-evan/kazwire
69 70 71 72 73 74 75 76 77 78
speed = Math.min(speed, blockConfig.maxSpeed); this.speed = -speed; this.direction = this.speed; // create block let geometry = new THREE.BoxGeometry( this.dimension.width, this.dimension.height, this.dimension.depth );
147
53
0
GitHub: ASSERT-KTH/ci-hackathon
50 51 52 53 54 55 56 57 58 59
return controls; } function addGrid(){ // Add basic box layout and lights var geometry = new THREE.BoxGeometry(...boxSize); geometry = new THREE.EdgesGeometry(geometry); var material = new THREE.LineBasicMaterial( { color: 0xffffff, lineWidth: true } ); var cube = new THREE.LineSegments( geometry, material );
26
28
0
+ 2 other calls in file
GitHub: gracexu94/FinalProject
82 83 84 85 86 87 88 89 90 91
switch (randomInt) { case 0: return new THREE.OctahedronGeometry(); break; case 1: return new THREE.BoxGeometry( 1, 1, 1 ); break; case 2: return new THREE.IcosahedronGeometry(); break;
14
4
0
+ 5 other calls in file
GitHub: Holograf/Holograf
25 26 27 28 29 30 31 32 33 34
//--DodecahedronGeometry(radius, detail) geometries.variable = new THREE.DodecahedronGeometry(25); //--BoxGeometry(width, height, depth, widthSegments, heightSegments, depthSegments) geometries.arrayIndex = new THREE.BoxGeometry( constants.size.arayIndex, constants.size.arayIndex, constants.size.arayIndex ); //--CylinderGeometry(radiusTop, radiusBottom, height, radiusSegments, heightSegments, openEnded, thetaStart, thetaLength) // geometries.conditionalBranch = new THREE.CylinderGeometry(40, 0, 20, 4, 1, true); geometries.conditionalBranch = new THREE.CylinderGeometry(40, 40, 30, 2, 1, true, 0, PI);
9
26
5
103 104 105 106 107 108 109 110 111 112
new THREE.Vector3( 10, -10, 0 ) ); ``` 但实际的应用中,很大一部分Geomety是很类似的。例如所有的立方体,都可以简单的用长宽高,三个属性去唯一确定出一个立方体的形状。所以Three.js的Geometry下预设有30个常用Geometry,以立方体为例: ```javascript var geometry = new THREE.BoxGeometry( 1, 1, 1 ); ``` 这样简单的一行代码,就创建除了一个长宽高为1的立方体。 ### 2.5 Material
16
20
3
+ 3 other calls in file
9 10 11 12 13 14 15 16 17 18
const THREE = require('three') const NodeThreeExporter = require('@injectit/threejs-nodejs-exporters') const fs = require('fs') //generate cube const geometry = new THREE.BoxGeometry( 1, 1, 1 ) const material = new THREE.MeshBasicMaterial( {color: 0x00ff00} ) const cube = new THREE.Mesh( geometry, material ) const exporter = new NodeThreeExporter()
3
4
2
5 6 7 8 9 10 11 12 13 14
import DAT from 'dat-gui' import Stats from 'stats-js' import ProxyGeometry, {ProxyMaterial} from './proxy_geometry' import RayMarcher from './rayMarching' var BoxGeometry = new THREE.BoxGeometry(1, 1, 1); var SphereGeometry = new THREE.SphereGeometry(1, 32, 32); var ConeGeometry = new THREE.ConeGeometry(1, 1); window.addEventListener('load', function() {
11
3
6
GitHub: FabricLabs/verse
196 197 198 199 200 201 202 203 204 205
vehicle.add(vehicleGlow); return vehicle; } function createVoxelMesh (type = 1) { const geometry = new THREE.BoxGeometry(1, 1, 1); const edges = new THREE.EdgesGeometry(geometry); const lineMaterial = new THREE.LineBasicMaterial({ color: 0x000000 }); const edgesMesh = new THREE.LineSegments(edges, lineMaterial); const material = new THREE.MeshLambertMaterial({ color: 0x00ff00 });
1
1
1
85 86 87 88 89 90 91 92 93 94
const hero = ratMesh; hero.updateMatrixWorld(); hero.position.set(30, 0, -30); hero.scale.set(1, 1, 1); bonePoints = []; const boneGeo = new THREE.BoxGeometry(1, 1, 1); const boneMat = new THREE.MeshBasicMaterial({ color: '0xff00ff', wireframe: true }); // if (!DEBUG_MODE) { boneMat.visible = false; // }
0
3
3
GitHub: bgun/cosmosis
82 83 84 85 86 87 88 89 90 91
// camera moves with ship camera.position.set(0,20,20); // camera.up = new THREE.Vector3(0,1,0); // camera.lookAt(15,3,200); var cubeGeom = new THREE.BoxGeometry(0.01,0.01,0.01); var cubeMaterial = new THREE.MeshBasicMaterial({ color: '#4488BB' }); steeringCube = new THREE.Mesh(cubeGeom, cubeMaterial); console.log("start",startPosition); steeringCube.position.set(startPosition.x, startPosition.y, startPosition.z);
0
1
2
124 125 126 127 128 129 130 131 132 133 134 135 136
const directionalLight = new THREE.DirectionalLight(0xffffff, 0.6); directionalLight.position.set(10, 20, 0); // x, y, z SCENE.add(directionalLight); //set cube geometry to use as voxels let VOXEL = new THREE.BoxGeometry( 1, 1, 1 ); ////////////// OTHER SETUP ///////////////
1
2
0
GitHub: teerzo/btx-face
1604 1605 1606 1607 1608 1609 1610 1611 1612 1613
// app.spotLight.position.copy(app.controls.target); app.spotLight.lookAt(app.controls.target); } app.scene.add(app.spotLight); let lightGeo = new THREE.BoxGeometry(1, 1, 1); let lightMat = new THREE.MeshPhongMaterial({ color: 0xFF0000, flatShading: true, wireframe: false, visible: false, transparent: true }); app.lightCube = new THREE.Mesh(lightGeo, lightMat); app.lightCube.update = () => { app.lightCube.position.copy(app.spotLight.position);
1
1
0
+ 2 other calls in file
85 86 87 88 89 90 91 92 93 94
const key = position.toArray().toString(); let geometry; if ( neighbors[ direction ].borderOffset.x == 0 ) { geometry = new THREE.BoxGeometry( boxConstantAlmostOne, boxConstantAlmostOne, borderThickness ); } else { geometry = new THREE.BoxGeometry( borderThickness, boxConstantAlmostOne, boxConstantAlmostOne ); } var box = new THREE.Mesh( geometry, material ); let newPos = position.clone().add( neighbors[ direction ].borderOffset ); box.position.set( newPos.x, newPos.y, newPos.z );
1
1
0
+ 9 other calls in file
21 22 23 24 25 26 27 28 29 30
this.minThickness = 0.01; this.textureGeometry = new THREE.Geometry(); this.intersectionVoxelGeometry = new THREE.BoxGeometry(1.0, 1.0, 1.0); this.anchorGeometry = new THREE.SphereGeometry(0.35, 0.35, 0.35); this.anchorMaterial = new THREE.MeshBasicMaterial({ color: 0xff0000 }); this.anchorParent = new THREE.Object3D();
1
1
0
+ 9 other calls in file
GitHub: ASLS-org/studio
235 236 237 238 239 240 241 242 243 244
floorMaterial.push(sideMaterial); floorMaterial.push(sideMaterial); floorMaterial.push(sideMaterial); floorMaterial.push(checkerMaterial); const floor_geometry = new THREE.BoxGeometry(50, 50, .5, 1, 1, 1); const floor = new THREE.Mesh(floor_geometry, floorMaterial); floor.position.setZ(-.25) SceneManager.add(this.globalLightHandle, floor, axesHelper);
0
7
0
+ 3 other calls in file
GitHub: 0xFlicker/onchaingas
85 86 87 88 89 90 91 92 93 94
opacity: 0.5, color: 16777147, blending: THREE.AdditiveBlending, }); const GAS_PARTICLE_SIZE = 20; const gasParticleGeometry = new THREE.BoxGeometry( GAS_PARTICLE_SIZE, GAS_PARTICLE_SIZE, GAS_PARTICLE_SIZE );
0
3
0
GitHub: jsdf/robot-control
240 241 242 243 244 245 246 247 248 249
} this.lineGeometry.verticesNeedUpdate = true; } makeBox(size: number, color: number | string, wireframe: boolean = false) { const geometry = new THREE.BoxGeometry(size, size, size); const material = new THREE.MeshBasicMaterial({color, wireframe}); const cube = new THREE.Mesh(geometry, material); return cube; }
0
3
0
676 677 678 679 680 681 682 683 684 685
// create geometry var fix = 0.001 // if a value happens to be 0, the geometry becomes a plane and will have 4 vertices instead of 12. var geometry = new THREE.BoxGeometry(width + fix, height + fix, length + fix) geometry.faceVertexUvs[0] = [] // assign materials
0
2
0
three.Vector3 is the most popular function in three (22341 examples)