Hello everyone! I’m very happy I found this community and I hope one of you can help me get me out of my current coding pickle
I’m trying to learn the scripting part of Spark AR by following Sohail Mehra’s first tutorial.
However, it is possible something has changed in the API since the tutorial was published because, although I feel like I followed the instructions closely, I’m currently stuck with errors I do not understand how to fix.
Here is the code (error below):
const Materials = require('Materials');
const Shaders = require('Shaders');
const Textures = require('Textures');
const Time = require('Time');
const Reactive = require('Reactive');
export const Diagnostics = require('Diagnostics');
function print(a)
{
Diagnostics.log(a);
}
const material0 = Materials.findFirst('material0');
const cameraTexture = Textures.findFirst('cameraTexture0');
function main()
{
const uvs = Shaders.vertexAttribute({"variableName" : Shaders.vertexAttribute.TEX_COORDS});
const ct = Reactive.mul(Time.ms,0.001);
const curve = Reactive.abs(Reactive.sin(ct));
const color = Shaders.textureSampler(cameraTexture, uvs);
const modulationColor = Reactive.pack4(curve,0,0,1);
const finalColor = Reactive.mul(color, modulationColor);
const textureSlot = Shaders.DefaultMaterialTextures.DIFFUSE;
material0.setTexture(mix2, {textureSlot: textureSlot});
}
main();
And the error I’m getting:
Error:Exception in HostFunction: Wrong object reference. Expected: native object reference
at ShadersModule::textureSampler (native)
at main (file:///7a6d89b6b47ba717bea40ff1cc728f46.js:865:37)
{
"line": 24,
"column": 41,
"sourceURL": "script.js"
}
Line 24 is this one:
const color = Shaders.textureSampler(cameraTexture, uvs);
Can anyone point me to what I’m doing wrong? I’d be very grateful.
PS: I’m using Spark AR Studio Version: 102.0.0.27.234
PPS: By the way, if you have any other resources for learning the scripting API (besides the official documentation), that would be amazing!
Thanks!