Texturize pyggel.mesh.OBJ

48 views
Skip to first unread message

Gemayel Lira

unread,
Sep 24, 2011, 10:18:35 PM9/24/11
to PYGGEL-dev
I have wavefront objects, and wanted to know the possibility of
changing the texture during the execution of the program.
the creation of objects pyggel.geometry.Cube or
pyggel.geometry.Plane, have the option of setting pyggel.data.Texture
but I can not implement this in pyggel.mesh.OBJ objects.
any help or advice is welcome

RB[0]

unread,
Sep 24, 2011, 11:20:10 PM9/24/11
to pygge...@googlegroups.com
Hmm it should be possible to do, I recall setting that up, but I dunno if that is in teh current version or if it has something to do with hacking materials funky...
I'll look into it :)


--
You received this message because you are subscribed to the Google Groups "PYGGEL-dev" group.
To post to this group, send email to pygge...@googlegroups.com.
To unsubscribe from this group, send email to pyggel-dev+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/pyggel-dev?hl=en.


RB[0]

unread,
Sep 24, 2011, 11:26:23 PM9/24/11
to pygge...@googlegroups.com
Alright, using the SVN version (should be latest release as well) - each part of a mesh has a material - ie, if you have a body, the head, body, legs, arms, etc. all have different materials.
These can be a single mesh (subdivided to fit, recommended) or different ones.
You can do this:
for obj in myObj:
   obj.material = data.Material('a name')
   obj.material.color = (1,1,1,1)
   obj.material.texture = newTexture


Now, I believe the texture coords are locked in for the mesh, so basically, any texture that is the same structure as the one you originally used on the mesh, should work... :)

Gemayel Lira

unread,
Sep 25, 2011, 9:54:56 AM9/25/11
to PYGGEL-dev
I am using the version 0.08-alpha4c as an example I will use the
example file test_texture_swap.py then I can not set
obj=(pyggel.mesh.OBJ("data/bird_plane.obj") the data.Texture the
texture("data/stickdude.png") for example would tell me how this
implementation?
example follows an attempt to line 124 http://bpaste.net/show/18924/
here, I'm trying to set a new texture on the bird.
Thanks for listening

On Sep 25, 12:26 am, "RB[0]" <roeb...@gmail.com> wrote:
> Alright, using the SVN version (should be latest release as well) - each
> part of a mesh has a material - ie, if you have a body, the head, body,
> legs, arms, etc. all have different materials.
> These can be a single mesh (subdivided to fit, recommended) or different
> ones.
> You can do this:
> for obj in myObj:
>    obj.material = data.Material('a name')
>    obj.material.color = (1,1,1,1)
>    obj.material.texture = newTexture
>
> Now, I believe the texture coords are locked in for the mesh, so basically,
> any texture that is the same structure as the one you originally used on the
> mesh, should work... :)
>
>
>
>
>
>
>
> On Sat, Sep 24, 2011 at 10:20 PM, RB[0] <roeb...@gmail.com> wrote:
> > Hmm it should be possible to do, I recall setting that up, but I dunno if
> > that is in teh current version or if it has something to do with hacking
> > materials funky...
> > I'll look into it :)
>

RB[0]

unread,
Sep 25, 2011, 11:29:53 AM9/25/11
to pygge...@googlegroups.com
If you will note:
Lines 84-99 are changing the texture on any object in the "to_swap" list.
In the loop, it specifically checks if it is a mesh (if isinstance(i, pyggel.mesh.BasicMesh)) and then updating the material that way.
What you need to do, is exactly what that is doing - create a new Material - but assign it a texture, so:
swap_material.texture = some_texture
then follow the steps in line 90-95 and it *should* work - been a long time since I did this.
But basically, what it is doing is setting up a list of swap_materials, and in the loop every few seconds it is swapping between the original texture and the swap texture.

You could also do like what is happening on lines 124-130 - which is actually a better idea, but hey, didn't see that til now... LOL
Basically, it is looping through the objs in the mesh, and assigning them a new texture when you press the spacebar...

Hope that helps! :)

Gemayel Lira

