mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-01 01:07:51 -04:00
add -points, fix some obj2egg issues
This commit is contained in:
parent
0368aaaf82
commit
ca514b559b
@ -40,6 +40,7 @@ EggBase() {
|
||||
|
||||
_got_tbnall = false;
|
||||
_got_tbnauto = false;
|
||||
_make_points = false;
|
||||
|
||||
_got_transform = false;
|
||||
_transform = LMatrix4d::ident_mat();
|
||||
@ -109,6 +110,19 @@ add_normals_options() {
|
||||
&EggBase::dispatch_none, &_got_tbnauto);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: EggBase::add_points_options
|
||||
// Access: Public
|
||||
// Description: Adds -points as a valid option for this program.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
void EggBase::
|
||||
add_points_options() {
|
||||
add_option
|
||||
("points", "", 46,
|
||||
"Construct <PointLight> entries for any unreferenced vertices, to make them visible.",
|
||||
&EggBase::dispatch_none, &_make_points);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: EggBase::add_transform_options
|
||||
// Access: Public
|
||||
|
@ -34,6 +34,7 @@ public:
|
||||
EggBase();
|
||||
|
||||
void add_normals_options();
|
||||
void add_points_options();
|
||||
void add_transform_options();
|
||||
|
||||
static void convert_paths(EggNode *node, PathReplace *path_replace,
|
||||
@ -65,6 +66,8 @@ protected:
|
||||
vector_string _tbn_names;
|
||||
bool _got_tbnall;
|
||||
bool _got_tbnauto;
|
||||
|
||||
bool _make_points;
|
||||
|
||||
bool _got_transform;
|
||||
LMatrix4d _transform;
|
||||
|
@ -75,6 +75,13 @@ post_process_egg_files() {
|
||||
}
|
||||
}
|
||||
|
||||
if (_make_points) {
|
||||
nout << "Making points\n";
|
||||
for (ei = _eggs.begin(); ei != _eggs.end(); ++ei) {
|
||||
(*ei)->make_point_primitives();
|
||||
}
|
||||
}
|
||||
|
||||
switch (_normals_mode) {
|
||||
case NM_strip:
|
||||
nout << "Stripping normals.\n";
|
||||
|
@ -135,6 +135,11 @@ post_process_egg_file() {
|
||||
_data->transform(_transform);
|
||||
}
|
||||
|
||||
if (_make_points) {
|
||||
nout << "Making points\n";
|
||||
_data->make_point_primitives();
|
||||
}
|
||||
|
||||
bool needs_remove = false;
|
||||
|
||||
switch (_normals_mode) {
|
||||
|
@ -19,6 +19,7 @@
|
||||
#include "streamReader.h"
|
||||
#include "virtualFileSystem.h"
|
||||
#include "eggPolygon.h"
|
||||
#include "dcast.h"
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: ObjToEggConverter::Constructor
|
||||
@ -130,12 +131,15 @@ process(const Filename &filename) {
|
||||
return false;
|
||||
}
|
||||
|
||||
_vi = 0;
|
||||
_vti = 0;
|
||||
_vni = 0;
|
||||
_vi = 1;
|
||||
_vti = 1;
|
||||
_vni = 1;
|
||||
|
||||
_vpool = new EggVertexPool("vpool");
|
||||
_egg_data->add_child(_vpool);
|
||||
_root_group = new EggGroup("root");
|
||||
_egg_data->add_child(_root_group);
|
||||
_current_group = _root_group;
|
||||
|
||||
StreamReader sr(strm, true);
|
||||
string line = sr.readline();
|
||||
@ -143,10 +147,12 @@ process(const Filename &filename) {
|
||||
while (!line.empty()) {
|
||||
line = trim(line);
|
||||
if (line.empty()) {
|
||||
line = sr.readline();
|
||||
continue;
|
||||
}
|
||||
|
||||
if (line[0] == '#') {
|
||||
line = sr.readline();
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -180,6 +186,8 @@ process_line(const string &line) {
|
||||
return process_vn(words);
|
||||
} else if (tag == "f") {
|
||||
return process_f(words);
|
||||
} else if (tag == "g") {
|
||||
return process_g(words);
|
||||
} else {
|
||||
bool inserted = _ignored_tags.insert(tag).second;
|
||||
if (!inserted) {
|
||||
@ -250,13 +258,13 @@ process_vt(vector_string &words) {
|
||||
return false;
|
||||
}
|
||||
|
||||
EggVertex *vertex = get_vertex(_vi);
|
||||
EggVertex *vertex = get_vertex(_vti);
|
||||
if (words.size() == 4) {
|
||||
vertex->set_uvw("", uvw);
|
||||
} else {
|
||||
vertex->set_uv("", TexCoordd(uvw[0], uvw[1]));
|
||||
}
|
||||
++_vi;
|
||||
++_vti;
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -287,9 +295,9 @@ process_vn(vector_string &words) {
|
||||
}
|
||||
normal.normalize();
|
||||
|
||||
EggVertex *vertex = get_vertex(_vi);
|
||||
EggVertex *vertex = get_vertex(_vni);
|
||||
vertex->set_normal(normal);
|
||||
++_vi;
|
||||
++_vni;
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -297,7 +305,7 @@ process_vn(vector_string &words) {
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: ObjToEggConverter::process_f
|
||||
// Access: Protected
|
||||
// Description:
|
||||
// Description: Defines a face in the obj file.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
bool ObjToEggConverter::
|
||||
process_f(vector_string &words) {
|
||||
@ -309,11 +317,40 @@ process_f(vector_string &words) {
|
||||
}
|
||||
poly->add_vertex(vertex);
|
||||
}
|
||||
_egg_data->add_child(poly);
|
||||
_current_group->add_child(poly);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: ObjToEggConverter::process_g
|
||||
// Access: Protected
|
||||
// Description: Defines a group in the obj file.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
bool ObjToEggConverter::
|
||||
process_g(vector_string &words) {
|
||||
EggGroup *group = _root_group;
|
||||
|
||||
// We assume the group names define a hierarchy of more-specific to
|
||||
// less-specific group names, so that the first group name is the
|
||||
// bottommost node, and the last group name is the topmost node.
|
||||
|
||||
// Thus, iterate from the back to the front.
|
||||
size_t i = words.size();
|
||||
while (i != 0) {
|
||||
--i;
|
||||
EggNode *child = group->find_child(words[i]);
|
||||
if (child == NULL || !child->is_of_type(EggGroup::get_class_type())) {
|
||||
child = new EggGroup(words[i]);
|
||||
group->add_child(child);
|
||||
}
|
||||
group = DCAST(EggGroup, child);
|
||||
}
|
||||
|
||||
_current_group = group;
|
||||
return true;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: ObjToEggConverter::get_vertex
|
||||
// Access: Protected
|
||||
@ -322,6 +359,10 @@ process_f(vector_string &words) {
|
||||
////////////////////////////////////////////////////////////////////
|
||||
EggVertex *ObjToEggConverter::
|
||||
get_vertex(int n) {
|
||||
if (n < 0) {
|
||||
// A negative index means to count backward from the end.
|
||||
n = _vi + n;
|
||||
}
|
||||
EggVertex *vertex = _vpool->get_vertex(n);
|
||||
if (vertex == NULL) {
|
||||
vertex = new EggVertex;
|
||||
|
@ -19,6 +19,7 @@
|
||||
|
||||
#include "somethingToEggConverter.h"
|
||||
#include "eggVertexPool.h"
|
||||
#include "eggGroup.h"
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Class : ObjToEggConverter
|
||||
@ -46,6 +47,7 @@ protected:
|
||||
bool process_vt(vector_string &words);
|
||||
bool process_vn(vector_string &words);
|
||||
bool process_f(vector_string &words);
|
||||
bool process_g(vector_string &words);
|
||||
|
||||
EggVertex *get_vertex(int n);
|
||||
EggVertex *get_face_vertex(const string &face_reference);
|
||||
@ -53,6 +55,8 @@ protected:
|
||||
int _line_number;
|
||||
int _vi, _vti, _vni;
|
||||
PT(EggVertexPool) _vpool;
|
||||
PT(EggGroup) _root_group;
|
||||
EggGroup *_current_group;
|
||||
|
||||
pset<string> _ignored_tags;
|
||||
};
|
||||
|
@ -27,6 +27,7 @@ ObjToEgg() :
|
||||
SomethingToEgg("obj", ".obj")
|
||||
{
|
||||
add_units_options();
|
||||
add_points_options();
|
||||
add_normals_options();
|
||||
add_transform_options();
|
||||
|
||||
|
@ -147,7 +147,9 @@ load_file(const Filename &path, const LoaderOptions &options,
|
||||
egg_data->transform(LMatrix4d::scale_mat(scale));
|
||||
}
|
||||
|
||||
if (!egg_data->has_normals()) {
|
||||
if (!egg_data->has_primitives()) {
|
||||
egg_data->make_point_primitives();
|
||||
} else if (!egg_data->has_normals()) {
|
||||
egg_data->recompute_polygon_normals();
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user