VRay Plugin: How to retrieve user defined attribute & object's transform info ?

Hi,

Is it possible to get these geometry(or let’s say object) related data in texture(or material\brdf) plugin ? I’ve traced the infomation contained in VUtils::RayResult, VUtils::IntersectionData, VUtils::GenericPrimitive and VUtils::GeometryGenerator but still got nothing usful. Which class equipped with these functionaliy ?

Thanks.

Yo want to do something similar to the sampler info texture?

VR::ObjectShadeInstance *si=(VR::ObjectShadeInstance*) GET_INTERFACE(rc.rayresult.si, EXT_OBJECT_SHADE_INSTANCE);

The sampler info texture example helps to solve the problem object id retrieving, but i still struggle with how to get user attribute :slight_smile:
I found the tex_mult.cpp provide some hint: The user attribute seems could be retrieved by using getUserProperty() of VUtils:: DefaultVRayShadeData. However the document not provide any detail ablut this function so i don’t know exactly how it works. The return data of getUserProperty() is of type tchar*, how it works if my user attribute is float, vector, matrix rather than string ?

An extra question is in tex_mult.cpp i see two statement about query VRayShadeData object’s interface:
queryInterfaceVR::VRaySurfaceUserAttributes(rc.rayresult.sd, EXT_SURFACE_USER_ATTRIBUTES);
queryInterface<VR:: DefaultVRayShadeData>(rc.rayresult.sd, EXT_DEFAULT_SHADE_DATA);
How can i know all the possible interface that can be queried for VRayShadeData object ? (These information seems not detailed in document)

The user attributes are generally strings and V-Ray itself makes no attempt to convert them to any specific values; how they are interpreted depends entirely on the plugin that reads them. The user color and user scalar textures interpret them in a specific way, but you may want to do something different. I’m attaching the code that we use for those textures. Note that it would be slow to do the conversion at every single shading hit; some kind of hash table to look up the computed value might be more appropriate. If you think this is useful, we can probably fold the code into V-Ray itself.

How can i know all the possible interface that can be queried for VRayShadeData object ? (These information seems not detailed in document)That’s an unfortunate disadvantage of using interfaces - it is not clear which interfaces can be queried for a given object type just by looking; nor is it possible to list the interfaces that a given object supports. With that said, the ones that I find by searching through the V-Ray plugins for rc.rayresult.sd are:

EXT_SURFACE_USER_ATTRIBUTES
EXT_DEFAULT_SHADE_DATA
EXT_MAPPED_SURFACE
EXT_MAPPED_SURFACE_2
EXT_MAPPED_SURFACE_3
EXT_VRAY_VERTEX_COLORS_INTERFACE
EXT_VRAY_COMMON_HAIR_SHADE_DATA
EXT_LIGHT_LIST
EXT_CHAMFERED_EDGES
EXT_SURFACE_INFO
EXT_VRAY_INSTANCE_DATA

Additional interfaces available from rc.rayresult.si are:
EXT_OBJECT_SHADE_INSTANCE
EXT_DEFAULT_SHADE_INSTANCE
EXT_GEOMETRY_SAMPLER_INTERFACE
EXT_REFERENCED_SURFACE
EXT_REFERENCED_SURFACE2
EXT_GEOM_PARTICLE_DATA
EXT_VRAY_PER_PARTICLE_DATA

Let me know if you have other questions.

Best regards,
Vlado
user_attr_parse.zip (1.01 KB)

I still got stuck with retrieving the user attribute. The snippet of my code is as following:

VR:: DefaultVRayShadeData* def_shade_data = queryInterface<VR:: DefaultVRayShadeData>(rc.rayresult.sd, EXT_DEFAULT_SHADE_DATA);

if(!def_shade_data)
{
    printf(" No DefaultVRayShadeData interface available …\n");
}
else
{
    tchar* result = NULL;
    result = def_shade_data->getUserProperty(“add”);
    printf(“Result = %s\n”, result);
    …
}

I actually get the DefaultVRayShadeData object and objects in the scene also attached with a user attribute (I fill in the “user attributes” field in object’s shape node with add=1.0; ). However the shown messages are all (null) when rendering. How do i fix this problem ?

This is the exact code that we are using:


const tchar* result = NULL;
		VR::VRaySurfaceUserAttributes *surfAttr=queryInterface<VR::VRaySurfaceUserAttributes>(rc.rayresult.sd, EXT_SURFACE_USER_ATTRIBUTES);
		if (!surfAttr) {
			VR::smile:efaultVRayShadeData *sd=queryInterface<VR::smile:efaultVRayShadeData>(rc.rayresult.sd, EXT_DEFAULT_SHADE_DATA);
			if (sd)
				result = sd->getUserProperty(propName);
		}
		else
			result = surfAttr->getUserProperty(rc, propName);

You can also check if VRayUserColor is working as expected.

Thanks ivaylo, it works perfectly now !