mesh draw with textures

alvarotrevinho's picture

im trying to create a patch for drawing a mesh with the mouse clicking in the screen to map an planar object, the problem i that i cannot keep the vertices i draw when close the patch and i open again. the other problem is that i dont know how to calculate the texture coordinates, anyone can help? i have the brain heat this days beacuse i dont find a way to do it correctly, any suggestion? thanks

PreviewAttachmentSize
Mesh draw.qtz83.41 KB

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

usefuldesign.au's picture
Re: mesh draw with textures

Kineme File tools will save and import structures.

http://kineme.net/release/FileTools/20100409

alvarotrevinho's picture
Re: mesh draw with textures

very nice, now i only need how to assign the correct texture coordinates , anyone can help me with this issue'?

dust's picture
Re: mesh draw with textures

for uv you do an expression like this if your model was sphere.

_v = vert

u=_v.x/sqrt(_v.x*_v.x+_v.y*_v.y+_v.z*_v.z) v=_v.y/sqrt(_v.x*_v.x+_v.y*_v.y+_v.z*_v.z)

alvarotrevinho's picture
Re: mesh draw with textures

i know this expression from wikipedia, but in this case its not an sphere, i know the uv of the corners from the mesh but how to calculate the middle points in different places, bufff, i cant get it, thanks dust anyway

dust's picture
Re: mesh draw with textures

i memorized that equation from wiki as well. my bad didn't know you where doing a flat grid. here is a uv., normal grid macro that will do what your wanting. its easier to just put the macro into your patch than explain but here is the kernel incase you where wondering. hope this helps. i suggest saving you structures down to a file to save your maps. a different approach would be to use the color info of the texture as well. hope this helps. once you got this working the way you want it post it back up. these mesh mapping patches are cool.

__kernel void grid(__global float4 *Normals, __global float2 *UVs, float Width, float Height)
{
   int   tid_x   = get_global_id(0),
      tid_y   = get_global_id(1),
      sz_x      = get_global_size(0),
      sz_y      = get_global_size(1);
   int index      = mad24(tid_y, sz_x, tid_x);
 
   float u = tid_x/(float)(sz_x-1);
   float v = tid_y/(float)(sz_y-1);
 
    vstore4(make_float4(0., 0., 1., 1.), (size_t)index, (__global float*)Normals);
    vstore2(make_float2(u, 1.-v), (size_t)index, (__global float*)UVs);
}
PreviewAttachmentSize
MeshDrawUV_dust.qtz93.13 KB

alvarotrevinho's picture
Re: mesh draw with textures

mmm, it seems to crash when i reset the vertex queue, i think its beacuse of the indices , well, its something strange, i dont know really whats the cause.... im not so good in code, perhaps i will try if there is any solution,thanks dust,

dust's picture
Re: mesh draw with textures

actually think I remember someone saying that the indices generator patch was not working right although I haven't really ever noticed that. there are some things you don't want to do like change the grid size while in execution of the uv kernel. the kernel is sort of independent of your vertex count so resetting your queue shouldn't effect the kernel but possibly having texture coords with no vertex points might cause the problem. does this happen when your not using the texture or only when you use he texture ? does your machine go down or just crash qc ?

alvarotrevinho's picture
Re: mesh draw with textures

ok, i fixed the crash, anyway it doesnt work as i expected, somthing goes wrong with the uv´s thanks very much with your help dust, i will work these days on it

gtoledo3's picture
Re: mesh draw with textures

BTW, it was hard for me to sort through the posted composition (I wasn't sure what the pulse/counter stuff was supposed to do), but I posted an example that textures a drawn mesh in the Composition Repository yesterday with you in mind.

There are different ways one could choose to texture a line though, so I'm not sure if it is what you're going for or not.

bernardo's picture
Re: mesh draw with textures

hi there is this snow leopard only? sorry for the dumb question

alvarotrevinho's picture
Re: mesh draw with textures

thanks george, but i saw your patch and the problem its that i would like to warp the texture to the mesh, in your case i can see that the texture is fixed to the screen i think. at last im trying to do it by write the coordinates by myself, but its very tricky if you have lot of vertices, hope to find the answer... thanks again for the nice example

alvarotrevinho's picture
Re: mesh draw with textures

oops the pulse / counter / conditional was to close the queue when the size predefined was reached.. its a dirty way, but t workss.

gtoledo3's picture
Re: mesh draw with textures

It's actually not too hard to approach what you want, I just wasn't sure what that was.

I'm gathering you want one image for every two triangles, from the sounds of it?

In what schema are you trying to texture? What is supposed to happen if you make a shape like a sideways u? What are the bottom/side/top rows supposed to look like? This can be important, depending on what you're going for.

gtoledo3's picture
Re: mesh draw with textures

What I posted was SL only, but if you looked in there for the javscript, it might be possible to convert the code to work with the kinemeGL quad. The only difference is that the Quad would expect keyed members.

alvarotrevinho's picture
Re: mesh draw with textures

okk. Imagine a 3d stairs ok? i would like to create the mesh to map the stairs , and for example the texture is a video that goes from the top to the bottom of the imgage, so goes following the stairs shape. ... i want the patch to create geometric shappes with the texture conformed to the shape. its difficult to explain, anyway thanks for the answer.

bernardo's picture
Re: mesh draw with textures

ahhhhhh! the index evil goddam me!!! i'll give a go them....