Component based object UV coordinates

I am facing a problem for two days and can’t figure how to sort it :

I’m using C++ SDK skp2xml sample as a basis of an skp Importer for our software.
Everything works fine except one case, when texture is handled by component and not by geometry itself

My SU model is :

  • A single square face converted as a component
  • The face has no material
  • The component has one texture (see incorpored image)

Because Face has default material like explained by @tt_su here, UV coords are default one and are useless when using SUUVHelperGetFrontUVQ/SUUVHelperGetBackUVQ.

I have also tried to use these calls with no success :

SUTextureWriterLoadFace
SUTextureWriterLoadEntity
SUFaceGetUVHelperWithTextureHandle

From SDK sample, the order of skp2xml algorithm is

WriteComponentDefinitions();
which then calls
WriteEntities()

But material is available in “component instance” not in “component definition” when I need material
So I am a little bit lost, I do not know where and when I get the right info and where I can set it.

void CXmlExporter::WriteEntities(SUEntitiesRef entities, XmlEntitiesInfo &entities_info) 
{
	WriteComponentInstances(entities, entities_info);
	WriteGroups(entities, entities_info);
	WriteGeometries(entities, entities_info);
}

This problem has been talked in previous post, but I am unsure what user did is correct by using SUFaceSetFrontMaterial with material from component on each individual face.

Am I correct that your goal is to know how textures are placed when the material is applied to the wrapping container?

When no UV coordinates (or Texture Positioning as the UI calls it) is defined for a face SketchUp falls back to use the local coordinate system. I don’t know the exact rules for how this is done but you can try applying a textured material to some geometry and see how SketchUp positions it.

Some quick tests indicates the UV origin is simply the XYZ origin projected to the face. The horisontal texture axis (can’t remember if it is U or V) seems to be normal * Z axis * normal. The horizontal texture axis seems to be the vertical one cross multiplied with the normal.

I haven’t checked on back faces though, but perhaps this helps you getting in the right direction.

1 Like

Thans for your answer.
To answer your question : yes you are right, basically I’m trying to find how works the texture mapping on a geometry with no texture when the texture comes from a parent object like a component which contains the textured material.

You have to use: SUTextureGetDimensions, the s_scale / t_scale factors will do the job for your case.

http://extensions.sketchup.com/developer_center/sketchup_c_api/sketchup/texture_8h.html#a5fa82e4c5ed4718852493877d127862b

2 Likes

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.