I am trying to create a dices using threejs and cannon-es. The dices are of 3 different shapes - cube, tetrahedron and octahedron. What I want to do is to add numbers to the different sides of the dice and later see which number landed on the top. How can I do both these things? I have used MeshPhongMaterial to create all the dice. Like this -
const boxGeo = new THREE.BoxGeometry(2, 2, 2);
const boxMat = new THREE.MeshPhongMaterial({
color: 0x00ff00,
wireframe: false,
});
const boxMesh = new THREE.Mesh(boxGeo, boxMat);
@hofk, I’m a complete beginner to threejs, none of these examples have helped me. Is there an easier or direct way to show the numbers on the sides of the cube ? I have been stuck on this for several days.
I think you could make a white cube in three.js (shown in the first tutorial) and add black dots to the faces (by making circles. THREE.JS - GEOMETRIES | Three.js)
So, because so many people start using this project to make dice, they made a special mesh object for it. A mesh is made out of two things - a geometry and a skin that covers the geometry (called a material).
They create that object in this line:
const diceMesh = new THREE.Mesh( diceGeometry, diceMaterials );
This sounds like: “I don’t know Japanese. Is there an easier or direct way to speak Japanese instead of using automatic translation?”
I’m sorry, I do not know any easier way to circumvent learning. The only ways are to learn, to pay someone who already learned it … or to find an existing library that does what you need.
If what you try to do is beyond your current skills, do not get discouraged, but inspired. My sincere advice is to split the problem into smaller problems, and resolve them one by one. For example, the problems could be:
how to build a Platonic solid
how to add a picture on a solid
how to add a picture on a specific side of a solid
how to generate a picture by code
how to roll the dice with Cannon-es
how to get the orientation of a dice at any moment
@hofk , thank you this is of great help ! Could you please also guide me as to how I can put html elements on the sides of the dice? I have tried doing it by following this example using CSS2dRenderer but it is not working for some reason. -
const boxGeo = new THREE.BoxGeometry(2, 2, 2);
const boxMat = new THREE.MeshPhongMaterial({
color: 0x00ff00,
wireframe: false,
});
const boxMesh = new THREE.Mesh(boxGeo, boxMat);
var earthDiv = document.createElement("div");
earthDiv.className = "label";
earthDiv.textContent = "Earth";
earthDiv.style.color = "#000000"
earthDiv.style.fontSize = "2rem"
earthDiv.style.marginTop = "-1em";
var earthLabel = new CSS2DRenderer.CSS2DObject(earthDiv);
earthLabel.position.set(0, 3, 0);
boxMesh.add(earthLabel);
also @hofk, I am rendering the images on the cube but it is taking over the entire side of the cube and making it white, instead of just the numbers appearing on top of the original cube like this -
I have tried using both svgs and pngs but the result is the same for some reason. I just want the numbers to appear and not the white background with them?
@prisoner849, I have taken a look at those examples, but the issue I am facing with them is that the canavs texture is completely taking over the shapes and thus they are losing the features that MeshPhongMaterial provides like reacting to the light. How can I accomplish this? Could you please show me how you are doing the same with the shapes in the images you provided?
Start to provide an editable live code examples, that demonstrate issues, so the other forum users could see what and how you do, thus, they could provide proper help.