I have below code for a cube out of cubes...I managed to get this online but I need to arrange these small cubes in this in an order, not random and also same color not different colours...can some one plz help me how do I change this to all same size and
cubes in a level and all same color please
var geometry = new THREE.BoxBufferGeometry(20, 20, 20);
for (var i = 0; i < 10000; i++) {
var object = new THREE.Mesh(geometry, new THREE.MeshLambertMaterial({ color: Math.random() * 0xffffff }));
object.position.x = Math.random() * 800 - 400;
object.position.y = Math.random() * 800 - 400;
object.position.z = Math.random() * 800 - 400;
object.rotation.x = Math.random() * 2 * Math.PI;
object.rotation.y = Math.random() * 2 * Math.PI;
object.rotation.z = Math.random() * 2 * Math.PI;
scene.add(object);
}
It seems you used the three.js canvas.
From your code, the
BoxBufferGeometryBesides draw a box. In your for()method, the
color were set Math.random() * 0xffffff which a random color. You could refer the API to know how to set
color. And the position or rotation you also set the Math.random() which a random position .You could refer to the API learn more about the “three.js”.
http://threejs.org/docs/index.html#Reference/Objects/Bone .
Best Regards,
Ailleen
MSDN Community Support
Please remember to "Mark as Answer" the responses that resolved your issue.
Member
200 Points
691 Posts
help with this javascript cube please
Aug 15, 2016 07:39 AM|Lexi85|LINK
Hello All,
I have been struggling a lot with this
I have below code for a cube out of cubes...I managed to get this online but I need to arrange these small cubes in this in an order, not random and also same color not different colours...can some one plz help me how do I change this to all same size and cubes in a level and all same color please
Member
540 Points
130 Posts
Re: help with this javascript cube please
Aug 16, 2016 12:48 PM|Ailleen|LINK
Hi Lexi85,
It seems you used the three.js canvas.
From your code, the BoxBufferGeometryBesides draw a box. In your for()method, the color were set Math.random() * 0xffffff which a random color. You could refer the API to know how to set color. And the position or rotation you also set the Math.random() which a random position .You could refer to the API learn more about the “three.js”. http://threejs.org/docs/index.html#Reference/Objects/Bone .
Best Regards,
Ailleen
MSDN Community Support
Please remember to "Mark as Answer" the responses that resolved your issue.
Member
200 Points
691 Posts
Re: help with this javascript cube please
Aug 16, 2016 12:53 PM|Lexi85|LINK
Yes its just that I am unable to figure out how to code for few cubes to be random color and few cubes to be transparent...