mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-03 10:22:45 -04:00
3-d texture coordinates, deal with animation properly
This commit is contained in:
parent
62e0ca3d4f
commit
f46eaaa3a8
@ -505,20 +505,22 @@ recompute_geom_node(const WorkingNodePath &np, LMatrix4f &rel_mat,
|
|||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
void ProjectionScreen::
|
void ProjectionScreen::
|
||||||
recompute_geom(Geom *geom, const LMatrix4f &rel_mat) {
|
recompute_geom(Geom *geom, const LMatrix4f &rel_mat) {
|
||||||
static const LMatrix3f lens_to_uv
|
static const LMatrix4f lens_to_uv
|
||||||
(0.5f, 0.0f, 0.0f,
|
(0.5f, 0.0f, 0.0f, 0.0f,
|
||||||
0.0f, 0.5f, 0.0f,
|
0.0f, 0.5f, 0.0f, 0.0f,
|
||||||
0.5f, 0.5f, 1.0f);
|
0.0f, 0.0f, 0.5f, 0.0f,
|
||||||
|
0.5f, 0.5f, 0.5f, 1.0f);
|
||||||
|
|
||||||
static const LMatrix3f lens_to_uv_inverted
|
static const LMatrix4f lens_to_uv_inverted
|
||||||
(0.5f, 0.0f, 0.0f,
|
(0.5f, 0.0f, 0.0f, 0.0f,
|
||||||
0.0f,-0.5f, 0.0f,
|
0.0f,-0.5f, 0.0f, 0.0f,
|
||||||
0.5f, 0.5f, 1.0f);
|
0.0f, 0.0f, 0.5f, 0.0f,
|
||||||
|
0.5f, 0.5f, 0.5f, 1.0f);
|
||||||
|
|
||||||
Lens *lens = _projector_node->get_lens();
|
Lens *lens = _projector_node->get_lens();
|
||||||
nassertv(lens != (Lens *)NULL);
|
nassertv(lens != (Lens *)NULL);
|
||||||
|
|
||||||
const LMatrix3f &to_uv = _invert_uvs ? lens_to_uv_inverted : lens_to_uv;
|
const LMatrix4f &to_uv = _invert_uvs ? lens_to_uv_inverted : lens_to_uv;
|
||||||
|
|
||||||
// Iterate through all the vertices in the Geom.
|
// Iterate through all the vertices in the Geom.
|
||||||
|
|
||||||
@ -526,7 +528,7 @@ recompute_geom(Geom *geom, const LMatrix4f &rel_mat) {
|
|||||||
if (!vdata->has_column(_texcoord_name)) {
|
if (!vdata->has_column(_texcoord_name)) {
|
||||||
// We need to add a new column for the new texcoords.
|
// We need to add a new column for the new texcoords.
|
||||||
vdata = vdata->replace_column
|
vdata = vdata->replace_column
|
||||||
(_texcoord_name, 2, Geom::NT_float32, Geom::C_texcoord);
|
(_texcoord_name, 3, Geom::NT_float32, Geom::C_texcoord);
|
||||||
geom->set_vertex_data(vdata);
|
geom->set_vertex_data(vdata);
|
||||||
}
|
}
|
||||||
if (_vignette_on && !vdata->has_column(InternalName::get_color())) {
|
if (_vignette_on && !vdata->has_column(InternalName::get_color())) {
|
||||||
@ -536,9 +538,17 @@ recompute_geom(Geom *geom, const LMatrix4f &rel_mat) {
|
|||||||
geom->set_vertex_data(vdata);
|
geom->set_vertex_data(vdata);
|
||||||
}
|
}
|
||||||
|
|
||||||
GeomVertexWriter texcoord(geom->modify_vertex_data(), _texcoord_name);
|
// Clear the vdata pointer so we don't force a copy in the below.
|
||||||
GeomVertexWriter color(geom->modify_vertex_data());
|
vdata.clear();
|
||||||
GeomVertexReader vertex(geom->get_vertex_data(), InternalName::get_vertex());
|
|
||||||
|
PT(GeomVertexData) modify_vdata = geom->modify_vertex_data();
|
||||||
|
|
||||||
|
// Maybe the vdata has animation that we should consider.
|
||||||
|
CPT(GeomVertexData) animated_vdata = geom->get_vertex_data()->animate_vertices();
|
||||||
|
|
||||||
|
GeomVertexWriter texcoord(modify_vdata, _texcoord_name);
|
||||||
|
GeomVertexWriter color(modify_vdata);
|
||||||
|
GeomVertexReader vertex(animated_vdata, InternalName::get_vertex());
|
||||||
|
|
||||||
if (_vignette_on) {
|
if (_vignette_on) {
|
||||||
color.set_column(InternalName::get_color());
|
color.set_column(InternalName::get_color());
|
||||||
@ -548,12 +558,12 @@ recompute_geom(Geom *geom, const LMatrix4f &rel_mat) {
|
|||||||
Vertexf vert = vertex.get_data3f();
|
Vertexf vert = vertex.get_data3f();
|
||||||
|
|
||||||
// For each vertex, project to the film plane.
|
// For each vertex, project to the film plane.
|
||||||
LPoint2f film(0.0, 0.0);
|
LPoint3f film(0.0f, 0.0f, 0.0f);
|
||||||
bool good = lens->project(vert * rel_mat, film);
|
bool good = lens->project(vert * rel_mat, film);
|
||||||
|
|
||||||
// Now the lens gives us coordinates in the range [-1, 1].
|
// Now the lens gives us coordinates in the range [-1, 1].
|
||||||
// Rescale these to [0, 1].
|
// Rescale these to [0, 1].
|
||||||
texcoord.set_data2f(film * to_uv);
|
texcoord.set_data3f(film * to_uv);
|
||||||
|
|
||||||
// If we have vignette color in effect, color the vertex according
|
// If we have vignette color in effect, color the vertex according
|
||||||
// to whether it fell in front of the lens or not.
|
// to whether it fell in front of the lens or not.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user