*** empty log message ***

This commit is contained in:
David Rose 2001-04-27 02:31:53 +00:00
parent 3b874d38e6
commit e4aa242e85
17 changed files with 415 additions and 60 deletions

View File

@ -49,3 +49,55 @@ set_egg_data(EggData *egg_data, bool owns_egg_data) {
_egg_data = egg_data;
_owns_egg_data = owns_egg_data;
}
////////////////////////////////////////////////////////////////////
// Function: SomethingToEggConverter::convert_path
// Access: Protected, Static
// Description: Converts the pathname reference by the source file as
// requested. This may either make it absolute,
// relative, or leave it alone.
//
// orig_filename is the filename as it actually appeared
// in the source file; as_found is the full pathname to the
// file as it actually exists on disk, assuming it was
// found on the search path. rel_dir is the directory
// to make the pathname relative to in the case of
// PC_relative or PC_rel_abs.
////////////////////////////////////////////////////////////////////
Filename SomethingToEggConverter::
convert_path(const Filename &orig_filename, const Filename &as_found,
const Filename &rel_dir, PathConvert path_convert) {
Filename result;
switch (path_convert) {
case PC_relative:
result = as_found;
result.make_relative_to(rel_dir);
return result;
case PC_absolute:
result = as_found;
if (as_found.is_local()) {
nout << "Warning: file " << as_found << " not found; cannot make absolute.\n";
return result;
}
result.make_absolute();
return result;
case PC_rel_abs:
result = as_found;
result.make_relative_to(rel_dir);
result = Filename(rel_dir, result);
return result;
case PC_strip:
return orig_filename.get_basename();
case PC_unchanged:
return orig_filename;
}
// Error case.
nout << "Invalid PathConvert type: " << (int)path_convert << "\n";
return orig_filename;
}

View File

@ -48,6 +48,13 @@ public:
virtual bool convert_file(const Filename &filename)=0;
protected:
static Filename convert_path(const Filename &orig_filename,
const Filename &as_found,
const Filename &rel_dir,
PathConvert path_convert);
protected:
PathConvert _tpc;
Filename _tpc_directory;

View File

@ -653,58 +653,6 @@ parse_comment(const string &comment, const string &name,
return true;
}
////////////////////////////////////////////////////////////////////
// Function: FltToEggConverter::convert_path
// Access: Private, Static
// Description: Converts the pathname reference by the flt file as
// requested. This may either make it absolute,
// relative, or leave it alone.
//
// orig_filename is the filename as it actually appeared
// in the flt file; as_found is the full pathname to the
// file as it actually exists on disk, assuming it was
// found on the search path. rel_dir is the directory
// to make the pathname relative to in the case of
// PC_relative or PC_rel_abs.
////////////////////////////////////////////////////////////////////
Filename FltToEggConverter::
convert_path(const Filename &orig_filename, const Filename &as_found,
const Filename &rel_dir, PathConvert path_convert) {
Filename result;
switch (path_convert) {
case PC_relative:
result = as_found;
result.make_relative_to(rel_dir);
return result;
case PC_absolute:
result = as_found;
if (as_found.is_local()) {
nout << "Warning: file " << as_found << " not found; cannot make absolute.\n";
return result;
}
result.make_absolute();
return result;
case PC_rel_abs:
result = as_found;
result.make_relative_to(rel_dir);
result = Filename(rel_dir, result);
return result;
case PC_strip:
return orig_filename.get_basename();
case PC_unchanged:
return orig_filename;
}
// Error case.
nout << "Invalid PathConvert type: " << (int)path_convert << "\n";
return orig_filename;
}
////////////////////////////////////////////////////////////////////
// Function: FltToEggConverter::make_egg_vertex
// Access: Private

View File

@ -74,11 +74,6 @@ private:
bool parse_comment(const string &comment, const string &name,
EggNode *egg_node);
static Filename convert_path(const Filename &orig_filename,
const Filename &as_found,
const Filename &rel_dir,
PathConvert path_convert);
PT(EggVertex) make_egg_vertex(const FltVertex *flt_vertex);
PT(EggTexture) make_egg_texture(const FltTexture *flt_texture);

View File

