Texturing in OpenCASCADE 6.5

Hi, I was hoping to be able to show a simple texture on some faces of my model.

I had some difficulty getting the texture to show - seems the display mode must be higher than other object currently being used in the model for textures to show...  Anyway, I have them showing now, but I expected the texture to be uniform across the face of my planar rectangular surface.  It is, however, stretched across each of the sub triangles on the surface, which are of different sizes, which results in a very ugly look.

Is there anything that can be done so that the scaling is uniform and that the edges of the texture would line up on that sub-triangles?

I'll attach a picture of what I currently am seeing...

Attachments: 
bwilliams_138522's picture

I should add that I'm doing this via AIS_TexturedShape with the following:

Handle(AIS_TexturedShape) aTShape = new AIS_TexturedShape(ShapeCopy);

TCollection_AsciiString aFile("C:\\N\\bmp.bmp");

aTShape->SetTextureFileName(aFile);

aTShape->SetTextureMapOn();

aTShape->SetTextureScale(true, .2, .2);

aTShape->DisableTextureModulate();​

myAISContext->Display(aTShape, AIS_ExactHLR, -1);

Kirill Gavrilov's picture

Can you share also your shape?

bwilliams_138522's picture

Hmm...  How do I do that?  I can share the code that built the shape which is very variable -- are you looking for the exact inputs for the shape in question (I could try to do that...)  One I have my reference to the AIS_TexturedShape, can I do some kind of dump to share?

I'll attach the function that appears to be creating the shape if that is of any use...

Kirill Gavrilov's picture

Can I do some kind of dump to share?

BRepTools::Write() exports TopoDS_Shape into file.

bwilliams_138522's picture

Ok, I'm attaching the output of the shape

Attachments: 
Kirill Gavrilov's picture

You shape consists of 3 Faces (see attached screenshot from CAD Assistant).
Standard presentation builder StdPrs_ShadedShape (used by AIS_TexturedShape) defines texture mapping UV coordinates from Surface parametric space individually for each Face.

To achieve desired result, either you have to create a single Face instead of 3 Faces in this specific place (I don't know if you are going to texture other shapes and in which way),
or compute UV texture coordinates manually using some alternative mapping logic (like projecting triangle nodes onto plane).
In general case (complex shape definition), you might need creating a mesh Unfolding to be able generating a texture coordinates considering seam edges:
https://www.opencascade.com/content/unfolding-library

There are also visualization-only solutions for generating texture UV coordinates on GPU, depending on what you are trying to achieve
(Graphic3d_Texture2Dplane/Graphic3d_TextureEnv, though these are rarely used due to limited use cases where such mapping makes sense).

Attachments: 
bwilliams_138522's picture

Thank you for you help, Krill.  Yes, it was obvious to me up front there were 3 triangles, and each used the same ratio of scaling the image to fit the width/height, but unfortunately the overall widths were different resulting in different overall scalings.

I want it to use the scales so that the overall image stretching is consistent for each triangle.  Also, the origins should all align.  

It occurred to me that re-tessellating rectangles so that they were 2 triangles of equal size would solve this.  I don't know how to achieve that, though...

All I have is source code -- I am unfamiliar with this CAD Assistant if it is something that comes with Open CASCADE, nor do I have much in the way of documentation other than the headers.  Also, I know very little about CG (I suppose this is not the ideal situation :) )  So, I could not find any reference to StdPrs_ShadedShape in any of the code I saw, particularly in the header for AIS_TexturedShape.   I'll mention again I'm using 6.5 -- in this version it seems I need an actual file on disk and cannot pass an in-memory image (annoying...)

It's not clear to me how I do the individual mapping given the AIS_TexturedShape -- is this possible?

Kirill Gavrilov's picture

I am unfamiliar with this CAD Assistant if it is something that comes with Open CASCADE

CAD Assistant is a free tool, useful for opening 3D models and Data Exchange:
https://www.opencascade.com/content/cad-assistant

It's not clear to me how I do the individual mapping given the AIS_TexturedShape -- is this possible?

You cannot ask AIS_TexturedShape to map UV coordinates in your way, but you can define your own AIS presentation for that purpose. For that, you will have to learn how ::Compute() method works.

I could not find any reference to StdPrs_ShadedShape in any of the code I saw

StdPrs_ShadedShape is a tool computing shape presentation for AIS_Shape nowadays. In older OCCT versions there were more tools (more than actually needed) named differently for that purpose.

Yes, it was obvious to me up front there were 3 triangles, and each used the same ratio of scaling the image to fit the width/height, but unfortunately the overall widths were different resulting in different overall scalings.

It looks like a playing with parameters, but considering the origin of UV texture coordinates generated by AIS_TexturedShape (parametric space of underlying surface) - there might be no combination giving desired result despite the fact that these are just planar faces with simple boundaries.

I would suggest using support services in case if you have problems solving your task using OCCT.