*** empty log message ***
This commit is contained in:
parent
aa0f79a36f
commit
d1b8bf8bf6
|
|
@ -36,6 +36,16 @@ FltToEggConverter::
|
|||
FltToEggConverter() {
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: FltToEggConverter::Destructor
|
||||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
FltToEggConverter::
|
||||
~FltToEggConverter() {
|
||||
cleanup();
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: FltToEggConverter::get_name
|
||||
|
|
@ -103,7 +113,7 @@ convert_flt(const FltHeader *flt_header) {
|
|||
|
||||
// Generate a default vertex pool.
|
||||
_main_egg_vpool = new EggVertexPool("vpool");
|
||||
_egg_data->add_child(_main_egg_vpool);
|
||||
_egg_data->add_child(_main_egg_vpool.p());
|
||||
|
||||
// We could populate the vertex pool right away, but it's better to
|
||||
// defer each vertex until we encounter it, since some of the
|
||||
|
|
@ -118,12 +128,28 @@ convert_flt(const FltHeader *flt_header) {
|
|||
if (_main_egg_vpool->empty()) {
|
||||
// If we didn't get any global vertices, remove the vertex pool
|
||||
// just for cleanliness.
|
||||
_egg_data->remove_child(_main_egg_vpool);
|
||||
_egg_data->remove_child(_main_egg_vpool.p());
|
||||
}
|
||||
|
||||
cleanup();
|
||||
|
||||
return !_error;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: FltToEggConverter::cleanup
|
||||
// Access: Private
|
||||
// Description: Frees all the internal data structures after we're
|
||||
// done converting, and resets the converter to its
|
||||
// initial state.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
void FltToEggConverter::
|
||||
cleanup() {
|
||||
_flt_header.clear();
|
||||
_main_egg_vpool.clear();
|
||||
_textures.clear();
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: FltToEggConverter::convert_record
|
||||
// Access: Private
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@
|
|||
#include <somethingToEggConverter.h>
|
||||
#include <fltHeader.h>
|
||||
#include <eggVertex.h>
|
||||
#include <eggVertexPool.h>
|
||||
#include <eggTexture.h>
|
||||
#include <pointerTo.h>
|
||||
|
||||
|
|
@ -29,7 +30,6 @@ class FltExternalReference;
|
|||
class FltTexture;
|
||||
class EggGroupNode;
|
||||
class EggPrimitive;
|
||||
class EggVertexPool;
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Class : FltToEggConverter
|
||||
|
|
@ -41,6 +41,7 @@ class EggVertexPool;
|
|||
class FltToEggConverter : public SomethingToEggConverter {
|
||||
public:
|
||||
FltToEggConverter();
|
||||
~FltToEggConverter();
|
||||
|
||||
virtual string get_name() const;
|
||||
virtual string get_extension() const;
|
||||
|
|
@ -49,6 +50,8 @@ public:
|
|||
bool convert_flt(const FltHeader *flt_header);
|
||||
|
||||
private:
|
||||
void cleanup();
|
||||
|
||||
typedef vector< PT(EggVertex) > EggVertices;
|
||||
|
||||
void convert_record(const FltRecord *flt_record, FltToEggLevelState &state);
|
||||
|
|
@ -79,7 +82,7 @@ private:
|
|||
|
||||
CPT(FltHeader) _flt_header;
|
||||
|
||||
EggVertexPool *_main_egg_vpool;
|
||||
PT(EggVertexPool) _main_egg_vpool;
|
||||
|
||||
typedef map<const FltTexture *, PT(EggTexture) > Textures;
|
||||
Textures _textures;
|
||||
|
|
|
|||
|
|
@ -139,9 +139,9 @@ make_faces() {
|
|||
float smooth_angle = -1.0;
|
||||
|
||||
int num_polygons = _polygons->get_num_polygons();
|
||||
for (int i = 0; i < num_polygons; i++) {
|
||||
LwoPolygons::Polygon *poly = _polygons->get_polygon(i);
|
||||
CLwoSurface *surface = get_surface(i);
|
||||
for (int pindex = 0; pindex < num_polygons; pindex++) {
|
||||
LwoPolygons::Polygon *poly = _polygons->get_polygon(pindex);
|
||||
CLwoSurface *surface = get_surface(pindex);
|
||||
|
||||
bool is_valid = true;
|
||||
|
||||
|
|
@ -154,38 +154,50 @@ make_faces() {
|
|||
// clockwise ordering convention. We also want to start with the
|
||||
// last vertex, so that the first convex angle is the first angle
|
||||
// in the EggPolygon (for determining correct normals).
|
||||
int num_vertices = poly->_vertices.size();
|
||||
PT(EggPrimitive) egg_prim;
|
||||
|
||||
if (num_vertices == 1) {
|
||||
if (poly->_vertices.size() == 1) {
|
||||
egg_prim = new EggPoint;
|
||||
} else {
|
||||
egg_prim = new EggPolygon;
|
||||
}
|
||||
|
||||
if (surface != (CLwoSurface *)NULL) {
|
||||
surface->apply_properties(egg_prim, smooth_angle);
|
||||
}
|
||||
surface->check_texture();
|
||||
|
||||
// First, we have to create a temporary vector of vertices for the
|
||||
// polygon, so we can possibly adjust the properties of these
|
||||
// vertices (like the UV's) in the shader before we create them.
|
||||
vector_PT_EggVertex egg_vertices;
|
||||
|
||||
int num_vertices = poly->_vertices.size();
|
||||
for (int vi = num_vertices; vi > 0; vi--) {
|
||||
int vindex = poly->_vertices[vi % num_vertices];
|
||||
if (vindex < 0 || vindex >= num_points) {
|
||||
nout << "Invalid vertex index " << vindex << " in polygon.\n";
|
||||
is_valid = false;
|
||||
|
||||
} else {
|
||||
EggVertex egg_vert;
|
||||
PT(EggVertex) egg_vertex = new EggVertex;
|
||||
LPoint3d pos = LCAST(double, points->get_point(vindex));
|
||||
egg_vert.set_pos(pos);
|
||||
if (surface != (CLwoSurface *)NULL && surface->has_uvs()) {
|
||||
egg_vert.set_uv(surface->get_uv(pos));
|
||||
}
|
||||
EggVertex *new_vert = egg_vpool->create_unique_vertex(egg_vert);
|
||||
egg_prim->add_vertex(new_vert);
|
||||
egg_vertex->set_pos(pos);
|
||||
|
||||
egg_vertices.push_back(egg_vertex);
|
||||
}
|
||||
}
|
||||
|
||||
if (is_valid) {
|
||||
if (surface != (CLwoSurface *)NULL) {
|
||||
surface->apply_properties(egg_prim, egg_vertices, smooth_angle);
|
||||
}
|
||||
|
||||
// Now add all the vertices officially to the primitive.
|
||||
vector_PT_EggVertex::const_iterator evi;
|
||||
for (evi = egg_vertices.begin(); evi != egg_vertices.end(); ++evi) {
|
||||
EggVertex *egg_vertex = (*evi);
|
||||
EggVertex *new_vertex = egg_vpool->create_unique_vertex(*egg_vertex);
|
||||
egg_prim->add_vertex(new_vertex);
|
||||
}
|
||||
|
||||
// And add the primitive to its parent.
|
||||
_egg_group->add_child(egg_prim.p());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -135,13 +135,14 @@ CLwoSurface::
|
|||
// angle is greater than that specified.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
void CLwoSurface::
|
||||
apply_properties(EggPrimitive *egg_prim, float &smooth_angle) {
|
||||
apply_properties(EggPrimitive *egg_prim, vector_PT_EggVertex &egg_vertices,
|
||||
float &smooth_angle) {
|
||||
if (!_surface->_source.empty()) {
|
||||
// This surface is derived from another surface; apply that one
|
||||
// first.
|
||||
CLwoSurface *parent = _converter->get_surface(_surface->_source);
|
||||
if (parent != (CLwoSurface *)NULL && parent != this) {
|
||||
parent->apply_properties(egg_prim, smooth_angle);
|
||||
parent->apply_properties(egg_prim, egg_vertices, smooth_angle);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -165,6 +166,13 @@ apply_properties(EggPrimitive *egg_prim, float &smooth_angle) {
|
|||
// Texture overrides the primitive's natural color.
|
||||
egg_prim->set_texture(_egg_texture);
|
||||
egg_prim->clear_color();
|
||||
|
||||
// Assign UV's to the vertices.
|
||||
vector_PT_EggVertex::const_iterator vi;
|
||||
for (vi = egg_vertices.begin(); vi != egg_vertices.end(); ++vi) {
|
||||
EggVertex *egg_vertex = (*vi);
|
||||
egg_vertex->set_uv(get_uv(egg_vertex->get_pos3()));
|
||||
}
|
||||
}
|
||||
|
||||
if ((_flags & F_transparency) != 0) {
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@
|
|||
#include <lwoSurface.h>
|
||||
#include <luse.h>
|
||||
#include <eggTexture.h>
|
||||
#include <vector_PT_EggVertex.h>
|
||||
|
||||
#include <map>
|
||||
|
||||
|
|
@ -32,7 +33,9 @@ public:
|
|||
|
||||
INLINE const string &get_name() const;
|
||||
|
||||
void apply_properties(EggPrimitive *egg_prim, float &smooth_angle);
|
||||
void apply_properties(EggPrimitive *egg_prim,
|
||||
vector_PT_EggVertex &egg_vertices,
|
||||
float &smooth_angle);
|
||||
bool check_texture();
|
||||
|
||||
INLINE bool has_uvs() const;
|
||||
|
|
|
|||
|
|
@ -39,43 +39,7 @@ LwoToEggConverter() {
|
|||
////////////////////////////////////////////////////////////////////
|
||||
LwoToEggConverter::
|
||||
~LwoToEggConverter() {
|
||||
if (_generic_layer != (CLwoLayer *)NULL) {
|
||||
delete _generic_layer;
|
||||
}
|
||||
|
||||
Layers::iterator li;
|
||||
for (li = _layers.begin(); li != _layers.end(); ++li) {
|
||||
CLwoLayer *layer = (*li);
|
||||
if (layer != (CLwoLayer *)NULL) {
|
||||
delete layer;
|
||||
}
|
||||
}
|
||||
|
||||
Clips::iterator ci;
|
||||
for (ci = _clips.begin(); ci != _clips.end(); ++ci) {
|
||||
CLwoClip *clip = (*ci);
|
||||
if (clip != (CLwoClip *)NULL) {
|
||||
delete clip;
|
||||
}
|
||||
}
|
||||
|
||||
Points::iterator pi;
|
||||
for (pi = _points.begin(); pi != _points.end(); ++pi) {
|
||||
CLwoPoints *points = (*pi);
|
||||
delete points;
|
||||
}
|
||||
|
||||
Polygons::iterator gi;
|
||||
for (gi = _polygons.begin(); gi != _polygons.end(); ++gi) {
|
||||
CLwoPolygons *polygons = (*gi);
|
||||
delete polygons;
|
||||
}
|
||||
|
||||
Surfaces::iterator si;
|
||||
for (si = _surfaces.begin(); si != _surfaces.end(); ++si) {
|
||||
CLwoSurface *surface = (*si).second;
|
||||
delete surface;
|
||||
}
|
||||
cleanup();
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
|
@ -164,6 +128,7 @@ convert_lwo(const LwoHeader *lwo_header) {
|
|||
connect_egg();
|
||||
|
||||
_egg_data->remove_unused_vertices();
|
||||
cleanup();
|
||||
|
||||
return !_error;
|
||||
}
|
||||
|
|
@ -212,6 +177,62 @@ get_surface(const string &name) const {
|
|||
return (CLwoSurface *)NULL;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: LwoToEggConverter::cleanup
|
||||
// Access: Private
|
||||
// Description: Frees all the internal data structures after we're
|
||||
// done converting, and resets the converter to its
|
||||
// initial state.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
void LwoToEggConverter::
|
||||
cleanup() {
|
||||
_lwo_header.clear();
|
||||
|
||||
if (_generic_layer != (CLwoLayer *)NULL) {
|
||||
delete _generic_layer;
|
||||
_generic_layer = (CLwoLayer *)NULL;
|
||||
}
|
||||
|
||||
Layers::iterator li;
|
||||
for (li = _layers.begin(); li != _layers.end(); ++li) {
|
||||
CLwoLayer *layer = (*li);
|
||||
if (layer != (CLwoLayer *)NULL) {
|
||||
delete layer;
|
||||
}
|
||||
}
|
||||
_layers.clear();
|
||||
|
||||
Clips::iterator ci;
|
||||
for (ci = _clips.begin(); ci != _clips.end(); ++ci) {
|
||||
CLwoClip *clip = (*ci);
|
||||
if (clip != (CLwoClip *)NULL) {
|
||||
delete clip;
|
||||
}
|
||||
}
|
||||
_clips.clear();
|
||||
|
||||
Points::iterator pi;
|
||||
for (pi = _points.begin(); pi != _points.end(); ++pi) {
|
||||
CLwoPoints *points = (*pi);
|
||||
delete points;
|
||||
}
|
||||
_points.clear();
|
||||
|
||||
Polygons::iterator gi;
|
||||
for (gi = _polygons.begin(); gi != _polygons.end(); ++gi) {
|
||||
CLwoPolygons *polygons = (*gi);
|
||||
delete polygons;
|
||||
}
|
||||
_polygons.clear();
|
||||
|
||||
Surfaces::iterator si;
|
||||
for (si = _surfaces.begin(); si != _surfaces.end(); ++si) {
|
||||
CLwoSurface *surface = (*si).second;
|
||||
delete surface;
|
||||
}
|
||||
_surfaces.clear();
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: LwoToEggConverter::collect_lwo
|
||||
// Access: Private
|
||||
|
|
|
|||
|
|
@ -46,6 +46,8 @@ public:
|
|||
CLwoSurface *get_surface(const string &name) const;
|
||||
|
||||
private:
|
||||
void cleanup();
|
||||
|
||||
void collect_lwo();
|
||||
void make_egg();
|
||||
void connect_egg();
|
||||
|
|
|
|||
Loading…
Reference in New Issue