In a 3d scene, how do I create an effect like this?
My initial thought for a simpler version of this was to find the extent of the camera, then draw a series of boxes that get smaller and more transparent, so you’d get about an inch of this effect at the edge of the screen. But I can’t even get a line to render at the moment; if I choose the UI layer, nothing happens, and if I choose the world layer everything goes black:
PickerRaycast.prototype.onSelect = function (x, y) {
var from = this.entity.camera.screenToWorld(x, y, this.entity.camera.nearClip);
var to = this.entity.camera.screenToWorld(x, y, this.entity.camera.farClip);
var pickedEntity = this.app.systems.rigidbody.raycastFirst(from, to);
if (pickedEntity && pickedEntity.entity.name == 'TargetModel') {
//console.log("selected correct model");
// trigger positive feedback animations
} else {
// trigger negative feedback
var start = new pc.Vec3(0, x, y);
var end = new pc.Vec3(1, x+100, y+100);
var color = new pc.Color(1, 1, 1);
var UILayer = this.app.scene.layers.getLayerById(pc.LAYERID_UI);
this.app.renderLine(start, end, color, {
layer: UILayer
});
}
};
line rendering to world layer is broken … we have an issue opened for this. Use pc.LAYERID_IMMEDIATE instead (which is a default if you don’t specify a layer). But note that coordinates need to be in world space for it I believe.
You could use the procedure mesh API and generate a bunch of triangles. Texture then with an image that I s solid colour in the middle and fades out to the edge.
That should get you pretty close if you wanted a code only solution.
It would also give you room to make it random too by shifting the triangle point