@ -25,6 +25,20 @@ public:
virtual IffChunk *make_new_chunk(IffInputFile *in, IffId id);
public:
virtual TypeHandle get_type() const {
return get_class_type();
}
virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
static TypeHandle get_class_type() {
return _type_handle;
}
static void init_type() {
LwoGroupChunk::init_type();
register_type(_type_handle, "LwoClip",
LwoGroupChunk::get_class_type());
}
private:
static TypeHandle _type_handle;
};

View File

@ -29,6 +29,17 @@ TypeHandle LwoSurfaceBlock::_type_handle;
////////////////////////////////////////////////////////////////////
bool LwoSurfaceBlock::
read_iff(IffInputFile *in, size_t stop_at) {
PT(IffChunk) chunk = in->get_subchunk(this);
if (chunk == (IffChunk *)NULL) {
return false;
}
if (!chunk->is_of_type(LwoSurfaceBlockHeader::get_class_type())) {
nout << "Invalid chunk for header of surface block: " << *chunk << "\n";
return false;
}
_header = DCAST(LwoSurfaceBlockHeader, chunk);
read_subchunks_iff(in, stop_at);
return true;
}
@ -42,6 +53,8 @@ void LwoSurfaceBlock::
write(ostream &out, int indent_level) const {
indent(out, indent_level)
<< get_id() << " {\n";
_header->write(out, indent_level + 2);
out << "\n";
write_chunks(out, indent_level + 2);
indent(out, indent_level)
<< "}\n";

View File

@ -9,6 +9,7 @@
#include <pandatoolbase.h>
#include "lwoGroupChunk.h"
#include "lwoSurfaceBlockHeader.h"
////////////////////////////////////////////////////////////////////
// Class : LwoSurfaceBlock
@ -24,6 +25,8 @@ public:
virtual IffChunk *make_new_chunk(IffInputFile *in, IffId id);
PT(LwoSurfaceBlockHeader) _header;
private:
static TypeHandle _type_handle;
};

View File

@ -20,9 +20,9 @@
class LwoSurfaceBlockAxis : public LwoChunk {
public:
enum Axis {
M_x = 0,
M_y = 1,
M_z = 2
A_x = 0,
A_y = 1,
A_z = 2
};
Axis _axis;

View File

@ -12,6 +12,7 @@
cLwoPoints.I cLwoPoints.cxx cLwoPoints.h \
cLwoPolygons.I cLwoPolygons.cxx cLwoPolygons.h \
cLwoSurface.I cLwoSurface.cxx cLwoSurface.h \
cLwoSurfaceBlock.I cLwoSurfaceBlock.cxx cLwoSurfaceBlock.h \
lwoToEggConverter.I lwoToEggConverter.cxx lwoToEggConverter.h
#define INSTALL_HEADERS \

View File

@ -0,0 +1,36 @@
// Filename: cLwoClip.h
// Created by: drose (26Apr01)
//
////////////////////////////////////////////////////////////////////
#ifndef CLWOCLIP_H
#define CLWOCLIP_H
#include <pandatoolbase.h>
#include <lwoClip.h>
#include <eggGroup.h>
#include <pointerTo.h>
class LwoToEggConverter;
////////////////////////////////////////////////////////////////////
// Class : CLwoClip
// Description : This class is a wrapper around LwoClip and stores
// additional information useful during the
// conversion-to-egg process.
////////////////////////////////////////////////////////////////////
class CLwoClip {
public:
INLINE CLwoClip(LwoToEggConverter *converter, const LwoClip *clip);
INLINE int get_number() const;
LwoToEggConverter *_converter;
CPT(LwoClip) _clip;
};
#include "cLwoClip.I"
#endif

View File

@ -4,12 +4,14 @@
////////////////////////////////////////////////////////////////////
#include "cLwoSurface.h"
#include "cLwoSurfaceBlock.h"
#include "lwoToEggConverter.h"
#include <lwoSurfaceColor.h>
#include <lwoSurfaceParameter.h>
#include <lwoSurfaceSmoothingAngle.h>
#include <lwoSurfaceSidedness.h>
#include <lwoSurfaceBlock.h>
#include <eggPrimitive.h>
@ -24,6 +26,8 @@ CLwoSurface(LwoToEggConverter *converter, const LwoSurface *surface) :
_surface(surface)
{
_flags = 0;
_checked_texture = false;
_block = (CLwoSurfaceBlock *)NULL;
// Walk through the chunk list, looking for some basic properties.
int num_chunks = _surface->get_num_chunks();
@ -73,10 +77,49 @@ CLwoSurface(LwoToEggConverter *converter, const LwoSurface *surface) :
const LwoSurfaceSidedness *sn = DCAST(LwoSurfaceSidedness, chunk);
_flags |= F_backface;
_backface = (sn->_sidedness == LwoSurfaceSidedness::S_front_and_back);
} else if (chunk->is_of_type(LwoSurfaceBlock::get_class_type())) {
const LwoSurfaceBlock *lwo_block = DCAST(LwoSurfaceBlock, chunk);
// One of possibly several blocks in the texture that define
// additional fancy rendering properties.
CLwoSurfaceBlock *block = new CLwoSurfaceBlock(_converter, lwo_block);
// We only consider enabled "IMAP" type blocks that affect "COLR".
if (block->_block_type == IffId("IMAP") &&
block->_channel_id == IffId("COLR") &&
block->_enabled) {
// Now save the block with the lowest ordinal.
if (_block == (CLwoSurfaceBlock *)NULL) {
_block = block;
} else if (block->_ordinal < _block->_ordinal) {
delete _block;
_block = block;
} else {
delete block;
}
} else {
delete block;
}
}
}
}
////////////////////////////////////////////////////////////////////
// Function: CLwoSurface::Destructor
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
CLwoSurface::
~CLwoSurface() {
if (_block != (CLwoSurfaceBlock *)NULL) {
delete _block;
}
}
////////////////////////////////////////////////////////////////////
// Function: CLwoSurface::apply_properties
// Access: Public
@ -131,4 +174,31 @@ apply_properties(EggPrimitive *egg_prim, float &smooth_angle) {
if ((_flags & F_smooth_angle) != 0) {
smooth_angle = max(smooth_angle, _smooth_angle);
}
check_texture();
}
////////////////////////////////////////////////////////////////////
// Function: CLwoSurface::check_texture
// Access: Public
// Description: Checks whether the surface demands a texture or not.
// Returns true if so, false otherwise.
//
// If the surface demands a texture, this also sets up
// _egg_texture and _compute_uvs as appropriate for the
// texture.
////////////////////////////////////////////////////////////////////
bool CLwoSurface::
check_texture() {
if (_checked_texture) {
return (_egg_texture != (EggTexture *)NULL);
}
_checked_texture = true;
/*
cerr << "Got texture:\n";
_block->_block->write(cerr, 2);
*/
return true;
}

