Not sure if you gave it a try, but I did myself. From the inner workings of the " How to get the uv coordinate of a mesh" example, I am focusing on these scripts:
renderLayerTotexture.js
and
brush.js
I write in much of your Lines-on-Cube example in renderLayerTotexture.js like this:
// initialize code called once per entity
RenderLayerTotexturePnt.prototype.initialize = function() {
// Create a 512x512x24-bit render target with a depth buffer
var colorBuffer = new pc.Texture(this.app.graphicsDevice, {
width: 512,
height: 512,
format: pc.PIXELFORMAT_R8_G8_B8_A8,
autoMipmap: false
});
colorBuffer.minFilter = pc.FILTER_LINEAR;
colorBuffer.magFilter = pc.FILTER_LINEAR;
this.renderTarget = new pc.RenderTarget(this.app.graphicsDevice, colorBuffer, { depth: false });
// create a layer for rendering to texture, and add it to the beginning of layers to render into it first
this.paintLayer = new pc.Layer({ name: "paintLayer" });
this.fromExistingLayersID_toNewOnes = 20;
this.app.scene.layers.insert(this.paintLayer, this.fromExistingLayersID_toNewOnes);
/// paintlayer to RenderTarget:
var paintCamera = this.app.root.findByName("RenderCamera");
paintCamera.addComponent("camera", {
// clearColorBuffer: false, // already as such in editor
projection: pc.PROJECTION_ORTHOGRAPHIC,
layers: [this.paintLayer.id]
});
var layer = this.app.scene.layers.getLayerByName(this.layerName);
layer.renderTarget = this.renderTarget;
};
RenderLayerTotexturePnt.prototype.newPaintLayer = function(){
// henter fra foerste deklaration i raycastPnt:
this.fromExistingLayersID_toNewOnes++;
this.app.scene.layers.insert(this.paintLayer, this.fromExistingLayersID_toNewOnes);
// set up layer to render to the render targer
this.paintLayer.renderTarget = this.renderTarget;
};
In brush.js I call the newPaintLayer function each time a brush is pressed:
...
// Create new paintlayer at renderLayerToTexture:
var newPntLayerFunction_Ent = this.app.root.findByName("Root"); var newPntLayerFunction_Scr = newPntLayerFunction_Ent.script.renderLayerTotexturePnt;
var brushs = this.app.root.findByName("Brush Group").children;
brushs[0].element.on("click",function() {
this.brushSize = 3;
for(var i = 0;i < brushs.length;brushs[i++].element.color = pc.Color.WHITE);
brushs[0].element.color = pc.Color.RED;
this.chosenColor =0;newPntLayerFunction_Scr.newPaintLayer();
},this);
Unfortunately it now outputs me the error of:
Trying to bind current color buffer as a texture