Because the texture is sent on the renderer, you need a chance to
change the texture as pre3d is drawing. This is what the
quad_callback allows you to do. It's a little bit clumsy, but it
gives your application a bit more power.
Basically the callback is called before a quad is rendered, and you
have a chance to modify any render state, like the texture. This is
just done by setting renderer.texture, which is a TexureInfo class.
This class specifies the classic u/v texture coordinates that map to
the vertices of that quad. So u0/v0 is maps to the first vertex of
the QuadFace. The u/v coordinates are pixel coordinates into the
texture.
The tricky bit when using something like a sphere tessellation code,
is now you need to somehow make between the quad face and how it
should be textured. You could try doing something like a cube map,
and/or just looking at the centroid/normal of the quad face to select
which part of the image to texture from.
Here are some nice textures that will work well for a sphere:
http://www.humus.name/index.php?page=Textures
It shouldn't be so bad to map these uv's in the quad callback.
Let me know if that didn't help.
-- dean
> --
> You received this message because you are subscribed to the Google Groups "pre3d" group.
> To post to this group, send email to pr...@googlegroups.com.
> To unsubscribe from this group, send email to pre3d+un...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/pre3d?hl=en.
>
>
Thanks,
-- dean
Sorry for the slow response. I sat down and tried this today, and
realized something I should have realized a lot earlier. Hopefully
the attached picture clearly illustrates the problem.
This is one of many problems when you're working in higher level
primitives (in this case triangles and quads on a <canvas>) instead of
working per-pixel. In general cube mapping is a per-pixel concept.
If you try to just map them to triangles, you end up with holes along
the edges of the cubes (illustrated in the attached picture as the
large triangles spanning over the black regions). You must also
support triangles that wrap around the edges of the image, etc. So
unless I'm missing something clever, I don't see an obvious way of
directly mapping a cube-map image to vertex triangles.
I could think of a few ways of still making this work. One would be
to tesselate based on the cubemap image, so triangles never span
different faces of the cubemap. Another would be to walk the quads
manually, and do a scanline per-pixel texture fetch, creating a new
<canvas> with the faces drawn there. This would be a less compact
image, since the texture will likely not be packed very well.
Additionally as an optimization you could do a hybrid, only do this
for triangles that span more than one face. I think this could
definitely be doable. You could also pre-compute this if your
geometry is static.
Things are never as easy as they seem. Thanks,
-- dean
http://www.zynaps.com/jslab.xml?id=envmap
I've been tempted to make pre3d do things like the above, but in the
bigger picture WebGL is coming, and pre3d is not meant to be a
replacement. I'm trying to concentrate on doing things in pre3d that
are unique (like vector graphics), and it doesn't really make sense to
keep pushing the classic 3d concepts. I think there is still an
interesting future for applications like this:
Thanks,
-- dean