Hi there, @Blake and @Evgeni_Popov:
First, I apologize for the missing of a PG here, but my scene is very large and intended to be used in a non-public project. Anyway, I’m only looking for any general guidance and tips here.
The case is that, I’m experimenting a strange issue related to Decals.
In order to identify the perfect place for my decals, I’m using a code like this over a running scene, intended to capture the decal’s data:
_scene.onPointerObservable.add(function (evt) {
switch (evt.type) {
case BABYLON.PointerEventTypes.POINTERPICK:
var pickResult = _scene.pick(_scene.pointerX, _scene.pointerY);
if (pickResult.hit) {
//written data to be noted in order to be used later
alert("Mesh: " + pickResult.pickedMesh + "\nPoint: " + pickResult.pickedPoint + "\nNormal: " + pickResult.getNormal(true));
//I take this opportunity to show the decal and check is all OK
var decalMat = new BABYLON.StandardMaterial("decalMat", _scene);
decalMat.diffuseTexture = new BABYLON.Texture("/assets/textures/dirt.png", _scene);
decalMat.diffuseTexture.hasAlpha = true;
decalMat.zOffset = -2;
//
var decalMesh= BABYLON.MeshBuilder.CreateDecal("decal", pickResult.pickedMesh, {
normal: pickResult.getNormal(true),
position: pickResult.pickedPoint,
size: new BABYLON.Vector3(0.1, 0.1, 0.1)
});
decalMesh.material = decalMat;
}
break;
...
As I want to create all my decals by code, I only use the previous code in order to take note of the decal-related data from the “alert”. Those data will be written down later in the following decal creation code (see XXX_FROM_ALERT_OUTPUT in the following code)…
...
//1) material for the decal
var decalMat = new BABYLON.StandardMaterial("decalMat", _scene);
decalMat.diffuseTexture = new BABYLON.Texture("/assets/textures/dirt.png", _scene);
decalMat.diffuseTexture.hasAlpha = true;
decalMat.zOffset = -2;
//2) the decal itself
var decalMesh= BABYLON.MeshBuilder.CreateDecal("decal", scene.getNodeByName(MESH_FROM_ALERT_OUTPUT), {
normal: NORMAL_FROM_ALERT_OUTPUT,
position: POSITION_FROM_ALERT_OUTPUT,
size: new BABYLON.Vector3(0.1,0.1,0.1)
});
decalMesh.material = decalMat;
...
Doing so, sometimes it works and other times I get the infamous “Setting vertex data kind ‘position’ with an empty array”.
How is that possible that the same decal-creation-data used in the interactive creation of them (first block of code shown) is not valid (sometimes) when using that same data in the same scene in order to re-create that same decals from that data (second block of code shown)?
In a more specific way, how it can be that BJS complains about “Setting vertex data kind ‘position’ with an empty array” being position a not empty array at all?
May it be that weird behavior related with the fact that decals are working only with not-animated geometry? I’m not done yet a comprehensive survey on that.
May it be related with optimization tweaks I’m conducting in the scene?
Any help on this?
Thanks for your time.