15 #include "cLwoPolygons.h"
16 #include "lwoToEggConverter.h"
17 #include "cLwoPoints.h"
18 #include "cLwoLayer.h"
19 #include "cLwoSurface.h"
21 #include "lwoPolygonTags.h"
23 #include "lwoDiscontinuousVertexMap.h"
25 #include "eggPolygon.h"
27 #include "deg_2_rad.h"
39 if (_tags != (
LwoTags *)NULL && _tags != tags) {
40 nout <<
"Multiple Tags fields in effect on the same polygons.\n";
44 IffId type = lwo_ptags->_tag_type;
46 bool inserted = _ptags.insert(PTags::value_type(type, lwo_ptags)).second;
48 nout <<
"Multiple polygon tags on the same polygons of type "
52 if (type ==
IffId(
"SURF")) {
53 _surf_ptags = lwo_ptags;
68 IffId map_type = lwo_vmad->_map_type;
69 const string &name = lwo_vmad->_name;
72 if (map_type ==
IffId(
"TXUV")) {
74 _txuv.insert(VMad::value_type(name, lwo_vmad)).second;
81 nout <<
"Multiple discontinous vertex maps on the same polygons of type "
82 << map_type <<
" named " << name <<
"\n";
99 if (!_surf_ptags->
has_tag(polygon_index)) {
104 int tag_index = _surf_ptags->
get_tag(polygon_index);
105 if (_tags == (
LwoTags *)NULL || tag_index < 0 ||
108 nout <<
"Invalid polygon tag index " << tag_index <<
"\n";
112 string tag = _tags->
get_tag(tag_index);
117 nout <<
"Unknown surface " << tag <<
"\n";
141 VMad::const_iterator ni = _txuv.find(uv_name);
142 if (ni == _txuv.end()) {
147 if (vmad->_dimension != 2) {
148 nout <<
"Unexpected dimension of " << vmad->_dimension
149 <<
" for discontinuous UV map " << uv_name <<
"\n";
157 PTA_stdfloat value = vmad->
get_value(pi, vi);
159 uv.set(value[0], value[1]);
175 if (_polygons->_polygon_type ==
IffId(
"CURV")) {
176 nout <<
"Ignoring Catmull-Rom splines.\n";
178 }
else if (_polygons->_polygon_type ==
IffId(
"PTCH")) {
179 nout <<
"Treating subdivision patches as ordinary polygons.\n";
182 }
else if (_polygons->_polygon_type ==
IffId(
"MBAL")) {
183 nout <<
"Ignoring metaballs.\n";
185 }
else if (_polygons->_polygon_type ==
IffId(
"BONE")) {
186 nout <<
"Ignoring bones.\n";
188 }
else if (_polygons->_polygon_type ==
IffId(
"FACE")) {
192 nout <<
"Ignoring unknown geometry type " << _polygons->_polygon_type
204 nassertv(_points->_layer->_egg_group != (
EggGroup *)NULL);
205 nassertv(_egg_group != (
EggGroup *)NULL);
206 _points->_layer->_egg_group->steal_children(*_egg_group);
217 PN_stdfloat smooth_angle = -1.0;
219 int num_polygons = _polygons->get_num_polygons();
220 for (
int pindex = 0; pindex < num_polygons; pindex++) {
224 bool is_valid =
true;
227 const LwoPoints *points = _points->_points;
237 if (poly->_vertices.size() == 1) {
246 vector_PT_EggVertex egg_vertices;
248 int num_vertices = poly->_vertices.size();
249 for (
int vi = num_vertices; vi > 0; vi--) {
250 int vindex = poly->_vertices[vi % num_vertices];
251 if (vindex < 0 || vindex >= num_points) {
252 nout <<
"Invalid vertex index " << vindex <<
" in polygon.\n";
256 LPoint3d pos = LCAST(
double, points->get_point(vindex));
257 egg_vertex->set_pos(pos);
260 if (surface != (
CLwoSurface *)NULL && surface->has_named_uvs()) {
263 if (
get_uv(uv_name, pindex, vindex, uv)) {
266 egg_vertex->set_uv(LCAST(
double, uv));
268 }
else if (_points->
get_uv(uv_name, vindex, uv)) {
271 egg_vertex->set_uv(LCAST(
double, uv));
275 egg_vertices.push_back(egg_vertex);
285 vector_PT_EggVertex::const_iterator evi;
286 for (evi = egg_vertices.begin(); evi != egg_vertices.end(); ++evi) {
287 EggVertex *egg_vertex = (*evi);
289 egg_prim->add_vertex(new_vertex);
293 _egg_group->add_child(egg_prim.p());
298 if (smooth_angle > 0.0) {
299 _egg_group->recompute_vertex_normals(rad_2_deg(smooth_angle), cs);
301 _egg_group->recompute_polygon_normals(cs);
A base class for any of a number of kinds of geometry primitives: polygons, point lights...
void add_vmad(const LwoDiscontinuousVertexMap *lwo_vmad)
Associates the indicated DiscontinousVertexMap with the polygons.
void add_ptags(const LwoPolygonTags *lwo_ptags, const LwoTags *tags)
Associates the indicated PolygonTags and Tags with the polygons in this chunk.
bool get_uv(const string &uv_name, int pi, int vi, LPoint2 &uv) const
Returns true if there is a UV of the indicated name associated with the given vertex of the indicated...
EggData * get_egg_data()
Returns the EggData structure.
PTA_stdfloat get_value(int polygon_index, int vertex_index) const
Returns the mapping value associated with the given index, or an empty PTA_stdfloat if there is no ma...
CLwoSurface * get_surface(int polygon_index) const
Returns the surface associated with the given polygon, or NULL if no surface is associated.
bool has_value(int polygon_index, int vertex_index) const
Returns true if the map has a value associated with the given index, false otherwise.
A single point, or a collection of points as defined by a single <PointLight> entry.
void make_egg()
Creates the egg structures associated with this Lightwave object.
The main glue of the egg hierarchy, this corresponds to the <Group>, <Instance>, and <Joint> type nod...
This class is a wrapper around LwoSurface and stores additional information useful during the convers...
CoordinateSystem get_coordinate_system() const
Returns the coordinate system in which the egg file is defined.
Any one-, two-, three-, or four-component vertex, possibly with attributes such as a normal...
const string & get_uv_name() const
Returns the name of the set of UV's that are associated with this surface, if has_named_uvs() is true...
void apply_properties(EggPrimitive *egg_prim, vector_PT_EggVertex &egg_vertices, PN_stdfloat &smooth_angle)
Applies the color, texture, etc.
This is a three-component point in space (as opposed to a three-component vector, which represents a ...
bool get_uv(const string &uv_name, int n, LPoint2 &uv) const
Returns true if there is a UV of the indicated name associated with the given vertex, false otherwise.
int get_num_points() const
Returns the number of points of this group.
CLwoSurface * get_surface(const string &name) const
Returns a pointer to the surface definition with the given name, or NULL if there is no such surface...
This is a two-component point in space.
A four-byte chunk ID appearing in an "IFF" file.
void connect_egg()
Connects all the egg structures together.
A mapping of floating-point values per integer index.
EggVertex * create_unique_vertex(const EggVertex ©)
Creates a new vertex in the pool that is a copy of the indicated one and returns it.
A collection of vertices.
An array of points that will be referenced by later chunks.