I’ve got an object on which I’d like to add something like a text or an image.
For example: An object with a rough-looking material/texture which has a shiny text on it.
I already have an object with a rough-looking material/texture, but what is the best approach to add a shiny text to it? is decalGeometry the best approach?
Depending on your use case DecalGeometry is one way to project a text onto an existing surface. However, you need to write the text on a texture (e.g. write the text to a 2D canvas and then use CanvasTexture) and then use it as the diffuse map for the decal.
If you need more control over how the text is added to the object, you might want to add the text in a DCC tool like Blender and not at runtime.
For this example I used a small jpeg (just an image) to project it onto my object but I’m still having trouble.
let decalImage = new THREE.TextureLoader().load(‘Decal/ObjectDecal.jpg’);
let decalMaterial = new THREE.MeshPhongMaterial({
map: decalImage,
transparent: true,
depthTest: true,
depthWrite: false,
polygonOffset: true,
polygonOffsetFactor: -4,
wireframe: false
});
let decalGeometry = new THREE.DecalGeometry(
myObject,
new THREE.Euler(0, 20.5, 30),
new THREE.Euler(0, 0, 0),
new THREE.Euler(80, 80, 80),
myObjectMaterial
);
decal = new THREE.Mesh(decalGeometry, decalMaterial);
scene.add(decal);
I tried to solve the problem using the three.js-documentation but I’m still having trouble.
When I try this code there is this error: Cannot read property ‘geometry’ of undefined
Now I used the correct parameterization but there is still the mentioned error.
“DecalGeometry.js:62 Uncaught TypeError: Cannot read property ‘geometry’ of undefined
at generate (DecalGeometry.js:62)
at new THREE.DecalGeometry (DecalGeometry.js:43)
at index.html:267
at Object.onLoad (HDRCubeTextureLoader.js:104)
at XMLHttpRequest. (three.min.js:755)”
Correct . If you are going to implement a real app, I suggest you import the modules from the official npm package and then perform a build (e.g. with rollup) to produce your final app bundle. There are several starter projects that simplify the respective setup. E.g. Module Import / Usage - #26 by seanwasere
This sounds good so far.
It may be a pretty rough question -> But what are the main advantages using modules?
I’m not quite sure if I need them, and it sounds a little confusing too.