10

I want to put a decal inside a segment of a tube geometry (in the backface).

The way I do is use TubeGeometry as the decal geometry.

This is what I have: enter image description here

And this is what I want: enter image description here (bad drawing)

Sample code:

//code
var tube = new THREE.TubeGeometry(pipelineSpline, 200, 20, 20, closed2);

tubeMesh = THREE.SceneUtils.createMultiMaterialObject(
       geometry, [
            material,       // a phong material
            materialInside // a material for the inside               
       ]);

scene.add(tubeMesh); 

var decalGeometry = new THREE.DecalGeometry(
      tubeMesh.children[0], 
      new THREE.Vector3(0,0,0),      //position
      new THREE.Vector3(0,1,0),      //direction
      new THREE.Vector3(10,10,10),   //dimensions
      new THREE.Vector3(0,0,0)       //check
    );

However this seems to apply a decal of the tube along all the backside geometry path. And I want it only on one part of the BackSide of the Tube on key positions.

How can I make a localized decal in a TubeGeometry using THREE.DecalGeometry? Is it possible?

Rui d'Orey
  • 982
  • 3
  • 13
  • 31

1 Answers1

3

You will need to use a ShaderMaterial for this, and define the positioning and opacity rules in the shader code and the various uniform (e.g., the new texture) and parameter (e.g., UV) values passed to it by THREE.js.

bjorke
  • 3,295
  • 1
  • 16
  • 20
  • Thank you for your answer. And cant it be done with using THREE.DecalGeometry https://github.com/spite/THREE.DecalGeometry? Best – Rui d'Orey Nov 08 '15 at 09:15
  • 2
    That's not in the standard library :) A geo-heavy method like that is good for set-dressing, but will struggle if the decals are being placed dynamically (say, as explosion burns in a game). Only you know the context you need. – bjorke Nov 09 '15 at 16:22
  • Thank you @bjorke They will be put at the start of the scene... like 10 along the pipe and then will be static – Rui d'Orey Nov 09 '15 at 20:16
  • 1
    This question interests me as well, can't the decal be applied just to some faces of a mesh as an extra material with a texture map? Just thinking if there's an easier way than going through a custom shader – MacK Nov 14 '15 at 11:40
  • Hi @MacK If it works is great for me. I also thought of something along this lines: I only know the world coordinates of the decal, so I might need to do some automatic raycast by some way to find say the 4 left lateral faces of the tube and maybe use MeshFaceMaterial to put the texture there... I don't know if can apply a texture to cover a set of faces without the texture repeating itself for each face... – Rui d'Orey Nov 14 '15 at 15:51