Get Texture Coordinates (from mesh file)

Caelshadowhunter's picture

Hi, does anybody know of a way to get texture coordinates from a mesh file, so to apply them to a mesh creator?

cybero's picture
Re: Get Texture Coordinates (from mesh file)

Apropos getting a mesh texture co-ordinates, that rather depends upon the type of file, as to what way those values are held and structured.

Regarding .dae files there is a very good tutorial to be found here - http://www.wazim.com/Collada_Tutorial_1.htm - that covers those bases well, in a generic, non QC specific manner.

Otherwise one is going to have to either generate texture co-ordinates at the time that one generates a mesh or have a file, that is a mesh, that contains texture co-ordinates. [UVs].

There's a very good tuorial on creating textured meshes in Maya - outputs .dae.

How you get and exploit the co-ordinates is entirely dependent to some extent upon the type of patch being used to render the mesh.

Structure patches, Index & Key, output and hook up to the required input, away you go.

Caelshadowhunter's picture
Re: Get Texture Coordinates (from mesh file)

sorry, forgot to mention -were using .dae files. Are these going to be the easiest.

I cant believe that there isn't a pre-existing implementation, this seems like a fairly basic bit of functionality :/

cybero's picture
Re: Get Texture Coordinates (from mesh file)

Actually. come think of it, there already has been such an example posted, albeit not with the key factor UV specifically flagged as tags, the code is contained within the two examples posted by gtoledo

var _TextureCoordinates = []
 
function (__structure TextureCoordinates) main (__structure Positions)
{
   var result = new Object()
   var thickness = .1
 
   if (Positions != null) {   
      var v = 0
      var c = 0
      for (var i=0; i < Positions.length; ++i) {
         var pos = i/Positions.length
 
         _TextureCoordinates[v++] = [ Positions[i][0], Positions[i][1]+thickness*(1-pos),];
         _TextureCoordinates[v++] = [ Positions[i][0], Positions[i][1]-thickness*(1-pos),];
 
      }
   }
 
   result.TextureCoordinates = _TextureCoordinates
   return result
}

You just need to feed this a queue of positions.

You can find the implementation of this at http://kineme.net/composition/gtoledo3/MouseRibbonTexturegt.

Instead of feeding the script a 2D Queue , as per the example posted, you'd instead need to be extracting the positional data , the vertices, from the mesh file, Get Mesh Component.

Just given this a try out and found that a .dae baked with texture that renders as a textured .dae in Preview does not result in a properly rendered .dae mesh in QC, using the method described above, which method does work for dynamically generated meshes, as per the example file that code is to be found within.

Basically, if you bake a .dae Mesh and then use Mesh Loader, the mesh should texture up, so long as the image resource is found at the location named in the .dae file, like

<library_images>
        <image id="ID10">
            <init_from>gridtx/texture0.jpg</init_from>
        </image>
    </library_images>

BTW, not entirely sure if the problem case shown in the file attached is a result of the oft quoted 'broken' / proprietary or partial support for Collada .dae in OS X, or simply some temporary ineptness on my part :-). The attached file also shows how one can take a 'baked' textured mesh and render in QC.

Please note, that if the mesh you seek to texture has already been baked, using the Set Mesh Component / Texture patch won't work, in fact it will be entirely unnecessary.

PreviewAttachmentSize
TexturedMesh.zip34.35 KB

gtoledo3's picture
Re: Get Texture Coordinates (from mesh file)

No, Apple forgot that apparently.

dust's picture
Re: Get Texture Coordinates (from mesh file)

here is an example of how to import mesh texture coords.

http://kineme.net/composition/dust/ColladaImporter#comment-21508

you can import mesh textures or what ever else you want with the XML import patch. this gives you access to more asset components like animations, bones, skins, lights etc.....

if your importing just a basic mesh with apples mesh creator the indices are text coord indices and will not work with the mesh creator. so use the indices generator patch instead.