View File

@ -10,8 +10,13 @@
#include <lwoSurface.h>
#include <luse.h>
#include <eggTexture.h>
#include <map>
class CLwoSurfaceBlock;
class LwoToEggConverter;
class LwoSurfaceBlock;
class EggPrimitive;
////////////////////////////////////////////////////////////////////
@ -23,10 +28,12 @@ class EggPrimitive;
class CLwoSurface {
public:
CLwoSurface(LwoToEggConverter *converter, const LwoSurface *surface);
~CLwoSurface();
INLINE const string &get_name() const;
void apply_properties(EggPrimitive *egg_prim, float &smooth_angle);
bool check_texture();
enum Flags {
F_color = 0x0001,
@ -53,6 +60,11 @@ public:
LwoToEggConverter *_converter;
CPT(LwoSurface) _surface;
bool _checked_texture;
PT(EggTexture) _egg_texture;
CLwoSurfaceBlock *_block;
};
#include "cLwoSurface.I"

View File

@ -0,0 +1,4 @@
// Filename: cLwoSurfaceBlock.I
// Created by: drose (26Apr01)
//
////////////////////////////////////////////////////////////////////

View File

@ -0,0 +1,94 @@
// Filename: cLwoSurfaceBlock.cxx
// Created by: drose (26Apr01)
//
////////////////////////////////////////////////////////////////////
#include "cLwoSurfaceBlock.h"
#include "lwoToEggConverter.h"
#include <lwoSurfaceBlockChannel.h>
#include <lwoSurfaceBlockEnabled.h>
#include <lwoSurfaceBlockImage.h>
#include <lwoSurfaceBlockRepeat.h>
////////////////////////////////////////////////////////////////////
// Function: CLwoSurfaceBlock::Constructor
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
CLwoSurfaceBlock::
CLwoSurfaceBlock(LwoToEggConverter *converter, const LwoSurfaceBlock *block) :
_converter(converter),
_block(block)
{
_block_type = _block->_header->get_id();
_ordinal = _block->_header->_ordinal;
_enabled = true;
_opacity_type = LwoSurfaceBlockOpacity::T_additive;
_opacity = 1.0;
_transform = LMatrix4d::ident_mat();
_inv_transform = LMatrix4d::ident_mat();
_projection_mode = LwoSurfaceBlockProjection::M_uv;
_axis = LwoSurfaceBlockAxis::A_y;
_clip_index = -1;
_w_wrap = LwoSurfaceBlockWrap::M_repeat;
_h_wrap = LwoSurfaceBlockWrap::M_repeat;
_w_repeat = 1.0;
_h_repeat = 1.0;
// Scan the chunks in the header.
int num_hchunks = _block->_header->get_num_chunks();
for (int hi = 0; hi < num_hchunks; hi++) {
const IffChunk *hchunk = _block->_header->get_chunk(hi);
if (hchunk->is_of_type(LwoSurfaceBlockChannel::get_class_type())) {
const LwoSurfaceBlockChannel *bc =
DCAST(LwoSurfaceBlockChannel, hchunk);
_channel_id = bc->_channel_id;
} else if (hchunk->is_of_type(LwoSurfaceBlockEnabled::get_class_type())) {
const LwoSurfaceBlockEnabled *ec =
DCAST(LwoSurfaceBlockEnabled, hchunk);
_enabled = ec->_enabled;
}
}
// Scan the chunks in the body.
int num_chunks = _block->get_num_chunks();
for (int i = 0; i < num_chunks; i++) {
const IffChunk *chunk = _block->get_chunk(i);
if (chunk->is_of_type(LwoSurfaceBlockProjection::get_class_type())) {
const LwoSurfaceBlockProjection *proj = DCAST(LwoSurfaceBlockProjection, chunk);
_projection_mode = proj->_mode;
} else if (chunk->is_of_type(LwoSurfaceBlockAxis::get_class_type())) {
const LwoSurfaceBlockAxis *axis = DCAST(LwoSurfaceBlockAxis, chunk);
_axis = axis->_axis;
} else if (chunk->is_of_type(LwoSurfaceBlockImage::get_class_type())) {
const LwoSurfaceBlockImage *image = DCAST(LwoSurfaceBlockImage, chunk);
_clip_index = image->_index;
} else if (chunk->is_of_type(LwoSurfaceBlockWrap::get_class_type())) {
const LwoSurfaceBlockWrap *wrap = DCAST(LwoSurfaceBlockWrap, chunk);
_w_wrap = wrap->_width;
_h_wrap = wrap->_height;
} else if (chunk->is_of_type(LwoSurfaceBlockWrap::get_class_type())) {
const LwoSurfaceBlockWrap *wrap = DCAST(LwoSurfaceBlockWrap, chunk);
_w_wrap = wrap->_width;
_h_wrap = wrap->_height;
} else if (chunk->is_of_type(LwoSurfaceBlockRepeat::get_class_type())) {
const LwoSurfaceBlockRepeat *repeat = DCAST(LwoSurfaceBlockRepeat, chunk);
if (repeat->get_id() == IffId("WRPW")) {
_w_repeat = repeat->_cycles;
} else if (repeat->get_id() == IffId("WRPH")) {
_h_repeat = repeat->_cycles;
}
}
}
}

View File

@ -0,0 +1,59 @@
// Filename: cLwoSurfaceBlock.h
// Created by: drose (26Apr01)
//
////////////////////////////////////////////////////////////////////
#ifndef CLWOSURFACEBLOCK_H
#define CLWOSURFACEBLOCK_H
#include <pandatoolbase.h>
#include <lwoSurfaceBlock.h>
#include <lwoSurfaceBlockOpacity.h>
#include <lwoSurfaceBlockProjection.h>
#include <lwoSurfaceBlockAxis.h>
#include <lwoSurfaceBlockWrap.h>
#include <luse.h>
class LwoToEggConverter;
////////////////////////////////////////////////////////////////////
// Class : CLwoSurfaceBlock
// Description : This class is a wrapper around LwoSurfaceBlock and stores
// additional information useful during the
// conversion-to-egg process.
////////////////////////////////////////////////////////////////////
class CLwoSurfaceBlock {
public:
CLwoSurfaceBlock(LwoToEggConverter *converter, const LwoSurfaceBlock *block);
IffId _block_type;
IffId _channel_id;
string _ordinal;
bool _enabled;
LwoSurfaceBlockOpacity::Type _opacity_type;
float _opacity;
LMatrix4d _transform;
LMatrix4d _inv_transform;
LwoSurfaceBlockProjection::Mode _projection_mode;
LwoSurfaceBlockAxis::Axis _axis;
int _clip_index;
LwoSurfaceBlockWrap::Mode _w_wrap;
LwoSurfaceBlockWrap::Mode _h_wrap;
float _w_repeat;
float _h_repeat;
string _uv_name;
LwoToEggConverter *_converter;
CPT(LwoSurfaceBlock) _block;
};
#include "cLwoSurfaceBlock.I"
#endif

View File

@ -12,6 +12,7 @@
#include <eggData.h>
#include <lwoHeader.h>
#include <lwoLayer.h>
#include <lwoClip.h>
#include <lwoPoints.h>
#include <lwoPolygons.h>
#include <lwoVertexMap.h>
@ -172,6 +173,20 @@ get_layer(int number) const {
return (CLwoLayer *)NULL;
}
////////////////////////////////////////////////////////////////////
// Function: LwoToEggConverter::get_clip
// Access: Public
// Description: Returns a pointer to the clip with the given index
// number, or NULL if there is no such clip.
////////////////////////////////////////////////////////////////////
const LwoClip *LwoToEggConverter::
get_clip(int number) const {
if (number >= 0 && number < (int)_clips.size()) {
return _clips[number];
}
return (const LwoClip *)NULL;
}
////////////////////////////////////////////////////////////////////
// Function: LwoToEggConverter::get_surface
// Access: Public
@ -220,6 +235,16 @@ collect_lwo() {
last_points = (CLwoPoints *)NULL;
last_polygons = (CLwoPolygons *)NULL;
} else if (chunk->is_of_type(LwoClip::get_class_type())) {
const LwoClip *lwo_clip = DCAST(LwoClip, chunk);
int index = lwo_clip->_index;
slot_clip(index);
if (_clips[index] != (LwoClip *)NULL) {
nout << "Warning: multiple clips with index " << index << "\n";
}
_clips[index] = lwo_clip;
} else if (chunk->is_of_type(LwoPoints::get_class_type())) {
if (last_layer == (CLwoLayer *)NULL) {
last_layer = make_generic_layer();
@ -352,12 +377,28 @@ connect_egg() {
////////////////////////////////////////////////////////////////////
void LwoToEggConverter::
slot_layer(int number) {
nassertv(number - (int)_layers.size() < 1000);
while (number >= (int)_layers.size()) {
_layers.push_back((CLwoLayer *)NULL);
}
nassertv(number >= 0 && number < (int)_layers.size());
}
////////////////////////////////////////////////////////////////////
// Function: LwoToEggConverter::slot_clip
// Access: Private
// Description: Ensures that there is space in the _clips array to
// store an element at position number.
////////////////////////////////////////////////////////////////////
void LwoToEggConverter::
slot_clip(int number) {
nassertv(number - (int)_clips.size() < 1000);
while (number >= (int)_clips.size()) {
_clips.push_back((LwoClip *)NULL);
}
nassertv(number >= 0 && number < (int)_clips.size());
}
////////////////////////////////////////////////////////////////////
// Function: LwoToEggConverter::make_generic_layer
// Access: Private

View File

@ -19,6 +19,7 @@ class CLwoLayer;
class CLwoPoints;
class CLwoPolygons;
class CLwoSurface;
class LwoClip;
////////////////////////////////////////////////////////////////////
// Class : LwoToEggConverter
@ -39,6 +40,7 @@ public:
bool convert_lwo(const LwoHeader *lwo_header);
CLwoLayer *get_layer(int number) const;
const LwoClip *get_clip(int number) const;
CLwoSurface *get_surface(const string &name) const;
@ -48,6 +50,7 @@ private:
void connect_egg();
void slot_layer(int number);
void slot_clip(int number);
CLwoLayer *make_generic_layer();
CPT(LwoHeader) _lwo_header;
@ -56,6 +59,9 @@ private:
typedef vector<CLwoLayer *> Layers;
Layers _layers;
typedef vector<const LwoClip *> Clips;
Clips _clips;
typedef vector<CLwoPoints *> Points;
Points _points;