mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-04 10:54:24 -04:00
*** empty log message ***
This commit is contained in:
parent
e5a4d3ec81
commit
97500fea13
@ -1,40 +1,40 @@
|
||||
// Filename: xFileFace.cxx
|
||||
// Created by: drose (19Jun01)
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// PANDA 3D SOFTWARE
|
||||
// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved
|
||||
//
|
||||
// All use of this software is subject to the terms of the Panda 3d
|
||||
// Software license. You should have received a copy of this license
|
||||
// along with this source code; you will also find a current copy of
|
||||
// the license at http://www.panda3d.org/license.txt .
|
||||
//
|
||||
// To contact the maintainers of this program write to
|
||||
// panda3d@yahoogroups.com .
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "xFileFace.h"
|
||||
#include "xFileMesh.h"
|
||||
#include "eggPolygon.h"
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: XFileFace::Constructor
|
||||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
XFileFace::
|
||||
XFileFace(XFileMesh *mesh, EggPolygon *egg_poly) {
|
||||
// Walk through the polygon's vertices in reverse order, to change
|
||||
// from Egg's counter-clockwise convention to DX's clockwise.
|
||||
EggPolygon::reverse_iterator vi;
|
||||
for (vi = egg_poly->rbegin(); vi != egg_poly->rend(); ++vi) {
|
||||
EggVertex *egg_vertex = (*vi);
|
||||
Vertex v;
|
||||
v._vertex_index = mesh->add_vertex(egg_vertex, egg_poly);
|
||||
v._normal_index = mesh->add_normal(egg_vertex, egg_poly);
|
||||
_vertices.push_back(v);
|
||||
}
|
||||
}
|
||||
// Filename: xFileFace.cxx
|
||||
// Created by: drose (19Jun01)
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// PANDA 3D SOFTWARE
|
||||
// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved
|
||||
//
|
||||
// All use of this software is subject to the terms of the Panda 3d
|
||||
// Software license. You should have received a copy of this license
|
||||
// along with this source code; you will also find a current copy of
|
||||
// the license at http://www.panda3d.org/license.txt .
|
||||
//
|
||||
// To contact the maintainers of this program write to
|
||||
// panda3d@yahoogroups.com .
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "xFileFace.h"
|
||||
#include "xFileMesh.h"
|
||||
#include "eggPolygon.h"
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: XFileFace::Constructor
|
||||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
XFileFace::
|
||||
XFileFace(XFileMesh *mesh, EggPolygon *egg_poly) {
|
||||
// Walk through the polygon's vertices in reverse order, to change
|
||||
// from Egg's counter-clockwise convention to DX's clockwise.
|
||||
EggPolygon::reverse_iterator vi;
|
||||
for (vi = egg_poly->rbegin(); vi != egg_poly->rend(); ++vi) {
|
||||
EggVertex *egg_vertex = (*vi);
|
||||
Vertex v;
|
||||
v._vertex_index = mesh->add_vertex(egg_vertex, egg_poly);
|
||||
v._normal_index = mesh->add_normal(egg_vertex, egg_poly);
|
||||
_vertices.push_back(v);
|
||||
}
|
||||
}
|
||||
|
@ -1,46 +1,46 @@
|
||||
// Filename: xFileFace.h
|
||||
// Created by: drose (19Jun01)
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// PANDA 3D SOFTWARE
|
||||
// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved
|
||||
//
|
||||
// All use of this software is subject to the terms of the Panda 3d
|
||||
// Software license. You should have received a copy of this license
|
||||
// along with this source code; you will also find a current copy of
|
||||
// the license at http://www.panda3d.org/license.txt .
|
||||
//
|
||||
// To contact the maintainers of this program write to
|
||||
// panda3d@yahoogroups.com .
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef XFILEFACE_H
|
||||
#define XFILEFACE_H
|
||||
|
||||
#include "pandatoolbase.h"
|
||||
#include "pvector.h"
|
||||
|
||||
class XFileMesh;
|
||||
class EggPolygon;
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Class : XFileFace
|
||||
// Description : This represents a single face of an XFileMesh.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
class XFileFace {
|
||||
public:
|
||||
XFileFace(XFileMesh *mesh, EggPolygon *egg_poly);
|
||||
|
||||
class Vertex {
|
||||
public:
|
||||
int _vertex_index;
|
||||
int _normal_index;
|
||||
};
|
||||
typedef pvector<Vertex> Vertices;
|
||||
Vertices _vertices;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
// Filename: xFileFace.h
|
||||
// Created by: drose (19Jun01)
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// PANDA 3D SOFTWARE
|
||||
// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved
|
||||
//
|
||||
// All use of this software is subject to the terms of the Panda 3d
|
||||
// Software license. You should have received a copy of this license
|
||||
// along with this source code; you will also find a current copy of
|
||||
// the license at http://www.panda3d.org/license.txt .
|
||||
//
|
||||
// To contact the maintainers of this program write to
|
||||
// panda3d@yahoogroups.com .
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef XFILEFACE_H
|
||||
#define XFILEFACE_H
|
||||
|
||||
#include "pandatoolbase.h"
|
||||
#include "pvector.h"
|
||||
|
||||
class XFileMesh;
|
||||
class EggPolygon;
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Class : XFileFace
|
||||
// Description : This represents a single face of an XFileMesh.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
class XFileFace {
|
||||
public:
|
||||
XFileFace(XFileMesh *mesh, EggPolygon *egg_poly);
|
||||
|
||||
class Vertex {
|
||||
public:
|
||||
int _vertex_index;
|
||||
int _normal_index;
|
||||
};
|
||||
typedef pvector<Vertex> Vertices;
|
||||
Vertices _vertices;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
|
@ -1,388 +1,388 @@
|
||||
// Filename: xFileMaker.cxx
|
||||
// Created by: drose (19Jun01)
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// PANDA 3D SOFTWARE
|
||||
// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved
|
||||
//
|
||||
// All use of this software is subject to the terms of the Panda 3d
|
||||
// Software license. You should have received a copy of this license
|
||||
// along with this source code; you will also find a current copy of
|
||||
// the license at http://www.panda3d.org/license.txt .
|
||||
//
|
||||
// To contact the maintainers of this program write to
|
||||
// panda3d@yahoogroups.com .
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "xFileMaker.h"
|
||||
#include "xFileMesh.h"
|
||||
#include "notify.h"
|
||||
#include "eggGroupNode.h"
|
||||
#include "eggGroup.h"
|
||||
#include "eggBin.h"
|
||||
#include "eggPolysetMaker.h"
|
||||
#include "eggVertexPool.h"
|
||||
#include "eggVertex.h"
|
||||
#include "eggPolygon.h"
|
||||
#include "eggData.h"
|
||||
#include "pvector.h"
|
||||
#include "vector_int.h"
|
||||
#include "string_utils.h"
|
||||
#include "datagram.h"
|
||||
|
||||
// This must be included only in exactly one .cxx file, since
|
||||
// including defines the structure!
|
||||
#include <rmxftmpl.h>
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: XFileMaker::Constructor
|
||||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
XFileMaker::
|
||||
XFileMaker() {
|
||||
_dx_file = NULL;
|
||||
_dx_file_save = NULL;
|
||||
_mesh_index = 0;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: XFileMaker::Destructor
|
||||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
XFileMaker::
|
||||
~XFileMaker() {
|
||||
close();
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: XFileMaker::open
|
||||
// Access: Public
|
||||
// Description: Opens the indicated filename for writing, and writes
|
||||
// the .x header information; returns true on success,
|
||||
// false otherwise.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
bool XFileMaker::
|
||||
open(const Filename &filename) {
|
||||
HRESULT hr;
|
||||
|
||||
close();
|
||||
hr = DirectXFileCreate(&_dx_file);
|
||||
if (hr != DXFILE_OK) {
|
||||
nout << "Unable to create X interface.\n";
|
||||
return false;
|
||||
}
|
||||
|
||||
// Register our templates.
|
||||
hr = _dx_file->RegisterTemplates(D3DRM_XTEMPLATES, D3DRM_XTEMPLATE_BYTES);
|
||||
if (hr != DXFILE_OK) {
|
||||
nout << "Unable to register templates.\n";
|
||||
return false;
|
||||
}
|
||||
|
||||
string os_file = filename.to_os_specific();
|
||||
hr = _dx_file->CreateSaveObject(os_file.c_str(), DXFILEFORMAT_TEXT,
|
||||
&_dx_file_save);
|
||||
if (hr != DXFILE_OK) {
|
||||
nout << "Unable to open X file: " << os_file << "\n";
|
||||
return false;
|
||||
}
|
||||
|
||||
// Save the templates we will use.
|
||||
static const GUID *temps[] = {
|
||||
&TID_D3DRMCoords2d,
|
||||
&TID_D3DRMVector,
|
||||
&TID_D3DRMColorRGBA,
|
||||
&TID_D3DRMColorRGB,
|
||||
&TID_D3DRMIndexedColor,
|
||||
&TID_D3DRMTextureFilename,
|
||||
&TID_D3DRMMaterial,
|
||||
&TID_D3DRMMeshFace,
|
||||
&TID_D3DRMMesh,
|
||||
&TID_D3DRMMeshNormals,
|
||||
&TID_D3DRMMeshTextureCoords,
|
||||
&TID_D3DRMMeshMaterialList,
|
||||
&TID_D3DRMFrame,
|
||||
};
|
||||
static const int num_temps = sizeof(temps) / sizeof(temps[0]);
|
||||
hr = _dx_file_save->SaveTemplates(num_temps, temps);
|
||||
if (hr != DXFILE_OK) {
|
||||
nout << "Unable to save templates.\n";
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: XFileMaker::close
|
||||
// Access: Public
|
||||
// Description: Finalizes and closes the file previously opened via
|
||||
// open().
|
||||
////////////////////////////////////////////////////////////////////
|
||||
void XFileMaker::
|
||||
close() {
|
||||
if (_dx_file != NULL) {
|
||||
if (_dx_file_save != NULL) {
|
||||
_dx_file_save->Release();
|
||||
_dx_file_save = NULL;
|
||||
}
|
||||
_dx_file->Release();
|
||||
_dx_file = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: XFileMaker::add_tree
|
||||
// Access: Public
|
||||
// Description: Adds the egg tree rooted at the indicated node to the
|
||||
// DX structure. This may be somewhat destructive of
|
||||
// the egg tree. Returns true on success, false on
|
||||
// failure.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
bool XFileMaker::
|
||||
add_tree(EggData &egg_data) {
|
||||
// Now collect all the polygons together into polysets.
|
||||
EggPolysetMaker pmaker;
|
||||
int num_bins = pmaker.make_bins(&egg_data);
|
||||
|
||||
// And now we're ready to traverse the egg hierarchy.
|
||||
return add_node(&egg_data, NULL);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: XFileMaker::add_node
|
||||
// Access: Private
|
||||
// Description: Adds the node to the DX structure, in whatever form
|
||||
// it is supported.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
bool XFileMaker::
|
||||
add_node(EggNode *egg_node, LPDIRECTXFILEDATA dx_parent) {
|
||||
if (egg_node->is_of_type(EggBin::get_class_type())) {
|
||||
return add_bin(DCAST(EggBin, egg_node), dx_parent);
|
||||
|
||||
} else if (egg_node->is_of_type(EggGroup::get_class_type())) {
|
||||
return add_group(DCAST(EggGroup, egg_node), dx_parent);
|
||||
|
||||
} else if (egg_node->is_of_type(EggGroupNode::get_class_type())) {
|
||||
// A grouping node of some kind.
|
||||
EggGroupNode *egg_group = DCAST(EggGroupNode, egg_node);
|
||||
LPDIRECTXFILEDATA obj;
|
||||
if (!create_frame(obj, egg_group->get_name())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!recurse_nodes(egg_group, obj)) {
|
||||
obj->Release();
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!attach_and_release(obj, dx_parent)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// Some unsupported node type. Ignore it.
|
||||
return true;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: XFileMaker::add_group
|
||||
// Access: Private
|
||||
// Description: Adds a frame for the indicated group node.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
bool XFileMaker::
|
||||
add_group(EggGroup *egg_group, LPDIRECTXFILEDATA dx_parent) {
|
||||
LPDIRECTXFILEDATA obj;
|
||||
if (!create_frame(obj, egg_group->get_name())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!recurse_nodes(egg_group, obj)) {
|
||||
obj->Release();
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!attach_and_release(obj, dx_parent)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: XFileMaker::add_bin
|
||||
// Access: Private
|
||||
// Description: Determines what kind of object needs to be added for
|
||||
// the indicated bin node.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
bool XFileMaker::
|
||||
add_bin(EggBin *egg_bin, LPDIRECTXFILEDATA dx_parent) {
|
||||
switch (egg_bin->get_bin_number()) {
|
||||
case EggPolysetMaker::BN_polyset:
|
||||
return add_polyset(egg_bin, dx_parent);
|
||||
}
|
||||
|
||||
cerr << "Unexpected bin type " << egg_bin->get_bin_number() << "\n";
|
||||
return false;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: XFileMaker::add_polyset
|
||||
// Access: Private
|
||||
// Description: Adds a mesh object corresponding to the collection of
|
||||
// polygons within the indicated bin.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
bool XFileMaker::
|
||||
add_polyset(EggBin *egg_bin, LPDIRECTXFILEDATA dx_parent) {
|
||||
// Make sure that all our polygons are reasonable.
|
||||
egg_bin->remove_invalid_primitives();
|
||||
|
||||
XFileMesh mesh;
|
||||
|
||||
EggGroupNode::iterator ci;
|
||||
for (ci = egg_bin->begin(); ci != egg_bin->end(); ++ci) {
|
||||
EggPolygon *poly;
|
||||
DCAST_INTO_R(poly, *ci, false);
|
||||
|
||||
mesh.add_polygon(poly);
|
||||
}
|
||||
|
||||
// Get a unique number for each mesh.
|
||||
_mesh_index++;
|
||||
string mesh_index = format_string(_mesh_index);
|
||||
|
||||
// Finally, create the Mesh object.
|
||||
Datagram raw_data;
|
||||
mesh.make_mesh_data(raw_data);
|
||||
|
||||
LPDIRECTXFILEDATA xobj;
|
||||
cerr << "Creating mesh\n";
|
||||
if (!create_object(xobj, TID_D3DRMMesh, "mesh" + mesh_index, raw_data)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!attach_and_release(xobj, dx_parent)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: XFileMaker::recurse_nodes
|
||||
// Access: Private
|
||||
// Description: Adds each child of the indicated Node as a child of
|
||||
// the indicated DX object.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
bool XFileMaker::
|
||||
recurse_nodes(EggGroupNode *egg_node, LPDIRECTXFILEDATA dx_parent) {
|
||||
EggGroupNode::iterator ci;
|
||||
for (ci = egg_node->begin(); ci != egg_node->end(); ++ci) {
|
||||
EggNode *node = (*ci);
|
||||
if (!add_node(node, dx_parent)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: XFileMaker::create_object
|
||||
// Access: Private
|
||||
// Description: Creates a DX data object.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
bool XFileMaker::
|
||||
create_object(LPDIRECTXFILEDATA &obj, REFGUID template_id,
|
||||
const string &name, const Datagram &dg) {
|
||||
HRESULT hr;
|
||||
|
||||
string nice_name = make_nice_name(name);
|
||||
|
||||
int data_size = dg.get_length();
|
||||
void *data_pointer = (void *)dg.get_data();
|
||||
|
||||
if (data_size == 0) {
|
||||
data_pointer = (void *)NULL;
|
||||
}
|
||||
|
||||
hr = _dx_file_save->CreateDataObject
|
||||
(template_id, nice_name.c_str(), NULL,
|
||||
data_size, data_pointer, &obj);
|
||||
|
||||
if (hr != DXFILE_OK) {
|
||||
nout << "Unable to create data object for " << name << "\n";
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: XFileMaker::create_frame
|
||||
// Access: Private
|
||||
// Description: Creates a "frame" object with the indicated name.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
bool XFileMaker::
|
||||
create_frame(LPDIRECTXFILEDATA &obj, const string &name) {
|
||||
cerr << "Creating frame\n";
|
||||
return create_object(obj, TID_D3DRMFrame, name, Datagram());
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: XFileMaker::attach_and_release
|
||||
// Access: Private
|
||||
// Description: Assigns the indicated X data object to the indicated
|
||||
// parent, and releases the pointer.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
bool XFileMaker::
|
||||
attach_and_release(LPDIRECTXFILEDATA obj, LPDIRECTXFILEDATA dx_parent) {
|
||||
HRESULT hr;
|
||||
|
||||
if (dx_parent == NULL) {
|
||||
// No parent; it's a toplevel object.
|
||||
hr = _dx_file_save->SaveData(obj);
|
||||
if (hr != DXFILE_OK) {
|
||||
nout << "Unable to save data object\n";
|
||||
obj->Release();
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
// Got a parent; it's a child of the indicated object.
|
||||
hr = dx_parent->AddDataObject(obj);
|
||||
if (hr != DXFILE_OK) {
|
||||
nout << "Unable to save data object\n";
|
||||
obj->Release();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
obj->Release();
|
||||
return true;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: XFileMaker::make_nice_name
|
||||
// Access: Private, Static
|
||||
// Description: Transforms the indicated egg name to a name that is
|
||||
// acceptable to the DirectX format.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
string XFileMaker::
|
||||
make_nice_name(const string &str) {
|
||||
string result;
|
||||
|
||||
string::const_iterator si;
|
||||
for (si = str.begin(); si != str.end(); ++si) {
|
||||
if (isalnum(*si)) {
|
||||
result += *si;
|
||||
} else {
|
||||
result += "_";
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
// Filename: xFileMaker.cxx
|
||||
// Created by: drose (19Jun01)
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// PANDA 3D SOFTWARE
|
||||
// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved
|
||||
//
|
||||
// All use of this software is subject to the terms of the Panda 3d
|
||||
// Software license. You should have received a copy of this license
|
||||
// along with this source code; you will also find a current copy of
|
||||
// the license at http://www.panda3d.org/license.txt .
|
||||
//
|
||||
// To contact the maintainers of this program write to
|
||||
// panda3d@yahoogroups.com .
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "xFileMaker.h"
|
||||
#include "xFileMesh.h"
|
||||
#include "notify.h"
|
||||
#include "eggGroupNode.h"
|
||||
#include "eggGroup.h"
|
||||
#include "eggBin.h"
|
||||
#include "eggPolysetMaker.h"
|
||||
#include "eggVertexPool.h"
|
||||
#include "eggVertex.h"
|
||||
#include "eggPolygon.h"
|
||||
#include "eggData.h"
|
||||
#include "pvector.h"
|
||||
#include "vector_int.h"
|
||||
#include "string_utils.h"
|
||||
#include "datagram.h"
|
||||
|
||||
// This must be included only in exactly one .cxx file, since
|
||||
// including defines the structure!
|
||||
#include <rmxftmpl.h>
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: XFileMaker::Constructor
|
||||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
XFileMaker::
|
||||
XFileMaker() {
|
||||
_dx_file = NULL;
|
||||
_dx_file_save = NULL;
|
||||
_mesh_index = 0;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: XFileMaker::Destructor
|
||||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
XFileMaker::
|
||||
~XFileMaker() {
|
||||
close();
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: XFileMaker::open
|
||||
// Access: Public
|
||||
// Description: Opens the indicated filename for writing, and writes
|
||||
// the .x header information; returns true on success,
|
||||
// false otherwise.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
bool XFileMaker::
|
||||
open(const Filename &filename) {
|
||||
HRESULT hr;
|
||||
|
||||
close();
|
||||
hr = DirectXFileCreate(&_dx_file);
|
||||
if (hr != DXFILE_OK) {
|
||||
nout << "Unable to create X interface.\n";
|
||||
return false;
|
||||
}
|
||||
|
||||
// Register our templates.
|
||||
hr = _dx_file->RegisterTemplates(D3DRM_XTEMPLATES, D3DRM_XTEMPLATE_BYTES);
|
||||
if (hr != DXFILE_OK) {
|
||||
nout << "Unable to register templates.\n";
|
||||
return false;
|
||||
}
|
||||
|
||||
string os_file = filename.to_os_specific();
|
||||
hr = _dx_file->CreateSaveObject(os_file.c_str(), DXFILEFORMAT_TEXT,
|
||||
&_dx_file_save);
|
||||
if (hr != DXFILE_OK) {
|
||||
nout << "Unable to open X file: " << os_file << "\n";
|
||||
return false;
|
||||
}
|
||||
|
||||
// Save the templates we will use.
|
||||
static const GUID *temps[] = {
|
||||
&TID_D3DRMCoords2d,
|
||||
&TID_D3DRMVector,
|
||||
&TID_D3DRMColorRGBA,
|
||||
&TID_D3DRMColorRGB,
|
||||
&TID_D3DRMIndexedColor,
|
||||
&TID_D3DRMTextureFilename,
|
||||
&TID_D3DRMMaterial,
|
||||
&TID_D3DRMMeshFace,
|
||||
&TID_D3DRMMesh,
|
||||
&TID_D3DRMMeshNormals,
|
||||
&TID_D3DRMMeshTextureCoords,
|
||||
&TID_D3DRMMeshMaterialList,
|
||||
&TID_D3DRMFrame,
|
||||
};
|
||||
static const int num_temps = sizeof(temps) / sizeof(temps[0]);
|
||||
hr = _dx_file_save->SaveTemplates(num_temps, temps);
|
||||
if (hr != DXFILE_OK) {
|
||||
nout << "Unable to save templates.\n";
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: XFileMaker::close
|
||||
// Access: Public
|
||||
// Description: Finalizes and closes the file previously opened via
|
||||
// open().
|
||||
////////////////////////////////////////////////////////////////////
|
||||
void XFileMaker::
|
||||
close() {
|
||||
if (_dx_file != NULL) {
|
||||
if (_dx_file_save != NULL) {
|
||||
_dx_file_save->Release();
|
||||
_dx_file_save = NULL;
|
||||
}
|
||||
_dx_file->Release();
|
||||
_dx_file = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: XFileMaker::add_tree
|
||||
// Access: Public
|
||||
// Description: Adds the egg tree rooted at the indicated node to the
|
||||
// DX structure. This may be somewhat destructive of
|
||||
// the egg tree. Returns true on success, false on
|
||||
// failure.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
bool XFileMaker::
|
||||
add_tree(EggData &egg_data) {
|
||||
// Now collect all the polygons together into polysets.
|
||||
EggPolysetMaker pmaker;
|
||||
int num_bins = pmaker.make_bins(&egg_data);
|
||||
|
||||
// And now we're ready to traverse the egg hierarchy.
|
||||
return add_node(&egg_data, NULL);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: XFileMaker::add_node
|
||||
// Access: Private
|
||||
// Description: Adds the node to the DX structure, in whatever form
|
||||
// it is supported.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
bool XFileMaker::
|
||||
add_node(EggNode *egg_node, LPDIRECTXFILEDATA dx_parent) {
|
||||
if (egg_node->is_of_type(EggBin::get_class_type())) {
|
||||
return add_bin(DCAST(EggBin, egg_node), dx_parent);
|
||||
|
||||
} else if (egg_node->is_of_type(EggGroup::get_class_type())) {
|
||||
return add_group(DCAST(EggGroup, egg_node), dx_parent);
|
||||
|
||||
} else if (egg_node->is_of_type(EggGroupNode::get_class_type())) {
|
||||
// A grouping node of some kind.
|
||||
EggGroupNode *egg_group = DCAST(EggGroupNode, egg_node);
|
||||
LPDIRECTXFILEDATA obj;
|
||||
if (!create_frame(obj, egg_group->get_name())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!recurse_nodes(egg_group, obj)) {
|
||||
obj->Release();
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!attach_and_release(obj, dx_parent)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// Some unsupported node type. Ignore it.
|
||||
return true;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: XFileMaker::add_group
|
||||
// Access: Private
|
||||
// Description: Adds a frame for the indicated group node.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
bool XFileMaker::
|
||||
add_group(EggGroup *egg_group, LPDIRECTXFILEDATA dx_parent) {
|
||||
LPDIRECTXFILEDATA obj;
|
||||
if (!create_frame(obj, egg_group->get_name())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!recurse_nodes(egg_group, obj)) {
|
||||
obj->Release();
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!attach_and_release(obj, dx_parent)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: XFileMaker::add_bin
|
||||
// Access: Private
|
||||
// Description: Determines what kind of object needs to be added for
|
||||
// the indicated bin node.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
bool XFileMaker::
|
||||
add_bin(EggBin *egg_bin, LPDIRECTXFILEDATA dx_parent) {
|
||||
switch (egg_bin->get_bin_number()) {
|
||||
case EggPolysetMaker::BN_polyset:
|
||||
return add_polyset(egg_bin, dx_parent);
|
||||
}
|
||||
|
||||
cerr << "Unexpected bin type " << egg_bin->get_bin_number() << "\n";
|
||||
return false;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: XFileMaker::add_polyset
|
||||
// Access: Private
|
||||
// Description: Adds a mesh object corresponding to the collection of
|
||||
// polygons within the indicated bin.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
bool XFileMaker::
|
||||
add_polyset(EggBin *egg_bin, LPDIRECTXFILEDATA dx_parent) {
|
||||
// Make sure that all our polygons are reasonable.
|
||||
egg_bin->remove_invalid_primitives();
|
||||
|
||||
XFileMesh mesh;
|
||||
|
||||
EggGroupNode::iterator ci;
|
||||
for (ci = egg_bin->begin(); ci != egg_bin->end(); ++ci) {
|
||||
EggPolygon *poly;
|
||||
DCAST_INTO_R(poly, *ci, false);
|
||||
|
||||
mesh.add_polygon(poly);
|
||||
}
|
||||
|
||||
// Get a unique number for each mesh.
|
||||
_mesh_index++;
|
||||
string mesh_index = format_string(_mesh_index);
|
||||
|
||||
// Finally, create the Mesh object.
|
||||
Datagram raw_data;
|
||||
mesh.make_mesh_data(raw_data);
|
||||
|
||||
LPDIRECTXFILEDATA xobj;
|
||||
cerr << "Creating mesh\n";
|
||||
if (!create_object(xobj, TID_D3DRMMesh, "mesh" + mesh_index, raw_data)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!attach_and_release(xobj, dx_parent)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: XFileMaker::recurse_nodes
|
||||
// Access: Private
|
||||
// Description: Adds each child of the indicated Node as a child of
|
||||
// the indicated DX object.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
bool XFileMaker::
|
||||
recurse_nodes(EggGroupNode *egg_node, LPDIRECTXFILEDATA dx_parent) {
|
||||
EggGroupNode::iterator ci;
|
||||
for (ci = egg_node->begin(); ci != egg_node->end(); ++ci) {
|
||||
EggNode *node = (*ci);
|
||||
if (!add_node(node, dx_parent)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: XFileMaker::create_object
|
||||
// Access: Private
|
||||
// Description: Creates a DX data object.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
bool XFileMaker::
|
||||
create_object(LPDIRECTXFILEDATA &obj, REFGUID template_id,
|
||||
const string &name, const Datagram &dg) {
|
||||
HRESULT hr;
|
||||
|
||||
string nice_name = make_nice_name(name);
|
||||
|
||||
int data_size = dg.get_length();
|
||||
void *data_pointer = (void *)dg.get_data();
|
||||
|
||||
if (data_size == 0) {
|
||||
data_pointer = (void *)NULL;
|
||||
}
|
||||
|
||||
hr = _dx_file_save->CreateDataObject
|
||||
(template_id, nice_name.c_str(), NULL,
|
||||
data_size, data_pointer, &obj);
|
||||
|
||||
if (hr != DXFILE_OK) {
|
||||
nout << "Unable to create data object for " << name << "\n";
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: XFileMaker::create_frame
|
||||
// Access: Private
|
||||
// Description: Creates a "frame" object with the indicated name.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
bool XFileMaker::
|
||||
create_frame(LPDIRECTXFILEDATA &obj, const string &name) {
|
||||
cerr << "Creating frame\n";
|
||||
return create_object(obj, TID_D3DRMFrame, name, Datagram());
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: XFileMaker::attach_and_release
|
||||
// Access: Private
|
||||
// Description: Assigns the indicated X data object to the indicated
|
||||
// parent, and releases the pointer.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
bool XFileMaker::
|
||||
attach_and_release(LPDIRECTXFILEDATA obj, LPDIRECTXFILEDATA dx_parent) {
|
||||
HRESULT hr;
|
||||
|
||||
if (dx_parent == NULL) {
|
||||
// No parent; it's a toplevel object.
|
||||
hr = _dx_file_save->SaveData(obj);
|
||||
if (hr != DXFILE_OK) {
|
||||
nout << "Unable to save data object\n";
|
||||
obj->Release();
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
// Got a parent; it's a child of the indicated object.
|
||||
hr = dx_parent->AddDataObject(obj);
|
||||
if (hr != DXFILE_OK) {
|
||||
nout << "Unable to save data object\n";
|
||||
obj->Release();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
obj->Release();
|
||||
return true;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: XFileMaker::make_nice_name
|
||||
// Access: Private, Static
|
||||
// Description: Transforms the indicated egg name to a name that is
|
||||
// acceptable to the DirectX format.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
string XFileMaker::
|
||||
make_nice_name(const string &str) {
|
||||
string result;
|
||||
|
||||
string::const_iterator si;
|
||||
for (si = str.begin(); si != str.end(); ++si) {
|
||||
if (isalnum(*si)) {
|
||||
result += *si;
|
||||
} else {
|
||||
result += "_";
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
@ -1,78 +1,78 @@
|
||||
// Filename: xFileMaker.h
|
||||
// Created by: drose (19Jun01)
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// PANDA 3D SOFTWARE
|
||||
// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved
|
||||
//
|
||||
// All use of this software is subject to the terms of the Panda 3d
|
||||
// Software license. You should have received a copy of this license
|
||||
// along with this source code; you will also find a current copy of
|
||||
// the license at http://www.panda3d.org/license.txt .
|
||||
//
|
||||
// To contact the maintainers of this program write to
|
||||
// panda3d@yahoogroups.com .
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef XFILEMAKER_H
|
||||
#define XFILEMAKER_H
|
||||
|
||||
#include <pandatoolbase.h>
|
||||
|
||||
#include <filename.h>
|
||||
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#include <windows.h>
|
||||
#include <d3d.h>
|
||||
#include <dxfile.h>
|
||||
#include <rmxfguid.h>
|
||||
#undef WIN32_LEAN_AND_MEAN
|
||||
|
||||
class EggNode;
|
||||
class EggGroupNode;
|
||||
class EggGroup;
|
||||
class EggBin;
|
||||
class EggData;
|
||||
class EggVertexPool;
|
||||
class Datagram;
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Class : XFileMaker
|
||||
// Description : This class converts a Panda scene graph into a .X
|
||||
// file and writes it out.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
class XFileMaker {
|
||||
public:
|
||||
XFileMaker();
|
||||
~XFileMaker();
|
||||
|
||||
bool open(const Filename &filename);
|
||||
void close();
|
||||
|
||||
bool add_tree(EggData &egg_data);
|
||||
|
||||
private:
|
||||
bool add_node(EggNode *egg_node, LPDIRECTXFILEDATA dx_parent);
|
||||
bool add_group(EggGroup *egg_group, LPDIRECTXFILEDATA dx_parent);
|
||||
bool add_bin(EggBin *egg_bin, LPDIRECTXFILEDATA dx_parent);
|
||||
bool add_polyset(EggBin *egg_bin, LPDIRECTXFILEDATA dx_parent);
|
||||
|
||||
bool recurse_nodes(EggGroupNode *egg_node, LPDIRECTXFILEDATA dx_parent);
|
||||
|
||||
bool create_object(LPDIRECTXFILEDATA &obj, REFGUID template_id,
|
||||
const string &name, const Datagram &dg);
|
||||
bool create_frame(LPDIRECTXFILEDATA &obj, const string &name);
|
||||
bool attach_and_release(LPDIRECTXFILEDATA obj, LPDIRECTXFILEDATA dx_parent);
|
||||
|
||||
static string make_nice_name(const string &str);
|
||||
|
||||
LPDIRECTXFILE _dx_file;
|
||||
LPDIRECTXFILESAVEOBJECT _dx_file_save;
|
||||
|
||||
int _mesh_index;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
// Filename: xFileMaker.h
|
||||
// Created by: drose (19Jun01)
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// PANDA 3D SOFTWARE
|
||||
// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved
|
||||
//
|
||||
// All use of this software is subject to the terms of the Panda 3d
|
||||
// Software license. You should have received a copy of this license
|
||||
// along with this source code; you will also find a current copy of
|
||||
// the license at http://www.panda3d.org/license.txt .
|
||||
//
|
||||
// To contact the maintainers of this program write to
|
||||
// panda3d@yahoogroups.com .
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef XFILEMAKER_H
|
||||
#define XFILEMAKER_H
|
||||
|
||||
#include <pandatoolbase.h>
|
||||
|
||||
#include <filename.h>
|
||||
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#include <windows.h>
|
||||
#include <d3d.h>
|
||||
#include <dxfile.h>
|
||||
#include <rmxfguid.h>
|
||||
#undef WIN32_LEAN_AND_MEAN
|
||||
|
||||
class EggNode;
|
||||
class EggGroupNode;
|
||||
class EggGroup;
|
||||
class EggBin;
|
||||
class EggData;
|
||||
class EggVertexPool;
|
||||
class Datagram;
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Class : XFileMaker
|
||||
// Description : This class converts a Panda scene graph into a .X
|
||||
// file and writes it out.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
class XFileMaker {
|
||||
public:
|
||||
XFileMaker();
|
||||
~XFileMaker();
|
||||
|
||||
bool open(const Filename &filename);
|
||||
void close();
|
||||
|
||||
bool add_tree(EggData &egg_data);
|
||||
|
||||
private:
|
||||
bool add_node(EggNode *egg_node, LPDIRECTXFILEDATA dx_parent);
|
||||
bool add_group(EggGroup *egg_group, LPDIRECTXFILEDATA dx_parent);
|
||||
bool add_bin(EggBin *egg_bin, LPDIRECTXFILEDATA dx_parent);
|
||||
bool add_polyset(EggBin *egg_bin, LPDIRECTXFILEDATA dx_parent);
|
||||
|
||||
bool recurse_nodes(EggGroupNode *egg_node, LPDIRECTXFILEDATA dx_parent);
|
||||
|
||||
bool create_object(LPDIRECTXFILEDATA &obj, REFGUID template_id,
|
||||
const string &name, const Datagram &dg);
|
||||
bool create_frame(LPDIRECTXFILEDATA &obj, const string &name);
|
||||
bool attach_and_release(LPDIRECTXFILEDATA obj, LPDIRECTXFILEDATA dx_parent);
|
||||
|
||||
static string make_nice_name(const string &str);
|
||||
|
||||
LPDIRECTXFILE _dx_file;
|
||||
LPDIRECTXFILESAVEOBJECT _dx_file_save;
|
||||
|
||||
int _mesh_index;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
|
@ -1,139 +1,139 @@
|
||||
// Filename: xFileMesh.cxx
|
||||
// Created by: drose (19Jun01)
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// PANDA 3D SOFTWARE
|
||||
// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved
|
||||
//
|
||||
// All use of this software is subject to the terms of the Panda 3d
|
||||
// Software license. You should have received a copy of this license
|
||||
// along with this source code; you will also find a current copy of
|
||||
// the license at http://www.panda3d.org/license.txt .
|
||||
//
|
||||
// To contact the maintainers of this program write to
|
||||
// panda3d@yahoogroups.com .
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "xFileMesh.h"
|
||||
#include "xFileFace.h"
|
||||
#include "xFileVertex.h"
|
||||
#include "xFileNormal.h"
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: XFileMesh::Constructor
|
||||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
XFileMesh::
|
||||
XFileMesh() {
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: XFileMesh::Destructor
|
||||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
XFileMesh::
|
||||
~XFileMesh() {
|
||||
// ** Delete stuff.
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: XFileMesh::add_polygon
|
||||
// Access: Public
|
||||
// Description: Adds the indicated polygon to the mesh.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
void XFileMesh::
|
||||
add_polygon(EggPolygon *egg_poly) {
|
||||
XFileFace *face = new XFileFace(this, egg_poly);
|
||||
_faces.push_back(face);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: XFileMesh::add_vertex
|
||||
// Access: Public
|
||||
// Description: Creates a new XFileVertex, if one does not already
|
||||
// exist for the indicated vertex, and returns its
|
||||
// index.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
int XFileMesh::
|
||||
add_vertex(EggVertex *egg_vertex, EggPrimitive *egg_prim) {
|
||||
int next_index = _vertices.size();
|
||||
XFileVertex *vertex = new XFileVertex(egg_vertex, egg_prim);
|
||||
pair<UniqueVertices::iterator, bool> result =
|
||||
_unique_vertices.insert(UniqueVertices::value_type(vertex, next_index));
|
||||
|
||||
if (result.second) {
|
||||
// Successfully added; this is a new vertex.
|
||||
_vertices.push_back(vertex);
|
||||
return next_index;
|
||||
} else {
|
||||
// Not successfully added; there is already a vertex with these
|
||||
// properties. Return that one instead.
|
||||
delete vertex;
|
||||
return (*result.first).second;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: XFileMesh::add_normal
|
||||
// Access: Public
|
||||
// Description: Creates a new XFileNormal, if one does not already
|
||||
// exist for the indicated normal, and returns its
|
||||
// index.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
int XFileMesh::
|
||||
add_normal(EggVertex *egg_vertex, EggPrimitive *egg_prim) {
|
||||
int next_index = _normals.size();
|
||||
XFileNormal *normal = new XFileNormal(egg_vertex, egg_prim);
|
||||
pair<UniqueNormals::iterator, bool> result =
|
||||
_unique_normals.insert(UniqueNormals::value_type(normal, next_index));
|
||||
|
||||
if (result.second) {
|
||||
// Successfully added; this is a new normal.
|
||||
_normals.push_back(normal);
|
||||
return next_index;
|
||||
} else {
|
||||
// Not successfully added; there is already a normal with these
|
||||
// properties. Return that one instead.
|
||||
delete normal;
|
||||
return (*result.first).second;
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: XFileMesh::make_mesh_data
|
||||
// Access: Public
|
||||
// Description: Fills the datagram with the raw data for the DX
|
||||
// Mesh template.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
void XFileMesh::
|
||||
make_mesh_data(Datagram &raw_data) {
|
||||
raw_data.add_int32(_vertices.size());
|
||||
|
||||
Vertices::const_iterator vi;
|
||||
for (vi = _vertices.begin(); vi != _vertices.end(); ++vi) {
|
||||
XFileVertex *vertex = (*vi);
|
||||
const Vertexf &point = vertex->_point;
|
||||
raw_data.add_float32(point[0]);
|
||||
raw_data.add_float32(point[1]);
|
||||
raw_data.add_float32(point[2]);
|
||||
}
|
||||
|
||||
raw_data.add_int32(_faces.size());
|
||||
Faces::const_iterator fi;
|
||||
for (fi = _faces.begin(); fi != _faces.end(); ++fi) {
|
||||
XFileFace *face = (*fi);
|
||||
|
||||
raw_data.add_int32(face->_vertices.size());
|
||||
XFileFace::Vertices::const_iterator fvi;
|
||||
for (fvi = face->_vertices.begin();
|
||||
fvi != face->_vertices.end();
|
||||
++fvi) {
|
||||
raw_data.add_int32((*fvi)._vertex_index);
|
||||
}
|
||||
}
|
||||
}
|
||||
// Filename: xFileMesh.cxx
|
||||
// Created by: drose (19Jun01)
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// PANDA 3D SOFTWARE
|
||||
// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved
|
||||
//
|
||||
// All use of this software is subject to the terms of the Panda 3d
|
||||
// Software license. You should have received a copy of this license
|
||||
// along with this source code; you will also find a current copy of
|
||||
// the license at http://www.panda3d.org/license.txt .
|
||||
//
|
||||
// To contact the maintainers of this program write to
|
||||
// panda3d@yahoogroups.com .
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "xFileMesh.h"
|
||||
#include "xFileFace.h"
|
||||
#include "xFileVertex.h"
|
||||
#include "xFileNormal.h"
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: XFileMesh::Constructor
|
||||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
XFileMesh::
|
||||
XFileMesh() {
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: XFileMesh::Destructor
|
||||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
XFileMesh::
|
||||
~XFileMesh() {
|
||||
// ** Delete stuff.
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: XFileMesh::add_polygon
|
||||
// Access: Public
|
||||
// Description: Adds the indicated polygon to the mesh.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
void XFileMesh::
|
||||
add_polygon(EggPolygon *egg_poly) {
|
||||
XFileFace *face = new XFileFace(this, egg_poly);
|
||||
_faces.push_back(face);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: XFileMesh::add_vertex
|
||||
// Access: Public
|
||||
// Description: Creates a new XFileVertex, if one does not already
|
||||
// exist for the indicated vertex, and returns its
|
||||
// index.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
int XFileMesh::
|
||||
add_vertex(EggVertex *egg_vertex, EggPrimitive *egg_prim) {
|
||||
int next_index = _vertices.size();
|
||||
XFileVertex *vertex = new XFileVertex(egg_vertex, egg_prim);
|
||||
pair<UniqueVertices::iterator, bool> result =
|
||||
_unique_vertices.insert(UniqueVertices::value_type(vertex, next_index));
|
||||
|
||||
if (result.second) {
|
||||
// Successfully added; this is a new vertex.
|
||||
_vertices.push_back(vertex);
|
||||
return next_index;
|
||||
} else {
|
||||
// Not successfully added; there is already a vertex with these
|
||||
// properties. Return that one instead.
|
||||
delete vertex;
|
||||
return (*result.first).second;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: XFileMesh::add_normal
|
||||
// Access: Public
|
||||
// Description: Creates a new XFileNormal, if one does not already
|
||||
// exist for the indicated normal, and returns its
|
||||
// index.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
int XFileMesh::
|
||||
add_normal(EggVertex *egg_vertex, EggPrimitive *egg_prim) {
|
||||
int next_index = _normals.size();
|
||||
XFileNormal *normal = new XFileNormal(egg_vertex, egg_prim);
|
||||
pair<UniqueNormals::iterator, bool> result =
|
||||
_unique_normals.insert(UniqueNormals::value_type(normal, next_index));
|
||||
|
||||
if (result.second) {
|
||||
// Successfully added; this is a new normal.
|
||||
_normals.push_back(normal);
|
||||
return next_index;
|
||||
} else {
|
||||
// Not successfully added; there is already a normal with these
|
||||
// properties. Return that one instead.
|
||||
delete normal;
|
||||
return (*result.first).second;
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: XFileMesh::make_mesh_data
|
||||
// Access: Public
|
||||
// Description: Fills the datagram with the raw data for the DX
|
||||
// Mesh template.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
void XFileMesh::
|
||||
make_mesh_data(Datagram &raw_data) {
|
||||
raw_data.add_int32(_vertices.size());
|
||||
|
||||
Vertices::const_iterator vi;
|
||||
for (vi = _vertices.begin(); vi != _vertices.end(); ++vi) {
|
||||
XFileVertex *vertex = (*vi);
|
||||
const Vertexf &point = vertex->_point;
|
||||
raw_data.add_float32(point[0]);
|
||||
raw_data.add_float32(point[1]);
|
||||
raw_data.add_float32(point[2]);
|
||||
}
|
||||
|
||||
raw_data.add_int32(_faces.size());
|
||||
Faces::const_iterator fi;
|
||||
for (fi = _faces.begin(); fi != _faces.end(); ++fi) {
|
||||
XFileFace *face = (*fi);
|
||||
|
||||
raw_data.add_int32(face->_vertices.size());
|
||||
XFileFace::Vertices::const_iterator fvi;
|
||||
for (fvi = face->_vertices.begin();
|
||||
fvi != face->_vertices.end();
|
||||
++fvi) {
|
||||
raw_data.add_int32((*fvi)._vertex_index);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,68 +1,68 @@
|
||||
// Filename: xFileMesh.h
|
||||
// Created by: drose (19Jun01)
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// PANDA 3D SOFTWARE
|
||||
// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved
|
||||
//
|
||||
// All use of this software is subject to the terms of the Panda 3d
|
||||
// Software license. You should have received a copy of this license
|
||||
// along with this source code; you will also find a current copy of
|
||||
// the license at http://www.panda3d.org/license.txt .
|
||||
//
|
||||
// To contact the maintainers of this program write to
|
||||
// panda3d@yahoogroups.com .
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef XFILEMESH_H
|
||||
#define XFILEMESH_H
|
||||
|
||||
#include "pandatoolbase.h"
|
||||
#include "pvector.h"
|
||||
#include "pmap.h"
|
||||
#include "indirectCompareTo.h"
|
||||
|
||||
class XFileMesh;
|
||||
class XFileVertex;
|
||||
class XFileNormal;
|
||||
class XFileFace;
|
||||
class EggVertex;
|
||||
class EggPolygon;
|
||||
class EggPrimitive;
|
||||
class Datagram;
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Class : XFileMesh
|
||||
// Description : This is a collection of polygons; i.e. a polyset.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
class XFileMesh {
|
||||
public:
|
||||
XFileMesh();
|
||||
~XFileMesh();
|
||||
|
||||
void add_polygon(EggPolygon *egg_poly);
|
||||
int add_vertex(EggVertex *egg_vertex, EggPrimitive *egg_prim);
|
||||
int add_normal(EggVertex *egg_vertex, EggPrimitive *egg_prim);
|
||||
|
||||
void make_mesh_data(Datagram &raw_data);
|
||||
|
||||
public:
|
||||
typedef pvector<XFileVertex *> Vertices;
|
||||
typedef pvector<XFileNormal *> Normals;
|
||||
typedef pvector<XFileFace *> Faces;
|
||||
|
||||
Vertices _vertices;
|
||||
Normals _normals;
|
||||
Faces _faces;
|
||||
|
||||
private:
|
||||
typedef pmap<XFileVertex *, int, IndirectCompareTo<XFileVertex> > UniqueVertices;
|
||||
typedef pmap<XFileNormal *, int, IndirectCompareTo<XFileNormal> > UniqueNormals;
|
||||
UniqueVertices _unique_vertices;
|
||||
UniqueNormals _unique_normals;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
// Filename: xFileMesh.h
|
||||
// Created by: drose (19Jun01)
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// PANDA 3D SOFTWARE
|
||||
// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved
|
||||
//
|
||||
// All use of this software is subject to the terms of the Panda 3d
|
||||
// Software license. You should have received a copy of this license
|
||||
// along with this source code; you will also find a current copy of
|
||||
// the license at http://www.panda3d.org/license.txt .
|
||||
//
|
||||
// To contact the maintainers of this program write to
|
||||
// panda3d@yahoogroups.com .
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef XFILEMESH_H
|
||||
#define XFILEMESH_H
|
||||
|
||||
#include "pandatoolbase.h"
|
||||
#include "pvector.h"
|
||||
#include "pmap.h"
|
||||
#include "indirectCompareTo.h"
|
||||
|
||||
class XFileMesh;
|
||||
class XFileVertex;
|
||||
class XFileNormal;
|
||||
class XFileFace;
|
||||
class EggVertex;
|
||||
class EggPolygon;
|
||||
class EggPrimitive;
|
||||
class Datagram;
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Class : XFileMesh
|
||||
// Description : This is a collection of polygons; i.e. a polyset.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
class XFileMesh {
|
||||
public:
|
||||
XFileMesh();
|
||||
~XFileMesh();
|
||||
|
||||
void add_polygon(EggPolygon *egg_poly);
|
||||
int add_vertex(EggVertex *egg_vertex, EggPrimitive *egg_prim);
|
||||
int add_normal(EggVertex *egg_vertex, EggPrimitive *egg_prim);
|
||||
|
||||
void make_mesh_data(Datagram &raw_data);
|
||||
|
||||
public:
|
||||
typedef pvector<XFileVertex *> Vertices;
|
||||
typedef pvector<XFileNormal *> Normals;
|
||||
typedef pvector<XFileFace *> Faces;
|
||||
|
||||
Vertices _vertices;
|
||||
Normals _normals;
|
||||
Faces _faces;
|
||||
|
||||
private:
|
||||
typedef pmap<XFileVertex *, int, IndirectCompareTo<XFileVertex> > UniqueVertices;
|
||||
typedef pmap<XFileNormal *, int, IndirectCompareTo<XFileNormal> > UniqueNormals;
|
||||
UniqueVertices _unique_vertices;
|
||||
UniqueNormals _unique_normals;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
|
@ -1,49 +1,49 @@
|
||||
// Filename: xFileNormal.cxx
|
||||
// Created by: drose (19Jun01)
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// PANDA 3D SOFTWARE
|
||||
// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved
|
||||
//
|
||||
// All use of this software is subject to the terms of the Panda 3d
|
||||
// Software license. You should have received a copy of this license
|
||||
// along with this source code; you will also find a current copy of
|
||||
// the license at http://www.panda3d.org/license.txt .
|
||||
//
|
||||
// To contact the maintainers of this program write to
|
||||
// panda3d@yahoogroups.com .
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "xFileNormal.h"
|
||||
#include "eggVertex.h"
|
||||
#include "eggPrimitive.h"
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: XFileNormal::Constructor
|
||||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
XFileNormal::
|
||||
XFileNormal(EggVertex *egg_vertex, EggPrimitive *egg_prim) {
|
||||
if (egg_vertex->has_normal()) {
|
||||
_normal = LCAST(float, egg_vertex->get_normal());
|
||||
} else if (egg_prim->has_normal()) {
|
||||
_normal = LCAST(float, egg_prim->get_normal());
|
||||
} else {
|
||||
_normal.set(0.0, 0.0, 0.0);
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: XFileNormal::compare_to
|
||||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
int XFileNormal::
|
||||
compare_to(const XFileNormal &other) const {
|
||||
int ct;
|
||||
ct = _normal.compare_to(other._normal);
|
||||
return ct;
|
||||
}
|
||||
// Filename: xFileNormal.cxx
|
||||
// Created by: drose (19Jun01)
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// PANDA 3D SOFTWARE
|
||||
// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved
|
||||
//
|
||||
// All use of this software is subject to the terms of the Panda 3d
|
||||
// Software license. You should have received a copy of this license
|
||||
// along with this source code; you will also find a current copy of
|
||||
// the license at http://www.panda3d.org/license.txt .
|
||||
//
|
||||
// To contact the maintainers of this program write to
|
||||
// panda3d@yahoogroups.com .
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "xFileNormal.h"
|
||||
#include "eggVertex.h"
|
||||
#include "eggPrimitive.h"
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: XFileNormal::Constructor
|
||||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
XFileNormal::
|
||||
XFileNormal(EggVertex *egg_vertex, EggPrimitive *egg_prim) {
|
||||
if (egg_vertex->has_normal()) {
|
||||
_normal = LCAST(float, egg_vertex->get_normal());
|
||||
} else if (egg_prim->has_normal()) {
|
||||
_normal = LCAST(float, egg_prim->get_normal());
|
||||
} else {
|
||||
_normal.set(0.0, 0.0, 0.0);
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: XFileNormal::compare_to
|
||||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
int XFileNormal::
|
||||
compare_to(const XFileNormal &other) const {
|
||||
int ct;
|
||||
ct = _normal.compare_to(other._normal);
|
||||
return ct;
|
||||
}
|
||||
|
@ -1,44 +1,44 @@
|
||||
// Filename: xFileNormal.h
|
||||
// Created by: drose (19Jun01)
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// PANDA 3D SOFTWARE
|
||||
// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved
|
||||
//
|
||||
// All use of this software is subject to the terms of the Panda 3d
|
||||
// Software license. You should have received a copy of this license
|
||||
// along with this source code; you will also find a current copy of
|
||||
// the license at http://www.panda3d.org/license.txt .
|
||||
//
|
||||
// To contact the maintainers of this program write to
|
||||
// panda3d@yahoogroups.com .
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef XFILENORMAL_H
|
||||
#define XFILENORMAL_H
|
||||
|
||||
#include "pandatoolbase.h"
|
||||
#include "luse.h"
|
||||
|
||||
class EggVertex;
|
||||
class EggPrimitive;
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Class : XFileNormal
|
||||
// Description : This represents a single normal associated with an
|
||||
// XFileFace. It is separate from XFileVertex, because
|
||||
// the X syntax supports a different table of normals
|
||||
// than that of vertices.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
class XFileNormal {
|
||||
public:
|
||||
XFileNormal(EggVertex *egg_vertex, EggPrimitive *egg_prim);
|
||||
int compare_to(const XFileNormal &other) const;
|
||||
|
||||
Normalf _normal;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
// Filename: xFileNormal.h
|
||||
// Created by: drose (19Jun01)
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// PANDA 3D SOFTWARE
|
||||
// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved
|
||||
//
|
||||
// All use of this software is subject to the terms of the Panda 3d
|
||||
// Software license. You should have received a copy of this license
|
||||
// along with this source code; you will also find a current copy of
|
||||
// the license at http://www.panda3d.org/license.txt .
|
||||
//
|
||||
// To contact the maintainers of this program write to
|
||||
// panda3d@yahoogroups.com .
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef XFILENORMAL_H
|
||||
#define XFILENORMAL_H
|
||||
|
||||
#include "pandatoolbase.h"
|
||||
#include "luse.h"
|
||||
|
||||
class EggVertex;
|
||||
class EggPrimitive;
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Class : XFileNormal
|
||||
// Description : This represents a single normal associated with an
|
||||
// XFileFace. It is separate from XFileVertex, because
|
||||
// the X syntax supports a different table of normals
|
||||
// than that of vertices.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
class XFileNormal {
|
||||
public:
|
||||
XFileNormal(EggVertex *egg_vertex, EggPrimitive *egg_prim);
|
||||
int compare_to(const XFileNormal &other) const;
|
||||
|
||||
Normalf _normal;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
|
@ -1,63 +1,63 @@
|
||||
// Filename: xFileVertex.cxx
|
||||
// Created by: drose (19Jun01)
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// PANDA 3D SOFTWARE
|
||||
// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved
|
||||
//
|
||||
// All use of this software is subject to the terms of the Panda 3d
|
||||
// Software license. You should have received a copy of this license
|
||||
// along with this source code; you will also find a current copy of
|
||||
// the license at http://www.panda3d.org/license.txt .
|
||||
//
|
||||
// To contact the maintainers of this program write to
|
||||
// panda3d@yahoogroups.com .
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "xFileVertex.h"
|
||||
#include "eggVertex.h"
|
||||
#include "eggPrimitive.h"
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: XFileVertex::Constructor
|
||||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
XFileVertex::
|
||||
XFileVertex(EggVertex *egg_vertex, EggPrimitive *egg_prim) {
|
||||
_point = LCAST(float, egg_vertex->get_pos3());
|
||||
|
||||
if (egg_vertex->has_uv()) {
|
||||
_uv = LCAST(float, egg_vertex->get_uv());
|
||||
} else {
|
||||
_uv.set(0.0, 0.0);
|
||||
}
|
||||
|
||||
if (egg_vertex->has_color()) {
|
||||
_color = egg_vertex->get_color();
|
||||
} else if (egg_prim->has_color()) {
|
||||
_color = egg_prim->get_color();
|
||||
} else {
|
||||
_color.set(1.0, 1.0, 1.0, 1.0);
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: XFileVertex::compare_to
|
||||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
int XFileVertex::
|
||||
compare_to(const XFileVertex &other) const {
|
||||
int ct;
|
||||
ct = _point.compare_to(other._point);
|
||||
if (ct == 0) {
|
||||
ct = _uv.compare_to(other._uv);
|
||||
}
|
||||
if (ct == 0) {
|
||||
ct = _color.compare_to(other._color);
|
||||
}
|
||||
return ct;
|
||||
}
|
||||
// Filename: xFileVertex.cxx
|
||||
// Created by: drose (19Jun01)
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// PANDA 3D SOFTWARE
|
||||
// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved
|
||||
//
|
||||
// All use of this software is subject to the terms of the Panda 3d
|
||||
// Software license. You should have received a copy of this license
|
||||
// along with this source code; you will also find a current copy of
|
||||
// the license at http://www.panda3d.org/license.txt .
|
||||
//
|
||||
// To contact the maintainers of this program write to
|
||||
// panda3d@yahoogroups.com .
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "xFileVertex.h"
|
||||
#include "eggVertex.h"
|
||||
#include "eggPrimitive.h"
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: XFileVertex::Constructor
|
||||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
XFileVertex::
|
||||
XFileVertex(EggVertex *egg_vertex, EggPrimitive *egg_prim) {
|
||||
_point = LCAST(float, egg_vertex->get_pos3());
|
||||
|
||||
if (egg_vertex->has_uv()) {
|
||||
_uv = LCAST(float, egg_vertex->get_uv());
|
||||
} else {
|
||||
_uv.set(0.0, 0.0);
|
||||
}
|
||||
|
||||
if (egg_vertex->has_color()) {
|
||||
_color = egg_vertex->get_color();
|
||||
} else if (egg_prim->has_color()) {
|
||||
_color = egg_prim->get_color();
|
||||
} else {
|
||||
_color.set(1.0, 1.0, 1.0, 1.0);
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: XFileVertex::compare_to
|
||||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
int XFileVertex::
|
||||
compare_to(const XFileVertex &other) const {
|
||||
int ct;
|
||||
ct = _point.compare_to(other._point);
|
||||
if (ct == 0) {
|
||||
ct = _uv.compare_to(other._uv);
|
||||
}
|
||||
if (ct == 0) {
|
||||
ct = _color.compare_to(other._color);
|
||||
}
|
||||
return ct;
|
||||
}
|
||||
|
@ -1,44 +1,44 @@
|
||||
// Filename: xFileVertex.h
|
||||
// Created by: drose (19Jun01)
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// PANDA 3D SOFTWARE
|
||||
// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved
|
||||
//
|
||||
// All use of this software is subject to the terms of the Panda 3d
|
||||
// Software license. You should have received a copy of this license
|
||||
// along with this source code; you will also find a current copy of
|
||||
// the license at http://www.panda3d.org/license.txt .
|
||||
//
|
||||
// To contact the maintainers of this program write to
|
||||
// panda3d@yahoogroups.com .
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef XFILEVERTEX_H
|
||||
#define XFILEVERTEX_H
|
||||
|
||||
#include "pandatoolbase.h"
|
||||
#include "luse.h"
|
||||
|
||||
class EggVertex;
|
||||
class EggPrimitive;
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Class : XFileVertex
|
||||
// Description : This represents a single vertex associated with an
|
||||
// XFileFace.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
class XFileVertex {
|
||||
public:
|
||||
XFileVertex(EggVertex *egg_vertex, EggPrimitive *egg_poly);
|
||||
int compare_to(const XFileVertex &other) const;
|
||||
|
||||
Vertexf _point;
|
||||
TexCoordf _uv;
|
||||
Colorf _color;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
// Filename: xFileVertex.h
|
||||
// Created by: drose (19Jun01)
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// PANDA 3D SOFTWARE
|
||||
// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved
|
||||
//
|
||||
// All use of this software is subject to the terms of the Panda 3d
|
||||
// Software license. You should have received a copy of this license
|
||||
// along with this source code; you will also find a current copy of
|
||||
// the license at http://www.panda3d.org/license.txt .
|
||||
//
|
||||
// To contact the maintainers of this program write to
|
||||
// panda3d@yahoogroups.com .
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef XFILEVERTEX_H
|
||||
#define XFILEVERTEX_H
|
||||
|
||||
#include "pandatoolbase.h"
|
||||
#include "luse.h"
|
||||
|
||||
class EggVertex;
|
||||
class EggPrimitive;
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Class : XFileVertex
|
||||
// Description : This represents a single vertex associated with an
|
||||
// XFileFace.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
class XFileVertex {
|
||||
public:
|
||||
XFileVertex(EggVertex *egg_vertex, EggPrimitive *egg_poly);
|
||||
int compare_to(const XFileVertex &other) const;
|
||||
|
||||
Vertexf _point;
|
||||
TexCoordf _uv;
|
||||
Colorf _color;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user