URP Decals

Do you have a albedo texture assigned to your material in unity or blender? You can also just serialize the texture in a field if thats what you need

yes I have assigned

by user 1141289362336784394

by user 1141289362336784394

export class DecalProjector extends Behaviour {
showHelpers: boolean = true;

start() {
const decalMaterial = new THREE.MeshStandardMaterial({
map: this.material.map,
normalScale: new THREE.Vector2(1, 1),
transparent: true,
depthTest: true,
depthWrite: false,
polygonOffset: true,
polygonOffsetFactor: -4,
wireframe: false,
side: THREE.FrontSide,
decalMaterial.map.repeat = new Vector2(-1, -1);

if (this.gameObject.parent == null || !this.gameObject.parent.isMesh) return;

var origin = new THREE.Vector3();
var orientation = new THREE.Euler();
var quaternion = new THREE.Quaternion();
var decalSize = new THREE.Vector3(this.size.x, this.size.y, this.size.z);

if (this.showHelpers) {
  var direction = new THREE.Vector3();
  const arrowHelper = new THREE.ArrowHelper(
    new Vector3(0, 0, 1),
    new Vector3(0, 0, decalSize.z * -0.5),
    decalSize.z * 0.1,
    decalSize.z * 0.05

  const box = new THREE.Box3();
  box.setFromCenterAndSize(new Vector3(0, 0, 0), decalSize);
  const boxHelper = new THREE.Box3Helper(box, 0x00ff00);

var decalGeometry = new DecalGeometry(this.gameObject.parent, origin, orientation, decalSize);
var mesh = new THREE.Mesh(decalGeometry, decalMaterial);

This is my updated code.

by user 1141289362336784394

var decalGeometry = new DecalGeometry(this.gameObject.parent, origin, orientation, decalSize);
In this line i am not able to get the mesh component from the this.gameObject.parent.
What am i missing?

by user 1141289362336784394

You cant use a custom shader graph or when you do make sure you access the correct texture name and make sure your shader is marked for export. Check our docs for custom shaders. In your case your texture is named BaseMap (most likely, check in the texture) so the texture name in threejs is the same. The example above used a material with a standard threejs shader (which is used when your material in unity is e.g. a standard lit or urp lit material) in which case the property name is “map”. Thats why map is null in your case with a different shader

You can just console log your material in the web and check the browser console to see all names of your material.

Thanks a lot for your guidance. I have changed the material to standard now i am able to get the map.
Now I am getting stuck at this line
this.gameObject.parent.isMesh is returning undefined.(gameobject has parent object)

by user 1141289362336784394

When I console log the this.gameobject.parent i couldn’t find isMesh variable.

by user 1141289362336784394

You parent mesh is a multimaterial object in unity (a mesh with submeshes) in which case its a Group in threejs (now each child of this object is a mesh, you see it in the console where you have 3 mesh children)

Thanks a lot my lord🫡 . It worked when i changed to a plane without submeshes.

by user 1141289362336784394