Hi, I have this function that tries to turn an object into Phantom Object (for an AR application).
Phantom objects are those that are drawn to the depth buffer but not to the frame buffer.
Primitives.togglePhantom = function(entity)
{
if (entity.isPhantom === undefined)
entity.isPhantom = true;
else if (entity.isPhantom === false)
entity.isPhantom = true;
else
entity.isPhantom = false;
var model = entity.model.model;
if (model !== null)
{
var materials = model.getMaterials();
for (var i = 0; i < materials.length; i++)
{
var material = materials[i];
material.depthTest = true;
material.depthWrite = true;
if (entity.isPhantom === true)
{
material.blueWrite = false;
material.redWrite = false;
material.greenWrite = false;
material.alphaWrite = false;
}
else
{
material.blueWrite = true;
material.redWrite = true;
material.greenWrite = true;
material.alphaWrite = true;
}
material.update();
}
}
};
However, this function works ONLY for those objects created by the editor.
If I create the object programatically (and I need to do it) with:
var entity = new pc.Entity();
entity.name = "cube";
entity.addComponent("model", { type: 'box',});
root.addChild(entity);
and apply the togglePhantom function, then the object only occludes a set of lines created with the renderLine function (a grid that I have placed to serve as reference plane) but not the other objects of the scene.
Can someone give a hint/explanation and a solution for this??
Thanks in advance.