2

There is no direct way to change colours using patch editor in Spark AR, using the script seems to not work too, even though I was able to affect the opacity of the material using in the last line, I get no error inside Spark it just does not work but the editor keeps highlighting the first argument of Reactive.RGBA and give me this error

Argument of type '0' is not assignable to parameter of type 'ScalarSignal'.ts(2345)

are there any solutions to this?

const Materials = require('Materials');
const Textures = require('Textures');
const Diagnostics = require('Diagnostics');
const Scene = require('Scene');
const NativeUI = require('NativeUI');
const Patches = require('Patches');
const Reactive = require('Reactive');
var Animation = require('Animation');


const plane = Scene.root.find('plane0');

//Materials.get('material0').diffuse = Reactive.RGBA(1,0,1,1);
plane.material.color = Reactive.RGBA(0.2,0,1,0.5);
//plane.Textures.color = Reactive.RGBA(1,0,1,0.5);
//plane.material.opacity = 0.5; 

enter image description here enter image description here

Kamel Labiad
  • 525
  • 1
  • 6
  • 26

3 Answers3

2

I happen to be working on a similar thing, what I have up until now is something like this;

var texSig = Textures.get('1').signal;//optional for your use
var packedCol = Reactive.pack4(1, 0.5, 0.7, 1);
var newCol = Reactive.mul(texSig, packedCol);//optional for your use

const textureSlot = Shaders.DefaultMaterialTextures.DIFFUSE;
Materials.get('material0').setTexture(newCol, {textureSlotName: textureSlot});

You could skip the multiplying with a texture to just change the color of the material. I'm searching for a way to get color from the patch editor to the unpackedColor variable and so you don't have to type in the values but use the colorpicker in the patch editor instead. I hope this helped!

Wilrick B
  • 135
  • 8
1

Pretty old question, but very few spark AR questions are answered on stackoverflow even today :( so maybe it will help someone in the future:

You need to set diffuseColorFactor, for example:

diffuseColorFactor = Reactive.RGBA(0.1,0.2,0.3,0.5)

Finding the actual property names is very hard in spark AR, as it is not what you see in the Studio GUI. I tend to find it with a mix of the docs and by enumerating the properties of the actual Javascript object in my code, kind of reverse engineering it:

const stuff = await Materials.findFirst(`particle_h`) 
for (const property in stuff) {
  try{
   Diagnostics.log(`${property}: ${stuff[property]}`);
  }
  catch{
   Diagnostics.log(property);
  }
} 
-1
  1. Using RGBA:

RGBA to material color

  1. Using color:

enter image description here

  1. Coloring texture:

enter image description here

Paweł Krakowiak
  • 368
  • 3
  • 11
  • You have to take in consideration that the material has a texture already and I don’t want to loose it, the texture get lost if you apply a colour alone, when I apply texture in the patch editor it stretch it all over the object and loose to UV coordinates – Kamel Labiad Sep 27 '19 at 11:05
  • 1. Which version of Spark AR do you use? 2. Have you tried with different model? – Paweł Krakowiak Sep 27 '19 at 11:46
  • V7, this wont change if you change models – Kamel Labiad Sep 27 '19 at 11:48
  • I'm asking about different models, cause I've been using it many times without such issues. This may be specific model/format problem. The second case is that you're saying about Tiling Options which may be fixed by using UVs directly. – Paweł Krakowiak Sep 27 '19 at 12:17
  • Yes it is specific it is ring around the head, once you apply texture using patch editor the UV get locked and you cant control it – Kamel Labiad Sep 27 '19 at 12:19