Babylon Decals Positioning

I was working on Babylon decals. I actually manually wanted to position my decals on a vertical wall, but i wasn’t able to get one. My compiler was showing this warning:

BJS - [09:42:59]: Setting vertex data kind ‘position’ with an empty array

Can anyone please help me out

My code was this:

var decalSize = new BABYLON.Vector3(1,1, 1);
                        
var decal = BABYLON.MeshBuilder.CreateDecal("decal", mesh3,size: decalSize});
 
                                        decal.position.x=1.5;
                                        decal.position.y=1.1;
                                        decal.position.z=-0.1;
                                    
 
                                        decal.material = decalMaterial;

Thank you

Welcome aboard!

You should try to repro the problem in the Playground, it will be easier to help you.

Looking at this PG that does work, it seems you are not calling CreateDecal correctly:

var decal = BABYLON.MeshBuilder.CreateDecal("decal", cat,
  {position: pickInfo.pickedPoint, normal: pickInfo.getNormal(true),
     size: decalSize});

The 3rd parameter should be an object and you should pass the position, normal and size.

2 Likes

Okay thanks for answering back. I will create a repro in playground. Meanwhile can you please tell the syntax for creating a decal without using pickInfo(Without using on pointer down) ?

The syntax for creating a decal is written in API - DecalBuilder | Babylon.js Documentation

Here is the example where Vector3 values for position and normal are shown in console after click - https://playground.babylonjs.com/#1BAPRM#465
You may provide your own values when creating a decal, it is not necessary for a decal to be a pointer event.

2 Likes

@labris @Evgeni_Popov

Thank you so much both of you. I was able to do it using the babylon vector3 and normal. Both are essential for decals. Thanks to your guidance.

Here is the code:
Decal Manual Positioning | Babylon.js Playground (babylonjs.com)

2 Likes