Forum

Check if object has vertex color data

17 July 2018 17:54
I'm strugling with checking whether object has vertex color data or not.
The context is: I'm setting the vertex color material on click and it's working nicely for objects with vertex color data however if i set the material to the object without vertex color data I have b4w Error:
b4w.simple.min.js:583 B4W ERROR: missing data for "a_color" attribute
b4w.simple.min.js:1738 Uncaught engine panic:
The engine tried to perform an invalid operation and halted.
Please copy the console contents above and submit it to the Blend4Web forum at
https://www.blend4web.com/en/forums/forum/17/

There is low level api:
m_geom.extract_vertex_array(clothAnim,check_list[0],'a_color',m_scenes.DATA_ID_ALL);
but it doesn't return an array until the specified material is vertex color painted. Which is what I try to know in the first place.
18 July 2018 09:08
The context is: I'm setting the vertex color material on click
??? Could you describe PRECISELY what you are doing? You have a material with the "Vertex Color Paint" option checked and you copy that material onto an object with inherit_material - is that it?

however if i set the material to the object without vertex color data I have
b4w.simple.min.js:1738 Uncaught engine panic:
That is correct. I was able to reproduce this crash. But why would you assign a vc material to an object that has no vc layer? I mean, why not either make the non-vc objects unclickable, or give them a blank vc layer from the outset?

Anyway, you found a workaround:
There is low level api:
m_geom.extract_vertex_array
but it doesn't return an array until the specified material is vertex color painted. Which is what I try to know in the first place.
As I see it, it returns an array if the material has "Vertex Color Paint" checked (Material tab in Blender) AND the object has a vertex color layer (Data tab in Blender) - otherwise it returns NULL. That's all you need for checking if the object has vertex color data:
var check_for_vc_presence = m_geom.extract_vertex_array(your_object_reference, "your_material_name", "a_color")

if (check_for_vc_presence == null) 
  // object has no vertex color data;
else 
  // object DOES have vertex color data
This works for me.
18 July 2018 12:04
Thank you for helping.

You have a material with the "Vertex Color Paint" option checked and you copy that material onto an object with inherit_material - is that it?

Yes that's exactly what I'm trying to do.

The thing is I don't know if the object has the color data, It's sent to the server from the client and we have no more information about it.
Adding special prefix to the name is workaround, but would work.


As I see it, it returns an array if the material has "Vertex Color Paint" checked (Material tab in Blender) AND the object has a vertex color layer (Data tab in Blender) - otherwise it returns NULL. That's all you need for checking if the object has vertex color data:

That's true. But what if the object maybe has maybe not the color data and the material it doesn't have "Vertex Color Paint" checked.

There are options:
#1
- Object material Vertex Color Paint checked
- Object has a vertex color layer
Then we can check in javascript extract_vertex_array that it has color array and returns true - that's OK

#2
- Object material Vertex Color Paint checked
- Object hasn't a vertex color layer
Then we can check in javascript extract_vertex_array that it has color array and returns false - that's OK

#3
- Object material Vertex Color Paint unchecked
- Object has or hasn't a vertex color layer
Then we can't check in javascript extract_vertex_array that it has color array because always returns false - even if the object has color data, there is no way to check that because it always returns false. And coping the material(with Vertex Color Paint checked) onto this object is fine only when it really has the color data(otherwise crash) - but tere is no way to check if setting the material will make crash.
18 July 2018 15:32
The thing is I don't know if the object has the color data, It's sent to the server from the client and we have no more information about it.
Adding special prefix to the name is workaround, but would work.
That makes a lot more sense now because I was wondering why you would even bother about working around this problem since you should know which objects have vertex color materials and which don't.

There are options:
#1
#2
#3
This is exactly what I got as well. You will always get FALSE if the checkbox is not checked, and then you have no way of determining the color data status.

And coping the material(with Vertex Color Paint checked) onto this object is fine only when it really has the color data(otherwise crash) - but tere is no way to check if setting the material will make crash.
Correct. But ultimately, do you want to pass the vc material onto objects that come in without color data (i.e. do you want to pass the material basically onto ALL objects and you're only looking for a way to do it), or do you actually want to separate out those cases and not pass them the material?
 
Please register or log in to leave a reply.