Public
Edited
May 22, 2022
1 star
Insert cell
Insert cell
Insert cell
Insert cell
genererFigures = {
const figures = [];
const features = { Name: "" };
const parametric = {};

// you import anything from outside (no functions or libraries)
// should not produce any collateral effect
// You have access to fxrand()
// figures and features constants are the only other variables you have access to

// if you are not sure of the scale, make all geometry sizes and positions related
// to a constant;

// ------ your code starts here ------

// Here the variable u is the unit used to scale
const u = 1;

//simple cube

parametric.noise = noise;

figures.push({
geometry: {
type: "ParametricGeometry", // Type of geometry
args: [
// Arguments relevant to the geometry (check THREE API)
"noise",
25,
25
]
},
pos: {
// Position
x: 0 * u,
y: 0 * u,
z: 0 * u
},
rot: {
// Rotation
x: 0,
y: 0,
z: 0
},
lines: false, // Display color segments (like wireframe, but faces not triangles)
hatch: true, // Fill with white texture
full: false // Fill with color texture (in the anaverse, red and cyan)
});

// ------ your code ends here ------

return { figures, features, parametric };
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
scene = {
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x001b42);

//manufacture
genererFigures.figures.forEach((fig) => {
var geometry;

if (fig.geometry.type === "ParametricGeometry") {
// welcome to the jungle
//console.log(genererFigures.parametric[fig.geometry.args[0]]);
geometry = new THREE.ParametricGeometry(
genererFigures.parametric[fig.geometry.args[0]],
fig.geometry.args[1],
fig.geometry.args[2]
);
} else {
geometry = new THREE[fig.geometry.type](...fig.geometry.args);
}

console.log(geometry);

var edgeGeometry;
if (fig.lines) {
edgeGeometry = new THREE.EdgesGeometry(geometry);
}
var pos = new THREE.Vector3(fig.pos.x, fig.pos.y, fig.pos.z);
var rot = new THREE.Vector3(fig.rot.x, fig.rot.y, fig.rot.z);
if (fig.scale) {
var scale = new THREE.Vector3(fig.scale.x, fig.scale.y, fig.scale.z);
}

if (fig.lines) {
const line = new THREE.LineSegments(edgeGeometry, lineMaterial);
line.position.set(pos.x, pos.y, pos.z);
line.rotation.set(rot.x, rot.y, rot.z);
if (fig.scale) {
line.scale.set(scale.x, scale.y, scale.z);
}
scene.add(line);
}

if (fig.hatch) {
const hatch = new THREE.Mesh(geometry, hatchMaterial);
hatch.position.set(pos.x, pos.y, pos.z);
hatch.rotation.set(rot.x, rot.y, rot.z);
if (fig.scale) {
hatch.scale.set(scale.x, scale.y, scale.z);
}
scene.add(hatch);
}

if (fig.full) {
const full = new THREE.Mesh(geometry, fullMaterial);
full.position.set(pos.x, pos.y, pos.z);
full.rotation.set(rot.x, rot.y, rot.z);
if (fig.scale) {
full.scale.set(scale.x, scale.y, scale.z);
}
scene.add(full);
}
});

return scene;
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
THREE = {
const THREE = (window.THREE = await require("three@0.99.0/build/three.min.js"));
await require("three@0.99.0/examples/js/controls/OrbitControls.js").catch(
() => {}
);

return THREE;
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more