Revit API Forum
Welcome to Autodesk’s Revit API Forums. Share your knowledge, ask questions, and explore popular Revit API topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Obtaining texture UV coordinates

15 REPLIES 15
Reply
Message 1 of 16
pfk
Enthusiast
6916 Views, 15 Replies

Obtaining texture UV coordinates

Hi

 

I have an issue where I have coded a Revit plugin which renders a scene - and calculates the UV coordinates for each vertex.  Unfortunately there are a number of situations where UV mapping is wrong - even with planar mapping.

 

For example, the attached image images shows the results from UV mapping (on the right), verses the "Realistic" viewport setting.

 

As you can see, the horizontal surface is uncorrectly mapped.  MR does not have this issue.

 

The code to calculate the UV is:

 

foreach (Face face in solid.Faces)
{
    PlanarFace planarFace = face as PlanarFace;
    CylindricalFace cylindricalFace = face as CylindricalFace;
    ConicalFace conicalFace = face as ConicalFace;
    RevolvedFace revolvedFace = face as RevolvedFace;
    HermiteFace hermiteFace = face as HermiteFace;
    RuledFace ruledFace = face as RuledFace;

    for (int v = 0; v < 3; ++v)
    {
        XYZ pointXYZ = triangle.get_Vertex(v); 

        IntersectionResult ir = face.Project(pointXYZ);

        // Calculate the UV's if the face is planar
        if (planarFace != null)
        {
            if (ir != null)
            {
                m_Uvws[uvIndex].U = ir.UVPoint.U;
                m_Uvws[uvIndex].V = ir.UVPoint.V;
            }
        }
        else if (cylindricalFace != null)
        {
            if (ir != null)
            {
                ....

 

So my question is, how can I get correct UV's?

 

(EDIT: I have invested a significant amount of time trying to implement the approach outlined in http://thebuildingcoder.typepad.com/blog/2010/02/texture-data-uv-coordinates-and-fbx.html and it is simply not viable.  It is not possible to match the UV's indexs from the FBX with the vertex indexs obtained via the Revit API.  Also, FBX assigns each polygon to a RenderAppearance, rather than a Revit Material - so it is not possible to determine what the material is for a given polygon in the FBX.]

 

Thanks in advance.

15 REPLIES 15
Message 2 of 16
jeremytammik
in reply to: pfk

Dear Pfk,

 

Very sorry, the answer is no.

 

Best regards,

 

Jeremy



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

Message 3 of 16
jeremytammik
in reply to: jeremytammik

Dear Pfk,

 

You will be happy to har that I have an update to my previous answer, and the new reply is yes.

 

One cannot get accurate UV texture mapping via the regular Revit geometry API.

 

However, correct UVs can be got from the CustomExporter via an ExportContext in Revit 2014 (a.k.a. Visualization API). The OnPolymesh callback of the context receives PolymeshTopology objects that have UVs for each mesh.
 
The CustomExporter should be used for most (if not all) export and render external applications.
 

I hope this helps.

 

Please let me know how you end up making use of this! Thank you!

 

Best regards

 

Jeremy



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

Message 4 of 16
pfk
Enthusiast
in reply to: jeremytammik

Thanks Jeremy

I'm not quite sure how I missed this when going through the Revit 2014
API. Thank you for pointing it out. I will post back here with the
results.

Paul
Message 5 of 16
jeremytammik
in reply to: pfk

Dear Paul,

 

I wish you the best of luck with that and look forward to hearing how it goes for you.

 

I hear that the UVs are obtained for polymeshes in the exporter context.

 

Best regards,

 

Jeremy



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

Message 6 of 16
pfk
Enthusiast
in reply to: pfk

I have now implemented the solution proposed in the blog entry and can confirm that it works extremely well.  Thank you!  My only criticism is that it still doesn't allow obtaining texturemap named assigned to materials in the OnMaterial method.  I also noticed that the ArchVision RPC (cutout geometry) props do not get sent to ExportContext.  But still a huge step forward.

 

Thanks again.

 

Paul

Message 7 of 16
arnostlobel
in reply to: pfk

Hello Paul,

 

Thank you for making progress and reporting on it. 🙂 It seems the Custom Exporter is the right tool for you to utilize. I am sorry about the textures and RPCs. However we are under rather strict copyright obligations and we are not allowed to export data for RPCs in any of our export formats, including custom exports. As for the textures, although there are no such strict restrictions, the entire material component is – technically – not part of Revit code and its internal API does not allow us to acquire texture paths, at least not easily (as far as I know). Hopefully, the material component keeps on improving going forward allowing us expanding the functionality of custom exporters in future releases of the Revit API.

 

Thank you

 

Arnošt Löbel

Autodesk Revit R&D

Arnošt Löbel
Message 8 of 16
jeremytammik
in reply to: arnostlobel

Here is a summary of these results:

 

http://thebuildingcoder.typepad.com/blog/2013/07/texture-bitmap-and-uv-coordinates.html

 

Cheers, Jeremy.



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

Message 9 of 16
Anonymous
in reply to: arnostlobel

I never knew that exporting RPC may violate copyrights.

 

Yes, using custom export mechanism, there is not way of exporting RPC items like trees.

 

But some one told me to support RPC and I implemented by own mechanism to export RPC items and they showed up correctly in the final display on the web.

 

Does it violate any kind of copyright ?

 

Subir Kumar Dutta

Message 10 of 16
kubity
in reply to: Anonymous

Hi everyone,

Any tips to have the simple RPC geometry (like the placeholder)?

Thanks

Nick

Message 11 of 16
Anonymous
in reply to: pfk

hello Paul,

The texture UV coordinates which I obtained from the CustomExporter(IExportContext::OnPolymesh) directly is larger than UV's in Revit software. Did you know why and How can I obtain the correct UV's?

Thanks.

African


@pfkwrote:

I have now implemented the solution proposed in the blog entry and can confirm that it works extremely well.  Thank you!  My only criticism is that it still doesn't allow obtaining texturemap named assigned to materials in the OnMaterial method.  I also noticed that the ArchVision RPC (cutout geometry) props do not get sent to ExportContext.  But still a huge step forward.

 

Thanks again.

 

Paul



@pfkwrote:

I have now implemented the solution proposed in the blog entry and can confirm that it works extremely well.  Thank you!  My only criticism is that it still doesn't allow obtaining texturemap named assigned to materials in the OnMaterial method.  I also noticed that the ArchVision RPC (cutout geometry) props do not get sent to ExportContext.  But still a huge step forward.

 

Thanks again.

 

Paul



333.png

 

Message 12 of 16
Revitalizer
in reply to: Anonymous

Hi,

 

just my 50 cent...

It seems that the factor is about three point something.

May it be that there is a unit conversion problem, meters versus feet?

 

Revitalizer




Rudolf Honke
Software Developer
Mensch und Maschine





Message 13 of 16
pfk
Enthusiast
in reply to: Revitalizer

Yes, maybe you are setting vertices in feet, but the UV's are in meters.
Message 14 of 16
Anonymous
in reply to: Revitalizer

Hello Revitalizer,

Thank you for your reply. I have tried to unify the vertices and UV's in feet, but it still does not correct. is there something like transformation for UV's? 

Thanks.

aaaaaaa.png

 

Message 15 of 16
Anonymous
in reply to: Anonymous

Hello we are stuck on the visualization of rpc. Which mechanism did you implement to get mesh data for RPC trees and other elements.

Message 16 of 16
kubity
in reply to: Anonymous

Hi there, 

RPC are not supported now, just the geometry, not the textures. As developers, we cannot add this functionality for the moment as it's limited by Autodesk restrictions. 

Hope I was able to answer your question. 

Cheers, 
Nathan

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report