@@ -2907,6 +2907,19 @@ static void visitANARIWorld(ASGVisitor self, ASGObject obj, void* userData) {
29072907
29082908 anariRelease (anari->device ,vertexPosition);
29092909
2910+ if (geom->vertexColors ) {
2911+ // TODO: support all color types
2912+ ANARIArray1D vertexColor = anariNewArray1D (anari->device ,
2913+ geom->vertexColors ,
2914+ 0 ,0 ,ANARI_FLOAT32_VEC4 ,
2915+ geom->numVertices );
2916+
2917+ anariSetParameter (anari->device ,geom->anariGeometry ," vertex.color" ,
2918+ ANARI_ARRAY1D ,&vertexColor);
2919+
2920+ anariRelease (anari->device ,vertexColor);
2921+ }
2922+
29102923 if (geom->indices != nullptr && geom->numIndices > 0 ) {
29112924 ANARIArray1D primitiveIndex = anariNewArray1D (anari->device ,
29122925 geom->indices ,
@@ -3049,12 +3062,33 @@ static void visitANARIWorld(ASGVisitor self, ASGObject obj, void* userData) {
30493062 if (mat->anariMaterial == nullptr )
30503063 mat->anariMaterial = anariNewMaterial (anari->device , " matte" );
30513064
3052- float kd[3 ];
3053- asgParamGetValue (kdParam,kd);
3054- // std::cout << kd[0] << ' ' << kd[1] << ' ' << kd[2] << '\n';
3065+ // Check if geometry has vertex colors
3066+ bool hasVertexColors = false ;
3067+ if (surf->geometry ->type == ASG_TYPE_TRIANGLE_GEOMETRY ) {
3068+ TriangleGeom* geom = (TriangleGeom*)surf->geometry ->impl ;
3069+ hasVertexColors = (geom->vertexColors != nullptr );
3070+ } else if (surf->geometry ->type == ASG_TYPE_SPHERE_GEOMETRY ) {
3071+ SphereGeom* geom = (SphereGeom*)surf->geometry ->impl ;
3072+ hasVertexColors = (geom->vertexColors != nullptr );
3073+ } else if (surf->geometry ->type == ASG_TYPE_CYLINDER_GEOMETRY ) {
3074+ CylinderGeom* geom = (CylinderGeom*)surf->geometry ->impl ;
3075+ hasVertexColors = (geom->vertexColors != nullptr );
3076+ }
30553077
3056- anariSetParameter (anari->device ,mat->anariMaterial ," color" ,
3057- ANARI_FLOAT32_VEC3 ,kd);
3078+ if (hasVertexColors) {
3079+ // Use vertex colors from geometry
3080+ const char * colorAttrib = " color" ;
3081+ anariSetParameter (anari->device ,mat->anariMaterial ," color" ,
3082+ ANARI_STRING ,colorAttrib);
3083+ } else {
3084+ // Use constant material color
3085+ float kd[3 ];
3086+ asgParamGetValue (kdParam,kd);
3087+ // std::cout << kd[0] << ' ' << kd[1] << ' ' << kd[2] << '\n';
3088+
3089+ anariSetParameter (anari->device ,mat->anariMaterial ," color" ,
3090+ ANARI_FLOAT32_VEC3 ,kd);
3091+ }
30583092 anariCommitParameters (anari->device ,mat->anariMaterial );
30593093 }
30603094 }
0 commit comments