unread,
Sep 26, 2011, 11:00:45 AM9/26/11
to PYGGEL-dev
Forgive my insistence
still can not understand why this does not work here. http://bpaste.net/show/18950/
line 124-132
it seems that it captures only one point changes the texture and
color, but not all enter the picture.
please tell me what should I do to get all the image texture.

On Sep 25, 12:29 pm, "RB[0]" <roeb...@gmail.com> wrote:
> If you will note:
> Lines 84-99 are changing the texture on any object in the "to_swap" list.
> In the loop, it specifically checks if it is a mesh (if isinstance(i,
> pyggel.mesh.BasicMesh)) and then updating the material that way.
> What you need to do, is exactly what that is doing - create a new Material -
> but assign it a texture, so:
> swap_material.texture = some_texture
> then follow the steps in line 90-95 and it *should* work - been a long time
> since I did this.
> But basically, what it is doing is setting up a list of swap_materials, and
> in the loop every few seconds it is swapping between the original texture
> and the swap texture.
>
> You could also do like what is happening on lines 124-130 - which is
> actually a better idea, but hey, didn't see that til now... LOL
> Basically, it is looping through the objs in the mesh, and assigning them a
> new texture when you press the spacebar...
>
> Hope that helps! :)
>
>
>
>
>
>
>
> On Sun, Sep 25, 2011 at 8:54 AM, Gemayel Lira <gemayell...@gmail.com> wrote:
> > I am using the version 0.08-alpha4c as an example I will use the
> > example file test_texture_swap.py then I  can not set
> > obj=(pyggel.mesh.OBJ("data/bird_plane.obj") the data.Texture the
> > texture("data/stickdude.png") for example would tell me how this
> > implementation?
> > example follows an attempt to line 124http://bpaste.net/show/18924/

RB[0]

unread,
Sep 26, 2011, 4:00:35 PM9/26/11
to pygge...@googlegroups.com
It is working - it is just that the object you are trying to apply the texture onto does not support textures.
You need to create a model that has texture coords in it's definition for it to work correctly - as it is, it is just applying the bottomleft corner of the texture as the whole thing - so a solid color.
If you take out the texture_swap parts it is easier to see what is going on, because there is less happening... :)

RB[0]

unread,
Sep 26, 2011, 7:31:29 PM9/26/11
to pygge...@googlegroups.com
I use a program called Wings3D to make my models - a popular free one (though more difficult to learn) is Blender.
Both programs should have tutorials for makings meshes and then "unwrapping" them to get texture coords... :)

On Mon, Sep 26, 2011 at 6:13 PM, Gemayel Lira <gemay...@gmail.com> wrote:
ok I think I understand I need to know how to set these coordinates,
I'm looking


On Sep 26, 5:00 pm, "RB[0]" <roeb...@gmail.com> wrote:
> It is working - it is just that the object you are trying to apply the
> texture onto does not support textures.
> You need to create a model that has texture coords in it's definition for it
> to work correctly - as it is, it is just applying the bottomleft corner of
> the texture as the whole thing - so a solid color.
> If you take out the texture_swap parts it is easier to see what is going on,
> because there is less happening... :)
>

Gemayel Lira

unread,
Sep 26, 2011, 7:13:38 PM9/26/11
to PYGGEL-dev
ok I think I understand I need to know how to set these coordinates,
I'm looking

On Sep 26, 5:00 pm, "RB[0]" <roeb...@gmail.com> wrote:
> It is working - it is just that the object you are trying to apply the
> texture onto does not support textures.
> You need to create a model that has texture coords in it's definition for it
> to work correctly - as it is, it is just applying the bottomleft corner of
> the texture as the whole thing - so a solid color.
> If you take out the texture_swap parts it is easier to see what is going on,
> because there is less happening... :)
>

Gemayel Lira

unread,
Sep 27, 2011, 9:05:08 AM9/27/11
to PYGGEL-dev
following my learning, unfortunately still not got what I wanted, now
I'm constantly getting this error:

