*** empty log message ***
This commit is contained in:
parent
1f6992387b
commit
6598257b5f
|
|
@ -150,12 +150,12 @@ make_faces() {
|
|||
EggVertexPool *egg_vpool = _points->_egg_vpool;
|
||||
|
||||
// We reverse the vertex ordering to compensate for Lightwave's
|
||||
// clockwise ordering convention.
|
||||
vector_int::reverse_iterator vi;
|
||||
for (vi = poly->_vertices.rbegin();
|
||||
vi != poly->_vertices.rend() && is_valid;
|
||||
++vi) {
|
||||
int vindex = (*vi);
|
||||
// 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();
|
||||
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;
|
||||
|
|
|
|||
|
|
@ -0,0 +1,16 @@
|
|||
// Filename: cLwoSurface.I
|
||||
// Created by: drose (25Apr01)
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: CLwoSurface::get_name
|
||||
// Access: Public
|
||||
// Description: Returns the name of the surface. Each surface in a
|
||||
// given Lightwave file should have a unique name.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE const string &CLwoSurface::
|
||||
get_name() const {
|
||||
return _surface->_name;
|
||||
}
|
||||
|
|
@ -0,0 +1,134 @@
|
|||
// Filename: cLwoSurface.cxx
|
||||
// Created by: drose (25Apr01)
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "cLwoSurface.h"
|
||||
#include "lwoToEggConverter.h"
|
||||
|
||||
#include <lwoSurfaceColor.h>
|
||||
#include <lwoSurfaceParameter.h>
|
||||
#include <lwoSurfaceSmoothingAngle.h>
|
||||
#include <lwoSurfaceSidedness.h>
|
||||
#include <eggPrimitive.h>
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: CLwoSurface::Constructor
|
||||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
CLwoSurface::
|
||||
CLwoSurface(LwoToEggConverter *converter, const LwoSurface *surface) :
|
||||
_converter(converter),
|
||||
_surface(surface)
|
||||
{
|
||||
_flags = 0;
|
||||
|
||||
// Walk through the chunk list, looking for some basic properties.
|
||||
int num_chunks = _surface->get_num_chunks();
|
||||
for (int i = 0; i < num_chunks; i++) {
|
||||
const IffChunk *chunk = _surface->get_chunk(i);
|
||||
|
||||
if (chunk->is_of_type(LwoSurfaceColor::get_class_type())) {
|
||||
const LwoSurfaceColor *color = DCAST(LwoSurfaceColor, chunk);
|
||||
_flags |= F_color;
|
||||
_color = color->_color;
|
||||
|
||||
} else if (chunk->is_of_type(LwoSurfaceParameter::get_class_type())) {
|
||||
const LwoSurfaceParameter *param = DCAST(LwoSurfaceParameter, chunk);
|
||||
IffId type = param->get_id();
|
||||
|
||||
if (type == IffId("DIFF")) {
|
||||
_flags |= F_diffuse;
|
||||
_diffuse = param->_value;
|
||||
|
||||
} else if (type == IffId("LUMI")) {
|
||||
_flags |= F_luminosity;
|
||||
_luminosity = param->_value;
|
||||
|
||||
} else if (type == IffId("SPEC")) {
|
||||
_flags |= F_specular;
|
||||
_specular = param->_value;
|
||||
|
||||
} else if (type == IffId("REFL")) {
|
||||
_flags |= F_reflection;
|
||||
_reflection = param->_value;
|
||||
|
||||
} else if (type == IffId("TRAN")) {
|
||||
_flags |= F_transparency;
|
||||
_transparency = param->_value;
|
||||
|
||||
} else if (type == IffId("TRNL")) {
|
||||
_flags |= F_translucency;
|
||||
_translucency = param->_value;
|
||||
}
|
||||
|
||||
} else if (chunk->is_of_type(LwoSurfaceSmoothingAngle::get_class_type())) {
|
||||
const LwoSurfaceSmoothingAngle *sa = DCAST(LwoSurfaceSmoothingAngle, chunk);
|
||||
_flags |= F_smooth_angle;
|
||||
_smooth_angle = sa->_angle;
|
||||
|
||||
} else if (chunk->is_of_type(LwoSurfaceSidedness::get_class_type())) {
|
||||
const LwoSurfaceSidedness *sn = DCAST(LwoSurfaceSidedness, chunk);
|
||||
_flags |= F_backface;
|
||||
_backface = (sn->_sidedness == LwoSurfaceSidedness::S_front_and_back);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: CLwoSurface::apply_properties
|
||||
// Access: Public
|
||||
// Description: Applies the color, texture, etc. described by the
|
||||
// surface to the indicated egg primitive.
|
||||
//
|
||||
// If the surface defines a smoothing angle,
|
||||
// smooth_angle may be updated to reflect it if the
|
||||
// angle is greater than that specified.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
void CLwoSurface::
|
||||
apply_properties(EggPrimitive *egg_prim, 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);
|
||||
}
|
||||
}
|
||||
|
||||
// We treat color and transparency separately, because Lightwave
|
||||
// does, and this will allow us to treat inherited surfaces a little
|
||||
// more robustly.
|
||||
if ((_flags & F_color) != 0) {
|
||||
Colorf color(1.0, 1.0, 1.0, 1.0);
|
||||
if (egg_prim->has_color()) {
|
||||
color = egg_prim->get_color();
|
||||
}
|
||||
|
||||
color[0] = _color[0];
|
||||
color[1] = _color[1];
|
||||
color[2] = _color[2];
|
||||
|
||||
egg_prim->set_color(color);
|
||||
}
|
||||
|
||||
if ((_flags & F_transparency) != 0) {
|
||||
Colorf color(1.0, 1.0, 1.0, 1.0);
|
||||
if (egg_prim->has_color()) {
|
||||
color = egg_prim->get_color();
|
||||
}
|
||||
|
||||
color[3] = 1.0 - _transparency;
|
||||
egg_prim->set_color(color);
|
||||
}
|
||||
|
||||
if ((_flags & F_backface) != 0) {
|
||||
egg_prim->set_bface_flag(_backface);
|
||||
}
|
||||
|
||||
if ((_flags & F_smooth_angle) != 0) {
|
||||
smooth_angle = max(smooth_angle, _smooth_angle);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,62 @@
|
|||
// Filename: cLwoSurface.h
|
||||
// Created by: drose (25Apr01)
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef CLWOSURFACE_H
|
||||
#define CLWOSURFACE_H
|
||||
|
||||
#include <pandatoolbase.h>
|
||||
|
||||
#include <lwoSurface.h>
|
||||
#include <luse.h>
|
||||
|
||||
class LwoToEggConverter;
|
||||
class EggPrimitive;
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Class : CLwoSurface
|
||||
// Description : This class is a wrapper around LwoSurface and stores
|
||||
// additional information useful during the
|
||||
// conversion-to-egg process.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
class CLwoSurface {
|
||||
public:
|
||||
CLwoSurface(LwoToEggConverter *converter, const LwoSurface *surface);
|
||||
|
||||
INLINE const string &get_name() const;
|
||||
|
||||
void apply_properties(EggPrimitive *egg_prim, float &smooth_angle);
|
||||
|
||||
enum Flags {
|
||||
F_color = 0x0001,
|
||||
F_diffuse = 0x0002,
|
||||
F_luminosity = 0x0004,
|
||||
F_specular = 0x0008,
|
||||
F_reflection = 0x0010,
|
||||
F_transparency = 0x0020,
|
||||
F_translucency = 0x0040,
|
||||
F_smooth_angle = 0x0080,
|
||||
F_backface = 0x0100,
|
||||
};
|
||||
|
||||
int _flags;
|
||||
RGBColorf _color;
|
||||
float _diffuse;
|
||||
float _luminosity;
|
||||
float _specular;
|
||||
float _reflection;
|
||||
float _transparency;
|
||||
float _translucency;
|
||||
float _smooth_angle;
|
||||
bool _backface;
|
||||
|
||||
LwoToEggConverter *_converter;
|
||||
CPT(LwoSurface) _surface;
|
||||
};
|
||||
|
||||
#include "cLwoSurface.I"
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
Loading…
Reference in New Issue