Skip to content

Instantly share code, notes, and snippets.

@Leprosy
Last active May 9, 2020 13:23
Show Gist options
  • Save Leprosy/6885737 to your computer and use it in GitHub Desktop.
Save Leprosy/6885737 to your computer and use it in GitHub Desktop.
Mockup model generator for THREE.js.
/* Model mockup */
var colors = [0xcceeee, 0xddeeff, 0xeeccee, 0x00cc00, 0x0000cc, 0xcc3333];
for (i = 0; i < 10; ++i) {
var w = 200 * Math.random();
var h = 200 * Math.random();
var d = 5 * Math.random() + 1;
var dx = (Math.random() * 40 - 20);
var dy = (Math.random() * 40 - 20);
var dz = Math.random() * 10;
var color = colors[Math.round(Math.random() * 5)];
var material = new THREE.MeshBasicMaterial({
color : color,
opacity: 0.4,
transparent: true,
side: THREE.DoubleSide
});
var wire = new THREE.MeshBasicMaterial({
color: color,
wireframe: true,
wireframeLinewidth: 2
});
var geo = new THREE.CubeGeometry(w, h, d);
var mesh1 = new THREE.Mesh(geo, material);
var mesh2 = new THREE.Mesh(geo, wire);
mesh1.position.x = mesh1.position.x + dx;
mesh1.position.y = mesh1.position.y + dy;
mesh1.position.z = dz;
mesh2.position.x = mesh2.position.x + dx;
mesh2.position.y = mesh2.position.y + dy;
mesh2.position.z = dz;
// add the meshes to the scene
scene.add(mesh1);
scene.add(mesh2);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment