mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-02 18:03:56 -04:00
support continuation characters, lines, points, and larger files
This commit is contained in:
parent
a16238932a
commit
355f786068
@ -19,6 +19,8 @@
|
|||||||
#include "streamReader.h"
|
#include "streamReader.h"
|
||||||
#include "virtualFileSystem.h"
|
#include "virtualFileSystem.h"
|
||||||
#include "eggPolygon.h"
|
#include "eggPolygon.h"
|
||||||
|
#include "eggPoint.h"
|
||||||
|
#include "eggLine.h"
|
||||||
#include "dcast.h"
|
#include "dcast.h"
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
@ -161,16 +163,16 @@ process(const Filename &filename) {
|
|||||||
// Function: EggToObjConverter::collect_vertices
|
// Function: EggToObjConverter::collect_vertices
|
||||||
// Access: Private
|
// Access: Private
|
||||||
// Description: Recursively walks the egg structure, looking for
|
// Description: Recursively walks the egg structure, looking for
|
||||||
// vertices referenced by polygons. Any such vertices
|
// vertices referenced by polygons or points. Any such
|
||||||
// are added to the vertex tables for writing to the obj
|
// vertices are added to the vertex tables for writing
|
||||||
// file.
|
// to the obj file.
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
void EggToObjConverter::
|
void EggToObjConverter::
|
||||||
collect_vertices(EggNode *egg_node) {
|
collect_vertices(EggNode *egg_node) {
|
||||||
if (egg_node->is_of_type(EggPolygon::get_class_type())) {
|
if (egg_node->is_of_type(EggPrimitive::get_class_type())) {
|
||||||
EggPolygon *egg_poly = DCAST(EggPolygon, egg_node);
|
EggPrimitive *egg_prim = DCAST(EggPrimitive, egg_node);
|
||||||
EggPolygon::iterator pi;
|
EggPrimitive::iterator pi;
|
||||||
for (pi = egg_poly->begin(); pi != egg_poly->end(); ++pi) {
|
for (pi = egg_prim->begin(); pi != egg_prim->end(); ++pi) {
|
||||||
record_vertex(*pi);
|
record_vertex(*pi);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -188,19 +190,29 @@ collect_vertices(EggNode *egg_node) {
|
|||||||
// Function: EggToObjConverter::write_faces
|
// Function: EggToObjConverter::write_faces
|
||||||
// Access: Private
|
// Access: Private
|
||||||
// Description: Recursively walks the egg structure again, this time
|
// Description: Recursively walks the egg structure again, this time
|
||||||
// writing out the face records for any polygons
|
// writing out the face records for any polygons,
|
||||||
// encountered.
|
// points, or lines encountered.
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
void EggToObjConverter::
|
void EggToObjConverter::
|
||||||
write_faces(ostream &out, EggNode *egg_node) {
|
write_faces(ostream &out, EggNode *egg_node) {
|
||||||
|
if (egg_node->is_of_type(EggPrimitive::get_class_type())) {
|
||||||
|
const char *prim_type = NULL;
|
||||||
if (egg_node->is_of_type(EggPolygon::get_class_type())) {
|
if (egg_node->is_of_type(EggPolygon::get_class_type())) {
|
||||||
|
prim_type = "f";
|
||||||
|
} else if (egg_node->is_of_type(EggPoint::get_class_type())) {
|
||||||
|
prim_type = "p";
|
||||||
|
} else if (egg_node->is_of_type(EggLine::get_class_type())) {
|
||||||
|
prim_type = "l";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (prim_type != NULL) {
|
||||||
write_group_reference(out, egg_node);
|
write_group_reference(out, egg_node);
|
||||||
|
|
||||||
EggPolygon *egg_poly = DCAST(EggPolygon, egg_node);
|
EggPrimitive *egg_prim = DCAST(EggPrimitive, egg_node);
|
||||||
|
|
||||||
out << "f";
|
out << prim_type;
|
||||||
EggPolygon::iterator pi;
|
EggPrimitive::iterator pi;
|
||||||
for (pi = egg_poly->begin(); pi != egg_poly->end(); ++pi) {
|
for (pi = egg_prim->begin(); pi != egg_prim->end(); ++pi) {
|
||||||
VertexDef &vdef = _vmap[(*pi)];
|
VertexDef &vdef = _vmap[(*pi)];
|
||||||
int vert_index = -1;
|
int vert_index = -1;
|
||||||
int uv_index = -1;
|
int uv_index = -1;
|
||||||
@ -239,7 +251,7 @@ write_faces(ostream &out, EggNode *egg_node) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
out << "\n";
|
out << "\n";
|
||||||
|
}
|
||||||
} else if (egg_node->is_of_type(EggGroupNode::get_class_type())) {
|
} else if (egg_node->is_of_type(EggGroupNode::get_class_type())) {
|
||||||
EggGroupNode *egg_group = DCAST(EggGroupNode, egg_node);
|
EggGroupNode *egg_group = DCAST(EggGroupNode, egg_node);
|
||||||
|
|
||||||
@ -408,7 +420,7 @@ write_vertices(ostream &out, const string &prefix, int num_components,
|
|||||||
const UniqueVertices &unique) {
|
const UniqueVertices &unique) {
|
||||||
// First, sort the list into numeric order.
|
// First, sort the list into numeric order.
|
||||||
int num_vertices = (int)unique.size();
|
int num_vertices = (int)unique.size();
|
||||||
const LVecBase4d **vertices = (const LVecBase4d **)alloca(num_vertices * sizeof(LVecBase4d *));
|
const LVecBase4d **vertices = (const LVecBase4d **)PANDA_MALLOC_ARRAY(num_vertices * sizeof(LVecBase4d *));
|
||||||
memset(vertices, 0, num_vertices * sizeof(LVecBase4d *));
|
memset(vertices, 0, num_vertices * sizeof(LVecBase4d *));
|
||||||
UniqueVertices::const_iterator ui;
|
UniqueVertices::const_iterator ui;
|
||||||
for (ui = unique.begin(); ui != unique.end(); ++ui) {
|
for (ui = unique.begin(); ui != unique.end(); ++ui) {
|
||||||
@ -427,6 +439,7 @@ write_vertices(ostream &out, const string &prefix, int num_components,
|
|||||||
}
|
}
|
||||||
out << "\n";
|
out << "\n";
|
||||||
}
|
}
|
||||||
|
PANDA_FREE_ARRAY(vertices);
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
|
@ -210,6 +210,16 @@ process(const Filename &filename) {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
while (line[line.length() - 1] == '\\') {
|
||||||
|
// If it ends on a backslash, it's a continuation character.
|
||||||
|
string line2 = sr.readline();
|
||||||
|
++_line_number;
|
||||||
|
if (line2.empty()) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
line = line.substr(0, line.length() - 1) + trim(line2);
|
||||||
|
}
|
||||||
|
|
||||||
if (line.substr(0, 15) == "#_ref_plane_res") {
|
if (line.substr(0, 15) == "#_ref_plane_res") {
|
||||||
process_ref_plane_res(line);
|
process_ref_plane_res(line);
|
||||||
line = sr.readline();
|
line = sr.readline();
|
||||||
@ -296,7 +306,7 @@ process_ref_plane_res(const string &line) {
|
|||||||
|
|
||||||
if (!okflag) {
|
if (!okflag) {
|
||||||
objegg_cat.error()
|
objegg_cat.error()
|
||||||
<< "Invalid number at line " << _line_number << "\n";
|
<< "Invalid number at line " << _line_number << ":\n";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user