For more information about the next generation Spectacles, click here.

Copying Device texture in Spectacles

Andrew Mendez
Andrew Mendez Posts: 2
edited May 17 in General #1

Is it possible to copy a camera device texture in Spectacles, the below code works in lens studio, but when I run it in spectacles, the width and height of the texture is a 1x1 image:

// -----JS CODE-----
// @input Asset.Texture DeviceCamTex;
// @input Component.Image displayImage;

const CHANNELS = 4; // RGBA
var cap = script.DeviceCamTex.copyFrame();
print('Cwidth: '+cap.getWidth());
print('Cheight: '+cap.getHeight());
var tex = ProceduralTextureProvider.createFromTexture(cap);
var width = tex.getWidth();
var height = tex.getHeight();
print('width: '+width);
print('height: '+height);
var pixelArray = new Uint8Array(width * height *CHANNELS);
tex.control.getPixels(0,0,width, height, pixelArray);

//var resultTex = ProceduralTextureProvider.create(width, height, Colorspace.RGBA);
var resultTex = ProceduralTextureProvider.createFromTexture(script.DeviceCamTex);

resultTex.control.setPixels(0,0,width,height,pixelArray);
script.displayImage.mainPass.baseTex = resultTex;