IndexError: list index out of range
File "/home/adorador/python/3d/misc/Exemplos_antigos/PYGGEL-V0.08-
alpha4c/test_texture_swap.py", line 194, in <module>
main()
File "/home/adorador/python/3d/misc/Exemplos_antigos/PYGGEL-V0.08-
alpha4c/test_texture_swap.py", line 47, in main
obj = pyggel.mesh.OBJ("/tmp/new.obg.obj")
File "/home/adorador/python/3d/misc/Exemplos_antigos/PYGGEL-V0.08-
alpha4c/pyggel/mesh.py", line 78, in OBJ
fin.append(i.compile(vertices, normals, texcoords))
File "/home/adorador/python/3d/misc/Exemplos_antigos/PYGGEL-V0.08-
alpha4c/pyggel/mesh.py", line 108, in compile
ut.append(texcoords[t[i]-1])

I'm trying to learn to work with wings 3d, and here is the simple cube
with a texture that I created, please let me know that I'm wrong.
http://dl.dropbox.com/u/41834317/new.wings

RB[0]

unread,
Sep 27, 2011, 12:42:39 PM9/27/11
to pygge...@googlegroups.com
The texture must be exported as a .OBJ file, PYGGEL cannot load .WINGS files - other than that it *should* work, there are some issues with rare OBJs that use a different indexing system, but I haven't run into one of them in a while now...

Gemayel Lira

unread,
Sep 27, 2011, 12:57:28 PM9/27/11
to PYGGEL-dev
ok, I do not think I explained right, if you look at the error log,
the file will see that I try to import into pyggel is /tmp/new.obg.obj
the new.obg.obj is exported created with wings 3d.
http://dl.dropbox.com/u/41834317/new.obg.mtl
http://dl.dropbox.com/u/41834317/new.obg.obj
and the error persists.

RB[0]

unread,
Sep 27, 2011, 1:08:53 PM9/27/11
to pygge...@googlegroups.com
Grr - I'll have to look into it later for you, unless someone else cares to analyze it - it should be working :(

Gemayel Lira

unread,
Sep 27, 2011, 1:11:19 PM9/27/11
to PYGGEL-dev
no problem, I appreciate any help and I can wait, I'm already four
days with this problem.
Thank you for your attention

On 27 set, 14:08, "RB[0]" <roeb...@gmail.com> wrote:
> Grr - I'll have to look into it later for you, unless someone else cares to
> analyze it - it should be working :(
>
> ...
>
> mais »

Gemayel Lira

unread,
Sep 27, 2011, 3:36:22 PM9/27/11
to PYGGEL-dev
in analyzing the objects in the game Robocalypto demonstration, I
Noticed That Were objects created using "Art of Illusion." (I try
install)
a difference in the object that I created for the objects is analyzed
is 'f' coordinates example:
working: manually modified
f 1//1 4//4 3//3 2//2
f 1//1 5//5 8//8 4//4
f 2//2 6//6 5//5 1//1
f 3//3 7//7 6//6 2//2
f 4//4 8//8 7//7 3//3
f 6//6 7//7 8//8 5//5
not working: created with wing3d
f 1/5/1 4/12/4 3/15/3 2/7/2
f 1/2/1 5/1/5 8/6/8 4/8/4
f 2/21/2 6/17/6 5/16/5 1/20/1
f 3/18/3 7/19/7 6/14/6 2/13/2
f 4/8/4 8/16/8 7/17/7 3/10/3
f 6/3/6 7/9/7 8/11/8 5/4/5
maybe this will help to explain something
> ...
>
> mais »

RB[0]

unread,
Sep 27, 2011, 3:43:18 PM9/27/11
to pygge...@googlegroups.com
Interesting, so the inner values are causing errors hmm... :S

Gemayel Lira

unread,
Sep 28, 2011, 2:30:38 PM9/28/11
to PYGGEL-dev
Solved!
got what I wanted, the solution is below.
pyggel version 0.075-alpha3b
obj = pyggel.mesh.OBJ("/tmp/box.obj")
new=[]
for x in obj.gl_lists:
gl_list, material = x
material=data.Texture("/tmp/floor.png")
new.append([gl_list,material])
obj.gl_lists=new
> ...
>
> mais »

RB[0]

unread,
Sep 28, 2011, 2:43:05 PM9/28/11
to pygge...@googlegroups.com
Congrats! :)

> ...
>
> mais »

Reply all
Reply to author
Forward
0 new messages