Delete lots of unused features (#48)

This commit is contained in:
hecks
2021-07-23 16:23:44 +02:00
committed by GitHub
parent dc2246dae7
commit 4ab3de3bab
1103 changed files with 41 additions and 216490 deletions

File diff suppressed because it is too large Load Diff

View File

@ -1,166 +0,0 @@
// Copyright (C) 2002-2012 Nikolaus Gebhardt
// This file is part of the "Irrlicht Engine".
// For conditions of distribution and use, see copyright notice in irrlicht.h
#ifndef __C_3DS_MESH_FILE_LOADER_H_INCLUDED__
#define __C_3DS_MESH_FILE_LOADER_H_INCLUDED__
#include "IMeshLoader.h"
#include "IFileSystem.h"
#include "ISceneManager.h"
#include "irrString.h"
#include "SMesh.h"
#include "matrix4.h"
namespace irr
{
namespace scene
{
//! Meshloader capable of loading 3ds meshes.
class C3DSMeshFileLoader : public IMeshLoader
{
public:
//! Constructor
C3DSMeshFileLoader(ISceneManager* smgr, io::IFileSystem* fs);
//! destructor
virtual ~C3DSMeshFileLoader();
//! returns true if the file maybe is able to be loaded by this class
//! based on the file extension (e.g. ".cob")
virtual bool isALoadableFileExtension(const io::path& filename) const _IRR_OVERRIDE_;
//! creates/loads an animated mesh from the file.
//! \return Pointer to the created mesh. Returns 0 if loading failed.
//! If you no longer need the mesh, you should call IAnimatedMesh::drop().
//! See IReferenceCounted::drop() for more information.
virtual IAnimatedMesh* createMesh(io::IReadFile* file) _IRR_OVERRIDE_;
private:
// byte-align structures
#include "irrpack.h"
struct ChunkHeader
{
u16 id;
s32 length;
} PACK_STRUCT;
// Default alignment
#include "irrunpack.h"
struct ChunkData
{
ChunkData() : read(0) {}
ChunkHeader header;
s32 read;
};
struct SCurrentMaterial
{
void clear() {
Material=video::SMaterial();
Name="";
Filename[0]="";
Filename[1]="";
Filename[2]="";
Filename[3]="";
Filename[4]="";
Strength[0]=0.f;
Strength[1]=0.f;
Strength[2]=0.f;
Strength[3]=0.f;
Strength[4]=0.f;
}
video::SMaterial Material;
core::stringc Name;
core::stringc Filename[5];
f32 Strength[5];
};
struct SMaterialGroup
{
SMaterialGroup() : faceCount(0), faces(0) {};
SMaterialGroup(const SMaterialGroup& o)
{
*this = o;
}
~SMaterialGroup()
{
clear();
}
void clear()
{
delete [] faces;
faces = 0;
faceCount = 0;
}
void operator =(const SMaterialGroup& o)
{
MaterialName = o.MaterialName;
faceCount = o.faceCount;
faces = new u16[faceCount];
for (u16 i=0; i<faceCount; ++i)
faces[i] = o.faces[i];
}
core::stringc MaterialName;
u16 faceCount;
u16* faces;
};
bool readChunk(io::IReadFile* file, ChunkData* parent);
bool readMaterialChunk(io::IReadFile* file, ChunkData* parent);
bool readFrameChunk(io::IReadFile* file, ChunkData* parent);
bool readTrackChunk(io::IReadFile* file, ChunkData& data,
IMeshBuffer* mb, const core::vector3df& pivot);
bool readObjectChunk(io::IReadFile* file, ChunkData* parent);
bool readPercentageChunk(io::IReadFile* file, ChunkData* chunk, f32& percentage);
bool readColorChunk(io::IReadFile* file, ChunkData* chunk, video::SColor& out);
void readChunkData(io::IReadFile* file, ChunkData& data);
void readString(io::IReadFile* file, ChunkData& data, core::stringc& out);
void readVertices(io::IReadFile* file, ChunkData& data);
void readIndices(io::IReadFile* file, ChunkData& data);
void readMaterialGroup(io::IReadFile* file, ChunkData& data);
void readTextureCoords(io::IReadFile* file, ChunkData& data);
void composeObject(io::IReadFile* file, const core::stringc& name);
void loadMaterials(io::IReadFile* file);
void cleanUp();
scene::ISceneManager* SceneManager;
io::IFileSystem* FileSystem;
f32* Vertices;
u16* Indices;
u32* SmoothingGroups;
core::array<u16> TempIndices;
f32* TCoords;
u16 CountVertices;
u16 CountFaces; // = CountIndices/4
u16 CountTCoords;
core::array<SMaterialGroup> MaterialGroups;
SCurrentMaterial CurrentMaterial;
core::array<SCurrentMaterial> Materials;
core::array<core::stringc> MeshBufferNames;
core::matrix4 TransformationMatrix;
SMesh* Mesh;
};
} // end namespace scene
} // end namespace irr
#endif

File diff suppressed because it is too large Load Diff

View File

@ -1,630 +0,0 @@
// Copyright (C) 2002-2012 Thomas Alten
// This file is part of the "Irrlicht Engine".
// For conditions of distribution and use, see copyright notice in irrlicht.h
#ifndef __C_ANIMATED_MESH_HALFLIFE_H_INCLUDED__
#define __C_ANIMATED_MESH_HALFLIFE_H_INCLUDED__
#include "IAnimatedMesh.h"
#include "ISceneManager.h"
#include "irrArray.h"
#include "irrString.h"
#include "IMeshLoader.h"
#include "SMesh.h"
#include "IReadFile.h"
namespace irr
{
namespace scene
{
// STUDIO MODELS, Copyright (c) 1998, Valve LLC. All rights reserved.
#define MAXSTUDIOTRIANGLES 20000 // TODO: tune this
#define MAXSTUDIOVERTS 2048 // TODO: tune this
#define MAXSTUDIOSEQUENCES 256 // total animation sequences
#define MAXSTUDIOSKINS 100 // total textures
#define MAXSTUDIOSRCBONES 512 // bones allowed at source movement
#define MAXSTUDIOBONES 128 // total bones actually used
#define MAXSTUDIOMODELS 32 // sub-models per model
#define MAXSTUDIOBODYPARTS 32
#define MAXSTUDIOGROUPS 4
#define MAXSTUDIOANIMATIONS 512 // per sequence
#define MAXSTUDIOMESHES 256
#define MAXSTUDIOEVENTS 1024
#define MAXSTUDIOPIVOTS 256
#define MAXSTUDIOCONTROLLERS 8
typedef f32 vec3_hl[3]; // x,y,z
typedef f32 vec4_hl[4]; // x,y,z,w
// byte-align structures
#include "irrpack.h"
struct SHalflifeHeader
{
c8 id[4];
s32 version;
c8 name[64];
s32 length;
vec3_hl eyeposition; // ideal eye position
vec3_hl min; // ideal movement hull size
vec3_hl max;
vec3_hl bbmin; // clipping bounding box
vec3_hl bbmax;
s32 flags;
u32 numbones; // bones
u32 boneindex;
u32 numbonecontrollers; // bone controllers
u32 bonecontrollerindex;
u32 numhitboxes; // complex bounding boxes
u32 hitboxindex;
u32 numseq; // animation sequences
u32 seqindex;
u32 numseqgroups; // demand loaded sequences
u32 seqgroupindex;
u32 numtextures; // raw textures
u32 textureindex;
u32 texturedataindex;
u32 numskinref; // replaceable textures
u32 numskinfamilies;
u32 skinindex;
u32 numbodyparts;
u32 bodypartindex;
u32 numattachments; // queryable attachable points
u32 attachmentindex;
s32 soundtable;
s32 soundindex;
s32 soundgroups;
s32 soundgroupindex;
s32 numtransitions; // animation node to animation node transition graph
s32 transitionindex;
} PACK_STRUCT;
// header for demand loaded sequence group data
struct studioseqhdr_t
{
s32 id;
s32 version;
c8 name[64];
s32 length;
} PACK_STRUCT;
// bones
struct SHalflifeBone
{
c8 name[32]; // bone name for symbolic links
s32 parent; // parent bone
s32 flags; // ??
s32 bonecontroller[6]; // bone controller index, -1 == none
f32 value[6]; // default DoF values
f32 scale[6]; // scale for delta DoF values
} PACK_STRUCT;
// bone controllers
struct SHalflifeBoneController
{
s32 bone; // -1 == 0
s32 type; // X, Y, Z, XR, YR, ZR, M
f32 start;
f32 end;
s32 rest; // byte index value at rest
s32 index; // 0-3 user set controller, 4 mouth
} PACK_STRUCT;
// intersection boxes
struct SHalflifeBBox
{
s32 bone;
s32 group; // intersection group
vec3_hl bbmin; // bounding box
vec3_hl bbmax;
} PACK_STRUCT;
#ifndef ZONE_H
// NOTE: this was a void*, but that crashes on 64bit.
// I have found no mdl format desc, so not sure what it's meant to be, but s32 at least works.
typedef s32 cache_user_t;
#endif
// demand loaded sequence groups
struct SHalflifeSequenceGroup
{
c8 label[32]; // textual name
c8 name[64]; // file name
cache_user_t cache; // cache index pointer
s32 data; // hack for group 0
} PACK_STRUCT;
// sequence descriptions
struct SHalflifeSequence
{
c8 label[32]; // sequence label
f32 fps; // frames per second
s32 flags; // looping/non-looping flags
s32 activity;
s32 actweight;
s32 numevents;
s32 eventindex;
s32 numframes; // number of frames per sequence
u32 numpivots; // number of foot pivots
u32 pivotindex;
s32 motiontype;
s32 motionbone;
vec3_hl linearmovement;
s32 automoveposindex;
s32 automoveangleindex;
vec3_hl bbmin; // per sequence bounding box
vec3_hl bbmax;
s32 numblends;
s32 animindex; // SHalflifeAnimOffset pointer relative to start of sequence group data
// [blend][bone][X, Y, Z, XR, YR, ZR]
s32 blendtype[2]; // X, Y, Z, XR, YR, ZR
f32 blendstart[2]; // starting value
f32 blendend[2]; // ending value
s32 blendparent;
s32 seqgroup; // sequence group for demand loading
s32 entrynode; // transition node at entry
s32 exitnode; // transition node at exit
s32 nodeflags; // transition rules
s32 nextseq; // auto advancing sequences
} PACK_STRUCT;
// events
struct mstudioevent_t
{
s32 frame;
s32 event;
s32 type;
c8 options[64];
} PACK_STRUCT;
// pivots
struct mstudiopivot_t
{
vec3_hl org; // pivot point
s32 start;
s32 end;
} PACK_STRUCT;
// attachment
struct SHalflifeAttachment
{
c8 name[32];
s32 type;
s32 bone;
vec3_hl org; // attachment point
vec3_hl vectors[3];
} PACK_STRUCT;
struct SHalflifeAnimOffset
{
u16 offset[6];
} PACK_STRUCT;
// animation frames
union SHalflifeAnimationFrame
{
struct {
u8 valid;
u8 total;
} PACK_STRUCT num;
s16 value;
} PACK_STRUCT;
// body part index
struct SHalflifeBody
{
c8 name[64];
u32 nummodels;
u32 base;
u32 modelindex; // index into models array
} PACK_STRUCT;
// skin info
struct SHalflifeTexture
{
c8 name[64];
s32 flags;
s32 width;
s32 height;
s32 index;
} PACK_STRUCT;
// skin families
// short index[skinfamilies][skinref]
// studio models
struct SHalflifeModel
{
c8 name[64];
s32 type;
f32 boundingradius;
u32 nummesh;
u32 meshindex;
u32 numverts; // number of unique vertices
u32 vertinfoindex; // vertex bone info
u32 vertindex; // vertex vec3_hl
u32 numnorms; // number of unique surface normals
u32 norminfoindex; // normal bone info
u32 normindex; // normal vec3_hl
u32 numgroups; // deformation groups
u32 groupindex;
} PACK_STRUCT;
// meshes
struct SHalflifeMesh
{
u32 numtris;
u32 triindex;
u32 skinref;
u32 numnorms; // per mesh normals
u32 normindex; // normal vec3_hl
} PACK_STRUCT;
// Default alignment
#include "irrunpack.h"
// lighting options
#define STUDIO_NF_FLATSHADE 0x0001
#define STUDIO_NF_CHROME 0x0002
#define STUDIO_NF_FULLBRIGHT 0x0004
// motion flags
#define STUDIO_X 0x0001
#define STUDIO_Y 0x0002
#define STUDIO_Z 0x0004
#define STUDIO_XR 0x0008
#define STUDIO_YR 0x0010
#define STUDIO_ZR 0x0020
#define STUDIO_LX 0x0040
#define STUDIO_LY 0x0080
#define STUDIO_LZ 0x0100
#define STUDIO_AX 0x0200
#define STUDIO_AY 0x0400
#define STUDIO_AZ 0x0800
#define STUDIO_AXR 0x1000
#define STUDIO_AYR 0x2000
#define STUDIO_AZR 0x4000
#define STUDIO_TYPES 0x7FFF
#define STUDIO_RLOOP 0x8000 // controller that wraps shortest distance
// sequence flags
#define STUDIO_LOOPING 0x0001
// bone flags
#define STUDIO_HAS_NORMALS 0x0001
#define STUDIO_HAS_VERTICES 0x0002
#define STUDIO_HAS_BBOX 0x0004
#define STUDIO_HAS_CHROME 0x0008 // if any of the textures have chrome on them
#define RAD_TO_STUDIO (32768.0/M_PI)
#define STUDIO_TO_RAD (M_PI/32768.0)
/*!
Textureatlas
Combine Source Images with arbitrary size and bithdepth to an Image with 2^n size
borders from the source images are copied around for allowing filtering ( bilinear, mipmap )
*/
struct STextureAtlas
{
STextureAtlas ()
{
release();
}
virtual ~STextureAtlas ()
{
release ();
}
void release ();
void addSource ( const c8 * name, video::IImage * image );
void create ( u32 pixelborder, video::E_TEXTURE_CLAMP texmode );
void getScale ( core::vector2df &scale );
void getTranslation ( const c8 * name, core::vector2di &pos );
struct TextureAtlasEntry
{
io::path name;
u32 width;
u32 height;
core::vector2di pos;
video::IImage * image;
bool operator < ( const TextureAtlasEntry & other )
{
return height > other.height;
}
};
core::array < TextureAtlasEntry > atlas;
video::IImage * Master;
};
//! Possible types of Animation Type
enum E_ANIMATION_TYPE
{
//! No Animation
EAMT_STILL,
//! From Start to End, then Stop ( Limited Line )
EAMT_WAYPOINT,
//! Linear Cycling Animation ( Sawtooth )
EAMT_LOOPING,
//! Linear bobbing ( Triangle )
EAMT_PINGPONG
};
//! Names for Animation Type
const c8* const MeshAnimationTypeNames[] =
{
"still",
"waypoint",
"looping",
"pingpong",
0
};
//! Data for holding named Animation Info
struct KeyFrameInterpolation
{
core::stringc Name; // Name of the current Animation/Bone
E_ANIMATION_TYPE AnimationType; // Type of Animation ( looping, usw..)
f32 CurrentFrame; // Current Frame
s32 NextFrame; // Frame which will be used next. For blending
s32 StartFrame; // Absolute Frame where the current animation start
s32 Frames; // Relative Frames how much Frames this animation have
s32 LoopingFrames; // How much of Frames sould be looped
s32 EndFrame; // Absolute Frame where the current animation ends End = start + frames - 1
f32 FramesPerSecond; // Speed in Frames/Seconds the animation is played
f32 RelativeSpeed; // Factor Original fps is modified
u32 BeginTime; // Animation started at this thime
u32 EndTime; // Animation end at this time
u32 LastTime; // Last Keyframe was done at this time
KeyFrameInterpolation ( const c8 * name = "", s32 start = 0, s32 frames = 0, s32 loopingframes = 0,
f32 fps = 0.f, f32 relativefps = 1.f )
: Name ( name ), AnimationType ( loopingframes ? EAMT_LOOPING : EAMT_WAYPOINT),
CurrentFrame ( (f32) start ), NextFrame ( start ), StartFrame ( start ),
Frames ( frames ), LoopingFrames ( loopingframes ), EndFrame ( start + frames - 1 ),
FramesPerSecond ( fps ), RelativeSpeed ( relativefps ),
BeginTime ( 0 ), EndTime ( 0 ), LastTime ( 0 )
{
}
// linear search
bool operator == ( const KeyFrameInterpolation & other ) const
{
return Name.equals_ignore_case ( other.Name );
}
};
//! a List holding named Animations
typedef core::array < KeyFrameInterpolation > IAnimationList;
//! a List holding named Skins
typedef core::array < core::stringc > ISkinList;
// Current Model per Body
struct SubModel
{
core::stringc name;
u32 startBuffer;
u32 endBuffer;
u32 state;
};
struct BodyPart
{
core::stringc name;
u32 defaultModel;
core::array < SubModel > model;
};
//! a List holding named Models and SubModels
typedef core::array < BodyPart > IBodyList;
class CAnimatedMeshHalfLife : public IAnimatedMesh
{
public:
//! constructor
CAnimatedMeshHalfLife();
//! destructor
virtual ~CAnimatedMeshHalfLife();
//! loads a Halflife mdl file
bool loadModelFile( io::IReadFile* file, ISceneManager * smgr );
//IAnimatedMesh
virtual u32 getFrameCount() const _IRR_OVERRIDE_;
virtual IMesh* getMesh(s32 frame, s32 detailLevel, s32 startFrameLoop, s32 endFrameLoop) _IRR_OVERRIDE_;
virtual const core::aabbox3d<f32>& getBoundingBox() const _IRR_OVERRIDE_;
virtual E_ANIMATED_MESH_TYPE getMeshType() const _IRR_OVERRIDE_;
void renderModel ( u32 param, video::IVideoDriver * driver, const core::matrix4 &absoluteTransformation);
//! returns amount of mesh buffers.
virtual u32 getMeshBufferCount() const _IRR_OVERRIDE_;
//! returns pointer to a mesh buffer
virtual IMeshBuffer* getMeshBuffer(u32 nr) const _IRR_OVERRIDE_;
//! Returns pointer to a mesh buffer which fits a material
virtual IMeshBuffer* getMeshBuffer( const video::SMaterial &material) const _IRR_OVERRIDE_;
virtual void setMaterialFlag(video::E_MATERIAL_FLAG flag, bool newvalue) _IRR_OVERRIDE_;
//! set the hardware mapping hint, for driver
virtual void setHardwareMappingHint(E_HARDWARE_MAPPING newMappingHint, E_BUFFER_TYPE buffer=EBT_VERTEX_AND_INDEX) _IRR_OVERRIDE_;
//! flags the meshbuffer as changed, reloads hardware buffers
virtual void setDirty(E_BUFFER_TYPE buffer=EBT_VERTEX_AND_INDEX) _IRR_OVERRIDE_;
//! set user axis aligned bounding box
virtual void setBoundingBox(const core::aabbox3df& box) _IRR_OVERRIDE_;
//! Gets the default animation speed of the animated mesh.
/** \return Amount of frames per second. If the amount is 0, it is a static, non animated mesh. */
virtual f32 getAnimationSpeed() const _IRR_OVERRIDE_
{
return FramesPerSecond;
}
//! Gets the frame count of the animated mesh.
/** \param fps Frames per second to play the animation with. If the amount is 0, it is not animated.
The actual speed is set in the scene node the mesh is instantiated in.*/
virtual void setAnimationSpeed(f32 fps) _IRR_OVERRIDE_
{
FramesPerSecond=fps;
}
//! Get the Animation List
IAnimationList* getAnimList () { return &AnimList; }
//! Return the named Body List of this Animated Mesh
IBodyList *getBodyList() { return &BodyList; }
private:
// KeyFrame Animation List
IAnimationList AnimList;
// Sum of all sequences
u32 FrameCount;
// Named meshes of the Body
IBodyList BodyList;
//! return a Mesh per frame
SMesh* MeshIPol;
ISceneManager *SceneManager;
SHalflifeHeader *Header;
SHalflifeHeader *TextureHeader;
bool OwnTexModel; // do we have a modelT.mdl ?
SHalflifeHeader *AnimationHeader[32]; // sequences named model01.mdl, model02.mdl
void initData ();
SHalflifeHeader * loadModel( io::IReadFile* file, const io::path &filename );
bool postLoadModel( const io::path &filename );
u32 SequenceIndex; // sequence index
f32 CurrentFrame; // Current Frame
f32 FramesPerSecond;
#define MOUTH_CONTROLLER 4
u8 BoneController[4 + 1 ]; // bone controllers + mouth position
u8 Blending[2]; // animation blending
vec4_hl BoneAdj;
f32 SetController( s32 controllerIndex, f32 value );
u32 SkinGroupSelection; // skin group selection
u32 SetSkin( u32 value );
void initModel();
void dumpModelInfo(u32 level) const;
void ExtractBbox(s32 sequence, core::aabbox3df &box) const;
void setUpBones ();
SHalflifeAnimOffset * getAnim( SHalflifeSequence *seq );
void slerpBones( vec4_hl q1[], vec3_hl pos1[], vec4_hl q2[], vec3_hl pos2[], f32 s );
void calcRotations ( vec3_hl *pos, vec4_hl *q, SHalflifeSequence *seq, SHalflifeAnimOffset *anim, f32 f );
void calcBoneAdj();
void calcBoneQuaternion(const s32 frame, const SHalflifeBone *bone, SHalflifeAnimOffset *anim, const u32 j, f32& angle1, f32& angle2) const;
void calcBonePosition(const s32 frame, f32 s, const SHalflifeBone *bone, SHalflifeAnimOffset *anim, f32 *pos ) const;
void buildVertices ();
io::path TextureBaseName;
#define HL_TEXTURE_ATLAS
#ifdef HL_TEXTURE_ATLAS
STextureAtlas TextureAtlas;
// video::ITexture *TextureMaster;
#endif
};
//! Meshloader capable of loading HalfLife Model files
class CHalflifeMDLMeshFileLoader : public IMeshLoader
{
public:
//! Constructor
CHalflifeMDLMeshFileLoader( scene::ISceneManager* smgr );
//! returns true if the file maybe is able to be loaded by this class
/** based on the file extension (e.g. ".bsp") */
virtual bool isALoadableFileExtension(const io::path& filename) const _IRR_OVERRIDE_;
//! creates/loads an animated mesh from the file.
/** \return Pointer to the created mesh. Returns 0 if loading failed.
If you no longer need the mesh, you should call IAnimatedMesh::drop().
See IReferenceCounted::drop() for more information.
*/
virtual IAnimatedMesh* createMesh(io::IReadFile* file) _IRR_OVERRIDE_;
private:
scene::ISceneManager* SceneManager;
};
} // end namespace scene
} // end namespace irr
#endif

View File

@ -1,465 +0,0 @@
// Copyright (C) 2002-2012 Nikolaus Gebhardt
// This file is part of the "Irrlicht Engine".
// For conditions of distribution and use, see copyright notice in irrlicht.h
#include "IrrCompileConfig.h"
#ifdef _IRR_COMPILE_WITH_MD2_LOADER_
#include "CAnimatedMeshMD2.h"
#include "SColor.h"
#include "irrMath.h"
namespace irr
{
namespace scene
{
const s32 MD2_FRAME_SHIFT = 2;
const f32 MD2_FRAME_SHIFT_RECIPROCAL = 1.f / (1 << MD2_FRAME_SHIFT);
const s32 Q2_VERTEX_NORMAL_TABLE_SIZE = 162;
static const f32 Q2_VERTEX_NORMAL_TABLE[Q2_VERTEX_NORMAL_TABLE_SIZE][3] = {
{-0.525731f, 0.000000f, 0.850651f},
{-0.442863f, 0.238856f, 0.864188f},
{-0.295242f, 0.000000f, 0.955423f},
{-0.309017f, 0.500000f, 0.809017f},
{-0.162460f, 0.262866f, 0.951056f},
{0.000000f, 0.000000f, 1.000000f},
{0.000000f, 0.850651f, 0.525731f},
{-0.147621f, 0.716567f, 0.681718f},
{0.147621f, 0.716567f, 0.681718f},
{0.000000f, 0.525731f, 0.850651f},
{0.309017f, 0.500000f, 0.809017f},
{0.525731f, 0.000000f, 0.850651f},
{0.295242f, 0.000000f, 0.955423f},
{0.442863f, 0.238856f, 0.864188f},
{0.162460f, 0.262866f, 0.951056f},
{-0.681718f, 0.147621f, 0.716567f},
{-0.809017f, 0.309017f, 0.500000f},
{-0.587785f, 0.425325f, 0.688191f},
{-0.850651f, 0.525731f, 0.000000f},
{-0.864188f, 0.442863f, 0.238856f},
{-0.716567f, 0.681718f, 0.147621f},
{-0.688191f, 0.587785f, 0.425325f},
{-0.500000f, 0.809017f, 0.309017f},
{-0.238856f, 0.864188f, 0.442863f},
{-0.425325f, 0.688191f, 0.587785f},
{-0.716567f, 0.681718f, -0.147621f},
{-0.500000f, 0.809017f, -0.309017f},
{-0.525731f, 0.850651f, 0.000000f},
{0.000000f, 0.850651f, -0.525731f},
{-0.238856f, 0.864188f, -0.442863f},
{0.000000f, 0.955423f, -0.295242f},
{-0.262866f, 0.951056f, -0.162460f},
{0.000000f, 1.000000f, 0.000000f},
{0.000000f, 0.955423f, 0.295242f},
{-0.262866f, 0.951056f, 0.162460f},
{0.238856f, 0.864188f, 0.442863f},
{0.262866f, 0.951056f, 0.162460f},
{0.500000f, 0.809017f, 0.309017f},
{0.238856f, 0.864188f, -0.442863f},
{0.262866f, 0.951056f, -0.162460f},
{0.500000f, 0.809017f, -0.309017f},
{0.850651f, 0.525731f, 0.000000f},
{0.716567f, 0.681718f, 0.147621f},
{0.716567f, 0.681718f, -0.147621f},
{0.525731f, 0.850651f, 0.000000f},
{0.425325f, 0.688191f, 0.587785f},
{0.864188f, 0.442863f, 0.238856f},
{0.688191f, 0.587785f, 0.425325f},
{0.809017f, 0.309017f, 0.500000f},
{0.681718f, 0.147621f, 0.716567f},
{0.587785f, 0.425325f, 0.688191f},
{0.955423f, 0.295242f, 0.000000f},
{1.000000f, 0.000000f, 0.000000f},
{0.951056f, 0.162460f, 0.262866f},
{0.850651f, -0.525731f, 0.000000f},
{0.955423f, -0.295242f, 0.000000f},
{0.864188f, -0.442863f, 0.238856f},
{0.951056f, -0.162460f, 0.262866f},
{0.809017f, -0.309017f, 0.500000f},
{0.681718f, -0.147621f, 0.716567f},
{0.850651f, 0.000000f, 0.525731f},
{0.864188f, 0.442863f, -0.238856f},
{0.809017f, 0.309017f, -0.500000f},
{0.951056f, 0.162460f, -0.262866f},
{0.525731f, 0.000000f, -0.850651f},
{0.681718f, 0.147621f, -0.716567f},
{0.681718f, -0.147621f, -0.716567f},
{0.850651f, 0.000000f, -0.525731f},
{0.809017f, -0.309017f, -0.500000f},
{0.864188f, -0.442863f, -0.238856f},
{0.951056f, -0.162460f, -0.262866f},
{0.147621f, 0.716567f, -0.681718f},
{0.309017f, 0.500000f, -0.809017f},
{0.425325f, 0.688191f, -0.587785f},
{0.442863f, 0.238856f, -0.864188f},
{0.587785f, 0.425325f, -0.688191f},
{0.688191f, 0.587785f, -0.425325f},
{-0.147621f, 0.716567f, -0.681718f},
{-0.309017f, 0.500000f, -0.809017f},
{0.000000f, 0.525731f, -0.850651f},
{-0.525731f, 0.000000f, -0.850651f},
{-0.442863f, 0.238856f, -0.864188f},
{-0.295242f, 0.000000f, -0.955423f},
{-0.162460f, 0.262866f, -0.951056f},
{0.000000f, 0.000000f, -1.000000f},
{0.295242f, 0.000000f, -0.955423f},
{0.162460f, 0.262866f, -0.951056f},
{-0.442863f, -0.238856f, -0.864188f},
{-0.309017f, -0.500000f, -0.809017f},
{-0.162460f, -0.262866f, -0.951056f},
{0.000000f, -0.850651f, -0.525731f},
{-0.147621f, -0.716567f, -0.681718f},
{0.147621f, -0.716567f, -0.681718f},
{0.000000f, -0.525731f, -0.850651f},
{0.309017f, -0.500000f, -0.809017f},
{0.442863f, -0.238856f, -0.864188f},
{0.162460f, -0.262866f, -0.951056f},
{0.238856f, -0.864188f, -0.442863f},
{0.500000f, -0.809017f, -0.309017f},
{0.425325f, -0.688191f, -0.587785f},
{0.716567f, -0.681718f, -0.147621f},
{0.688191f, -0.587785f, -0.425325f},
{0.587785f, -0.425325f, -0.688191f},
{0.000000f, -0.955423f, -0.295242f},
{0.000000f, -1.000000f, 0.000000f},
{0.262866f, -0.951056f, -0.162460f},
{0.000000f, -0.850651f, 0.525731f},
{0.000000f, -0.955423f, 0.295242f},
{0.238856f, -0.864188f, 0.442863f},
{0.262866f, -0.951056f, 0.162460f},
{0.500000f, -0.809017f, 0.309017f},
{0.716567f, -0.681718f, 0.147621f},
{0.525731f, -0.850651f, 0.000000f},
{-0.238856f, -0.864188f, -0.442863f},
{-0.500000f, -0.809017f, -0.309017f},
{-0.262866f, -0.951056f, -0.162460f},
{-0.850651f, -0.525731f, 0.000000f},
{-0.716567f, -0.681718f, -0.147621f},
{-0.716567f, -0.681718f, 0.147621f},
{-0.525731f, -0.850651f, 0.000000f},
{-0.500000f, -0.809017f, 0.309017f},
{-0.238856f, -0.864188f, 0.442863f},
{-0.262866f, -0.951056f, 0.162460f},
{-0.864188f, -0.442863f, 0.238856f},
{-0.809017f, -0.309017f, 0.500000f},
{-0.688191f, -0.587785f, 0.425325f},
{-0.681718f, -0.147621f, 0.716567f},
{-0.442863f, -0.238856f, 0.864188f},
{-0.587785f, -0.425325f, 0.688191f},
{-0.309017f, -0.500000f, 0.809017f},
{-0.147621f, -0.716567f, 0.681718f},
{-0.425325f, -0.688191f, 0.587785f},
{-0.162460f, -0.262866f, 0.951056f},
{0.442863f, -0.238856f, 0.864188f},
{0.162460f, -0.262866f, 0.951056f},
{0.309017f, -0.500000f, 0.809017f},
{0.147621f, -0.716567f, 0.681718f},
{0.000000f, -0.525731f, 0.850651f},
{0.425325f, -0.688191f, 0.587785f},
{0.587785f, -0.425325f, 0.688191f},
{0.688191f, -0.587785f, 0.425325f},
{-0.955423f, 0.295242f, 0.000000f},
{-0.951056f, 0.162460f, 0.262866f},
{-1.000000f, 0.000000f, 0.000000f},
{-0.850651f, 0.000000f, 0.525731f},
{-0.955423f, -0.295242f, 0.000000f},
{-0.951056f, -0.162460f, 0.262866f},
{-0.864188f, 0.442863f, -0.238856f},
{-0.951056f, 0.162460f, -0.262866f},
{-0.809017f, 0.309017f, -0.500000f},
{-0.864188f, -0.442863f, -0.238856f},
{-0.951056f, -0.162460f, -0.262866f},
{-0.809017f, -0.309017f, -0.500000f},
{-0.681718f, 0.147621f, -0.716567f},
{-0.681718f, -0.147621f, -0.716567f},
{-0.850651f, 0.000000f, -0.525731f},
{-0.688191f, 0.587785f, -0.425325f},
{-0.587785f, 0.425325f, -0.688191f},
{-0.425325f, 0.688191f, -0.587785f},
{-0.425325f, -0.688191f, -0.587785f},
{-0.587785f, -0.425325f, -0.688191f},
{-0.688191f, -0.587785f, -0.425325f},
};
struct SMD2AnimationType
{
s32 begin;
s32 end;
s32 fps;
};
static const SMD2AnimationType MD2AnimationTypeList[21] =
{
{ 0, 39, 9}, // STAND
{ 40, 45, 10}, // RUN
{ 46, 53, 10}, // ATTACK
{ 54, 57, 7}, // PAIN_A
{ 58, 61, 7}, // PAIN_B
{ 62, 65, 7}, // PAIN_C
{ 66, 71, 7}, // JUMP
{ 72, 83, 7}, // FLIP
{ 84, 94, 7}, // SALUTE
{ 95, 111, 10}, // FALLBACK
{112, 122, 7}, // WAVE
{123, 134, 6}, // POINT
{135, 153, 10}, // CROUCH_STAND
{154, 159, 7}, // CROUCH_WALK
{160, 168, 10}, // CROUCH_ATTACK
{169, 172, 7}, // CROUCH_PAIN
{173, 177, 5}, // CROUCH_DEATH
{178, 183, 7}, // DEATH_FALLBACK
{184, 189, 7}, // DEATH_FALLFORWARD
{190, 197, 7}, // DEATH_FALLBACKSLOW
{198, 198, 5}, // BOOM
};
//! constructor
CAnimatedMeshMD2::CAnimatedMeshMD2()
: InterpolationBuffer(0), InterpolationFirstFrame(-1), InterpolationSecondFrame(-1), InterpolationFrameDiv(0.f)
, FrameList(0), FrameCount(0), FramesPerSecond((f32)(MD2AnimationTypeList[0].fps << MD2_FRAME_SHIFT))
{
#ifdef _DEBUG
IAnimatedMesh::setDebugName("CAnimatedMeshMD2 IAnimatedMesh");
IMesh::setDebugName("CAnimatedMeshMD2 IMesh");
#endif
InterpolationBuffer = new SMeshBuffer;
}
//! destructor
CAnimatedMeshMD2::~CAnimatedMeshMD2()
{
delete [] FrameList;
if (InterpolationBuffer)
InterpolationBuffer->drop();
}
//! returns the amount of frames in milliseconds. If the amount is 1, it is a static (=non animated) mesh.
u32 CAnimatedMeshMD2::getFrameCount() const
{
return FrameCount<<MD2_FRAME_SHIFT;
}
//! returns the animated mesh based on a detail level. 0 is the lowest, 255 the highest detail. Note, that some Meshes will ignore the detail level.
IMesh* CAnimatedMeshMD2::getMesh(s32 frame, s32 detailLevel, s32 startFrameLoop, s32 endFrameLoop)
{
if ((u32)frame > getFrameCount())
frame = (frame % getFrameCount());
if (startFrameLoop == -1 && endFrameLoop == -1)
{
startFrameLoop = 0;
endFrameLoop = getFrameCount();
}
updateInterpolationBuffer(frame, startFrameLoop, endFrameLoop);
return this;
}
//! returns amount of mesh buffers. MD2 meshes only have one buffer
u32 CAnimatedMeshMD2::getMeshBufferCount() const
{
return 1;
}
//! returns pointer to a mesh buffer
IMeshBuffer* CAnimatedMeshMD2::getMeshBuffer(u32 nr) const
{
if (nr == 0)
return InterpolationBuffer;
else
return 0;
}
//! Returns pointer to a mesh buffer which fits a material
IMeshBuffer* CAnimatedMeshMD2::getMeshBuffer(const video::SMaterial &material) const
{
if (InterpolationBuffer->Material == material)
return InterpolationBuffer;
else
return 0;
}
// updates the interpolation buffer
void CAnimatedMeshMD2::updateInterpolationBuffer(s32 frame, s32 startFrameLoop, s32 endFrameLoop)
{
u32 firstFrame, secondFrame;
f32 div;
// TA: resolve missing ipol in loop between end-start
if (endFrameLoop - startFrameLoop == 0)
{
firstFrame = frame>>MD2_FRAME_SHIFT;
secondFrame = frame>>MD2_FRAME_SHIFT;
div = 1.0f;
}
else
{
// key frames
u32 s = startFrameLoop >> MD2_FRAME_SHIFT;
u32 e = endFrameLoop >> MD2_FRAME_SHIFT;
firstFrame = frame >> MD2_FRAME_SHIFT;
secondFrame = core::if_c_a_else_b(firstFrame + 1 > e, s, firstFrame + 1);
firstFrame = core::s32_min(FrameCount - 1, firstFrame);
secondFrame = core::s32_min(FrameCount - 1, secondFrame);
//div = (frame % (1<<MD2_FRAME_SHIFT)) / (f32)(1<<MD2_FRAME_SHIFT);
frame &= (1<<MD2_FRAME_SHIFT) - 1;
div = frame * MD2_FRAME_SHIFT_RECIPROCAL;
}
if ( firstFrame != InterpolationFirstFrame || secondFrame != InterpolationSecondFrame || div != InterpolationFrameDiv )
{
InterpolationFirstFrame = firstFrame;
InterpolationSecondFrame = secondFrame;
InterpolationFrameDiv = div;
video::S3DVertex* target = static_cast<video::S3DVertex*>(InterpolationBuffer->getVertices());
SMD2Vert* first = FrameList[firstFrame].pointer();
SMD2Vert* second = FrameList[secondFrame].pointer();
// interpolate both frames
const u32 count = FrameList[firstFrame].size();
for (u32 i=0; i<count; ++i)
{
const core::vector3df one = core::vector3df(f32(first->Pos.X) * FrameTransforms[firstFrame].scale.X + FrameTransforms[firstFrame].translate.X,
f32(first->Pos.Y) * FrameTransforms[firstFrame].scale.Y + FrameTransforms[firstFrame].translate.Y,
f32(first->Pos.Z) * FrameTransforms[firstFrame].scale.Z + FrameTransforms[firstFrame].translate.Z);
const core::vector3df two = core::vector3df(f32(second->Pos.X) * FrameTransforms[secondFrame].scale.X + FrameTransforms[secondFrame].translate.X,
f32(second->Pos.Y) * FrameTransforms[secondFrame].scale.Y + FrameTransforms[secondFrame].translate.Y,
f32(second->Pos.Z) * FrameTransforms[secondFrame].scale.Z + FrameTransforms[secondFrame].translate.Z);
target->Pos = two.getInterpolated(one, div);
const core::vector3df n1(
Q2_VERTEX_NORMAL_TABLE[first->NormalIdx][0],
Q2_VERTEX_NORMAL_TABLE[first->NormalIdx][2],
Q2_VERTEX_NORMAL_TABLE[first->NormalIdx][1]);
const core::vector3df n2(
Q2_VERTEX_NORMAL_TABLE[second->NormalIdx][0],
Q2_VERTEX_NORMAL_TABLE[second->NormalIdx][2],
Q2_VERTEX_NORMAL_TABLE[second->NormalIdx][1]);
target->Normal = n2.getInterpolated(n1, div);
++target;
++first;
++second;
}
//update bounding box
InterpolationBuffer->setBoundingBox(BoxList[secondFrame].getInterpolated(BoxList[firstFrame], div));
InterpolationBuffer->setDirty();
}
}
//! sets a flag of all contained materials to a new value
void CAnimatedMeshMD2::setMaterialFlag(video::E_MATERIAL_FLAG flag, bool newvalue)
{
InterpolationBuffer->Material.setFlag(flag, newvalue);
}
//! set the hardware mapping hint, for driver
void CAnimatedMeshMD2::setHardwareMappingHint(E_HARDWARE_MAPPING newMappingHint,
E_BUFFER_TYPE buffer)
{
InterpolationBuffer->setHardwareMappingHint(newMappingHint, buffer);
}
//! flags the meshbuffer as changed, reloads hardware buffers
void CAnimatedMeshMD2::setDirty(E_BUFFER_TYPE buffer)
{
InterpolationBuffer->setDirty(buffer);
}
//! returns an axis aligned bounding box
const core::aabbox3d<f32>& CAnimatedMeshMD2::getBoundingBox() const
{
return InterpolationBuffer->BoundingBox;
}
//! set user axis aligned bounding box
void CAnimatedMeshMD2::setBoundingBox(const core::aabbox3df& box)
{
InterpolationBuffer->BoundingBox = box;
}
//! Returns the type of the animated mesh.
E_ANIMATED_MESH_TYPE CAnimatedMeshMD2::getMeshType() const
{
return EAMT_MD2;
}
//! Returns frame loop data for a special MD2 animation type.
void CAnimatedMeshMD2::getFrameLoop(EMD2_ANIMATION_TYPE l,
s32& outBegin, s32& outEnd, s32& outFPS) const
{
if (l < 0 || l >= EMAT_COUNT)
return;
outBegin = MD2AnimationTypeList[l].begin << MD2_FRAME_SHIFT;
outEnd = MD2AnimationTypeList[l].end << MD2_FRAME_SHIFT;
// correct to anim between last->first frame
outEnd += MD2_FRAME_SHIFT == 0 ? 1 : (1 << MD2_FRAME_SHIFT) - 1;
outFPS = MD2AnimationTypeList[l].fps << MD2_FRAME_SHIFT;
}
//! Returns frame loop data for a special MD2 animation type.
bool CAnimatedMeshMD2::getFrameLoop(const c8* name,
s32& outBegin, s32&outEnd, s32& outFPS) const
{
for (u32 i=0; i < AnimationData.size(); ++i)
{
if (AnimationData[i].name == name)
{
outBegin = AnimationData[i].begin << MD2_FRAME_SHIFT;
outEnd = AnimationData[i].end << MD2_FRAME_SHIFT;
outEnd += MD2_FRAME_SHIFT == 0 ? 1 : (1 << MD2_FRAME_SHIFT) - 1;
outFPS = AnimationData[i].fps << MD2_FRAME_SHIFT;
return true;
}
}
return false;
}
//! Returns amount of md2 animations in this file.
s32 CAnimatedMeshMD2::getAnimationCount() const
{
return AnimationData.size();
}
//! Returns name of md2 animation.
const c8* CAnimatedMeshMD2::getAnimationName(s32 nr) const
{
if ((u32)nr >= AnimationData.size())
return 0;
return AnimationData[nr].name.c_str();
}
} // end namespace scene
} // end namespace irr
#endif // _IRR_COMPILE_WITH_MD2_LOADER_

View File

@ -1,158 +0,0 @@
// Copyright (C) 2002-2012 Nikolaus Gebhardt
// This file is part of the "Irrlicht Engine".
// For conditions of distribution and use, see copyright notice in irrlicht.h
#ifndef __C_ANIMATED_MESH_MD2_H_INCLUDED__
#define __C_ANIMATED_MESH_MD2_H_INCLUDED__
#include "IAnimatedMeshMD2.h"
#include "IMesh.h"
#include "CMeshBuffer.h"
#include "IReadFile.h"
#include "S3DVertex.h"
#include "irrArray.h"
#include "irrString.h"
namespace irr
{
namespace scene
{
class CAnimatedMeshMD2 : public IAnimatedMeshMD2
{
public:
//! constructor
CAnimatedMeshMD2();
//! destructor
virtual ~CAnimatedMeshMD2();
//! returns the amount of frames. If the amount is 1, it is a static (=non animated) mesh.
virtual u32 getFrameCount() const _IRR_OVERRIDE_;
//! Gets the default animation speed of the animated mesh.
/** \return Amount of frames per second. If the amount is 0, it is a static, non animated mesh. */
virtual f32 getAnimationSpeed() const _IRR_OVERRIDE_
{
return FramesPerSecond;
}
//! Gets the frame count of the animated mesh.
/** \param fps Frames per second to play the animation with. If the amount is 0, it is not animated.
The actual speed is set in the scene node the mesh is instantiated in.*/
virtual void setAnimationSpeed(f32 fps) _IRR_OVERRIDE_
{
FramesPerSecond=fps;
}
//! returns the animated mesh based on a detail level. 0 is the lowest, 255 the highest detail. Note, that some Meshes will ignore the detail level.
virtual IMesh* getMesh(s32 frame, s32 detailLevel=255, s32 startFrameLoop=-1, s32 endFrameLoop=-1) _IRR_OVERRIDE_;
//! returns amount of mesh buffers.
virtual u32 getMeshBufferCount() const _IRR_OVERRIDE_;
//! returns pointer to a mesh buffer
virtual IMeshBuffer* getMeshBuffer(u32 nr) const _IRR_OVERRIDE_;
//! Returns pointer to a mesh buffer which fits a material
/** \param material: material to search for
\return Returns the pointer to the mesh buffer or
NULL if there is no such mesh buffer. */
virtual IMeshBuffer* getMeshBuffer( const video::SMaterial &material) const _IRR_OVERRIDE_;
//! returns an axis aligned bounding box
virtual const core::aabbox3d<f32>& getBoundingBox() const _IRR_OVERRIDE_;
//! set user axis aligned bounding box
virtual void setBoundingBox( const core::aabbox3df& box) _IRR_OVERRIDE_;
//! sets a flag of all contained materials to a new value
virtual void setMaterialFlag(video::E_MATERIAL_FLAG flag, bool newvalue) _IRR_OVERRIDE_;
//! set the hardware mapping hint, for driver
virtual void setHardwareMappingHint(E_HARDWARE_MAPPING newMappingHint, E_BUFFER_TYPE buffer=EBT_VERTEX_AND_INDEX) _IRR_OVERRIDE_;
//! flags the meshbuffer as changed, reloads hardware buffers
virtual void setDirty(E_BUFFER_TYPE buffer=EBT_VERTEX_AND_INDEX) _IRR_OVERRIDE_;
//! Returns the type of the animated mesh.
virtual E_ANIMATED_MESH_TYPE getMeshType() const _IRR_OVERRIDE_;
//! Returns frame loop data for a special MD2 animation type.
virtual void getFrameLoop(EMD2_ANIMATION_TYPE,
s32& outBegin, s32& outEnd, s32& outFps) const _IRR_OVERRIDE_;
//! Returns frame loop data for a special MD2 animation type.
virtual bool getFrameLoop(const c8* name,
s32& outBegin, s32& outEnd, s32& outFps) const _IRR_OVERRIDE_;
//! Returns amount of md2 animations in this file.
virtual s32 getAnimationCount() const _IRR_OVERRIDE_;
//! Returns name of md2 animation.
//! \param nr: Zero based index of animation.
virtual const c8* getAnimationName(s32 nr) const _IRR_OVERRIDE_;
//
// exposed for loader
//
//! the buffer that contains the most recent animation
SMeshBuffer* InterpolationBuffer;
//! Frames used to calculate InterpolationBuffer
u32 InterpolationFirstFrame, InterpolationSecondFrame;
f32 InterpolationFrameDiv;
//! named animations
struct SAnimationData
{
core::stringc name;
s32 begin;
s32 end;
s32 fps;
};
//! scale and translations for keyframes
struct SKeyFrameTransform
{
core::vector3df scale;
core::vector3df translate;
};
//! md2 vertex data
struct SMD2Vert
{
core::vector3d<u8> Pos;
u8 NormalIdx;
};
//! keyframe transformations
core::array<SKeyFrameTransform> FrameTransforms;
//! keyframe vertex data
core::array<SMD2Vert> *FrameList;
//! bounding boxes for each keyframe
core::array<core::aabbox3d<f32> > BoxList;
//! named animations
core::array< SAnimationData > AnimationData;
u32 FrameCount;
private:
//! updates the interpolation buffer
void updateInterpolationBuffer(s32 frame, s32 startFrame, s32 endFrame);
f32 FramesPerSecond;
};
} // end namespace scene
} // end namespace irr
#endif

View File

@ -1,468 +0,0 @@
// Copyright (C) 2002-2012 Nikolaus Gebhardt / Fabio Concas / Thomas Alten
// This file is part of the "Irrlicht Engine".
// For conditions of distribution and use, see copyright notice in irrlicht.h
#include "IrrCompileConfig.h"
#ifdef _IRR_COMPILE_WITH_MD3_LOADER_
#include "CAnimatedMeshMD3.h"
#include "os.h"
namespace irr
{
namespace scene
{
// byte-align structures
#include "irrpack.h"
//! General properties of a single animation frame.
struct SMD3Frame
{
f32 mins[3]; // bounding box per frame
f32 maxs[3];
f32 position[3]; // position of bounding box
f32 radius; // radius of bounding sphere
c8 creator[16]; // name of frame
} PACK_STRUCT;
//! An attachment point for another MD3 model.
struct SMD3Tag
{
c8 Name[64]; //name of 'tag' as it's usually called in the md3 files try to see it as a sub-mesh/seperate mesh-part.
f32 position[3]; //relative position of tag
f32 rotationMatrix[9]; //3x3 rotation direction of tag
} PACK_STRUCT;
//!Shader
struct SMD3Shader
{
c8 name[64]; // name of shader
s32 shaderIndex;
} PACK_STRUCT;
// Default alignment
#include "irrunpack.h"
//! Constructor
CAnimatedMeshMD3::CAnimatedMeshMD3()
:Mesh(0), IPolShift(0), LoopMode(0), Scaling(1.f)//, FramesPerSecond(25.f)
{
#ifdef _DEBUG
setDebugName("CAnimatedMeshMD3");
#endif
Mesh = new SMD3Mesh();
MeshIPol = new SMesh();
setInterpolationShift(0, 0);
}
//! Destructor
CAnimatedMeshMD3::~CAnimatedMeshMD3()
{
if (Mesh)
Mesh->drop();
if (MeshIPol)
MeshIPol->drop();
}
//! Returns the amount of frames in milliseconds. If the amount is 1, it is a static (=non animated) mesh.
u32 CAnimatedMeshMD3::getFrameCount() const
{
return Mesh->MD3Header.numFrames << IPolShift;
}
//! Rendering Hint
void CAnimatedMeshMD3::setInterpolationShift(u32 shift, u32 loopMode)
{
IPolShift = shift;
LoopMode = loopMode;
}
//! returns amount of mesh buffers.
u32 CAnimatedMeshMD3::getMeshBufferCount() const
{
return MeshIPol->getMeshBufferCount();
}
//! returns pointer to a mesh buffer
IMeshBuffer* CAnimatedMeshMD3::getMeshBuffer(u32 nr) const
{
return MeshIPol->getMeshBuffer(nr);
}
//! Returns pointer to a mesh buffer which fits a material
IMeshBuffer* CAnimatedMeshMD3::getMeshBuffer(const video::SMaterial &material) const
{
return MeshIPol->getMeshBuffer(material);
}
void CAnimatedMeshMD3::setMaterialFlag(video::E_MATERIAL_FLAG flag, bool newvalue)
{
MeshIPol->setMaterialFlag(flag, newvalue);
}
//! set the hardware mapping hint, for driver
void CAnimatedMeshMD3::setHardwareMappingHint(E_HARDWARE_MAPPING newMappingHint,
E_BUFFER_TYPE buffer)
{
MeshIPol->setHardwareMappingHint(newMappingHint, buffer);
}
//! flags the meshbuffer as changed, reloads hardware buffers
void CAnimatedMeshMD3::setDirty(E_BUFFER_TYPE buffer)
{
MeshIPol->setDirty(buffer);
}
//! set user axis aligned bounding box
void CAnimatedMeshMD3::setBoundingBox(const core::aabbox3df& box)
{
MeshIPol->setBoundingBox(box);
}
//! Returns the animated tag list based on a detail level. 0 is the lowest, 255 the highest detail.
SMD3QuaternionTagList *CAnimatedMeshMD3::getTagList(s32 frame, s32 detailLevel, s32 startFrameLoop, s32 endFrameLoop)
{
if (0 == Mesh)
return 0;
getMesh(frame, detailLevel, startFrameLoop, endFrameLoop);
return &TagListIPol;
}
//! Returns the animated mesh based on a detail level. 0 is the lowest, 255 the highest detail.
IMesh* CAnimatedMeshMD3::getMesh(s32 frame, s32 detailLevel, s32 startFrameLoop, s32 endFrameLoop)
{
if (0 == Mesh)
return 0;
//! check if we have the mesh in our private cache
SCacheInfo candidate(frame, startFrameLoop, endFrameLoop);
if (candidate == Current)
return MeshIPol;
startFrameLoop = core::s32_max(0, startFrameLoop >> IPolShift);
endFrameLoop = core::if_c_a_else_b(endFrameLoop < 0, Mesh->MD3Header.numFrames - 1, endFrameLoop >> IPolShift);
const u32 mask = 1 << IPolShift;
s32 frameA;
s32 frameB;
f32 iPol;
if (LoopMode)
{
// correct frame to "pixel center"
frame -= mask >> 1;
// interpolation
iPol = f32(frame & (mask - 1)) * core::reciprocal(f32(mask));
// wrap anim
frame >>= IPolShift;
frameA = core::if_c_a_else_b(frame < startFrameLoop, endFrameLoop, frame);
frameB = core::if_c_a_else_b(frameA + 1 > endFrameLoop, startFrameLoop, frameA + 1);
}
else
{
// correct frame to "pixel center"
frame -= mask >> 1;
iPol = f32(frame & (mask - 1)) * core::reciprocal(f32(mask));
// clamp anim
frame >>= IPolShift;
frameA = core::s32_clamp(frame, startFrameLoop, endFrameLoop);
frameB = core::s32_min(frameA + 1, endFrameLoop);
}
// build current vertex
for (u32 i = 0; i!= Mesh->Buffer.size(); ++i)
{
buildVertexArray(frameA, frameB, iPol,
Mesh->Buffer[i],
(SMeshBufferLightMap*) MeshIPol->getMeshBuffer(i));
}
MeshIPol->recalculateBoundingBox();
// build current tags
buildTagArray(frameA, frameB, iPol);
Current = candidate;
return MeshIPol;
}
//! create a Irrlicht MeshBuffer for a MD3 MeshBuffer
IMeshBuffer * CAnimatedMeshMD3::createMeshBuffer(const SMD3MeshBuffer* source,
io::IFileSystem* fs, video::IVideoDriver * driver)
{
SMeshBufferLightMap * dest = new SMeshBufferLightMap();
dest->Vertices.set_used(source->MeshHeader.numVertices);
dest->Indices.set_used(source->Indices.size());
u32 i;
// fill in static face info
for (i = 0; i < source->Indices.size(); i += 3)
{
dest->Indices[i + 0] = (u16) source->Indices[i + 0];
dest->Indices[i + 1] = (u16) source->Indices[i + 1];
dest->Indices[i + 2] = (u16) source->Indices[i + 2];
}
// fill in static vertex info
for (i = 0; i!= (u32)source->MeshHeader.numVertices; ++i)
{
video::S3DVertex2TCoords &v = dest->Vertices[i];
v.Color = 0xFFFFFFFF;
v.TCoords.X = source->Tex[i].u;
v.TCoords.Y = source->Tex[i].v;
v.TCoords2.X = 0.f;
v.TCoords2.Y = 0.f;
}
// load static texture
u32 pos = 0;
quake3::tTexArray textureArray;
quake3::getTextures(textureArray, source->Shader, pos, fs, driver);
dest->Material.MaterialType = video::EMT_SOLID;
dest->Material.setTexture(0, textureArray[0]);
dest->Material.Lighting = false;
return dest;
}
//! build final mesh's vertices from frames frameA and frameB with linear interpolation.
void CAnimatedMeshMD3::buildVertexArray(u32 frameA, u32 frameB, f32 interpolate,
const SMD3MeshBuffer* source,
SMeshBufferLightMap* dest)
{
const u32 frameOffsetA = frameA * source->MeshHeader.numVertices;
const u32 frameOffsetB = frameB * source->MeshHeader.numVertices;
const f32 scale = (1.f/ 64.f);
for (s32 i = 0; i != source->MeshHeader.numVertices; ++i)
{
video::S3DVertex2TCoords &v = dest->Vertices [ i ];
const SMD3Vertex &vA = source->Vertices [ frameOffsetA + i ];
const SMD3Vertex &vB = source->Vertices [ frameOffsetB + i ];
// position
v.Pos.X = scale * (vA.position[0] + interpolate * (vB.position[0] - vA.position[0]));
v.Pos.Y = scale * (vA.position[2] + interpolate * (vB.position[2] - vA.position[2]));
v.Pos.Z = scale * (vA.position[1] + interpolate * (vB.position[1] - vA.position[1]));
// normal
const core::vector3df nA(quake3::getMD3Normal(vA.normal[0], vA.normal[1]));
const core::vector3df nB(quake3::getMD3Normal(vB.normal[0], vB.normal[1]));
v.Normal.X = nA.X + interpolate * (nB.X - nA.X);
v.Normal.Y = nA.Z + interpolate * (nB.Z - nA.Z);
v.Normal.Z = nA.Y + interpolate * (nB.Y - nA.Y);
}
dest->recalculateBoundingBox();
}
//! build final mesh's tag from frames frameA and frameB with linear interpolation.
void CAnimatedMeshMD3::buildTagArray(u32 frameA, u32 frameB, f32 interpolate)
{
const u32 frameOffsetA = frameA * Mesh->MD3Header.numTags;
const u32 frameOffsetB = frameB * Mesh->MD3Header.numTags;
for (s32 i = 0; i != Mesh->MD3Header.numTags; ++i)
{
SMD3QuaternionTag &d = TagListIPol [ i ];
const SMD3QuaternionTag &qA = Mesh->TagList[ frameOffsetA + i];
const SMD3QuaternionTag &qB = Mesh->TagList[ frameOffsetB + i];
// rotation
d.rotation.slerp(qA.rotation, qB.rotation, interpolate);
// position
d.position.X = qA.position.X + interpolate * (qB.position.X - qA.position.X);
d.position.Y = qA.position.Y + interpolate * (qB.position.Y - qA.position.Y);
d.position.Z = qA.position.Z + interpolate * (qB.position.Z - qA.position.Z);
}
}
/*!
loads a model
*/
bool CAnimatedMeshMD3::loadModelFile(u32 modelIndex, io::IReadFile* file,
io::IFileSystem* fs, video::IVideoDriver* driver)
{
if (!file)
return false;
//! Check MD3Header
{
file->read(&Mesh->MD3Header, sizeof(SMD3Header));
if (strncmp("IDP3", Mesh->MD3Header.headerID, 4))
{
os::Printer::log("MD3 Loader: invalid header");
return false;
}
}
//! store model name
Mesh->Name = file->getFileName();
u32 i;
//! Frame Data (ignore)
#if 0
SMD3Frame frameImport;
file->seek(Mesh->MD3Header.frameStart);
for (i = 0; i != Mesh->MD3Header.numFrames; ++i)
{
file->read(&frameImport, sizeof(frameImport));
}
#endif
//! Tag Data
const u32 totalTags = Mesh->MD3Header.numTags * Mesh->MD3Header.numFrames;
SMD3Tag import;
file->seek(Mesh->MD3Header.tagStart);
Mesh->TagList.set_used(totalTags);
for (i = 0; i != totalTags; ++i)
{
file->read(&import, sizeof(import));
SMD3QuaternionTag &exp = Mesh->TagList[i];
//! tag name
exp.Name = import.Name;
//! position
exp.position.X = import.position[0];
exp.position.Y = import.position[2];
exp.position.Z = import.position[1];
//! construct quaternion from a RH 3x3 Matrix
exp.rotation.set(import.rotationMatrix[7],
0.f,
-import.rotationMatrix[6],
1 + import.rotationMatrix[8]);
exp.rotation.normalize();
}
//! Meshes
u32 offset = Mesh->MD3Header.tagEnd;
for (i = 0; i != (u32)Mesh->MD3Header.numMeshes; ++i)
{
//! construct a new mesh buffer
SMD3MeshBuffer * buf = new SMD3MeshBuffer();
// !read mesh header info
SMD3MeshHeader &meshHeader = buf->MeshHeader;
//! read mesh info
file->seek(offset);
file->read(&meshHeader, sizeof(SMD3MeshHeader));
//! prepare memory
buf->Vertices.set_used(meshHeader.numVertices * Mesh->MD3Header.numFrames);
buf->Indices.set_used(meshHeader.numTriangles * 3);
buf->Tex.set_used(meshHeader.numVertices);
//! read skins (shaders). should be 1 per meshbuffer
SMD3Shader skin;
file->seek(offset + buf->MeshHeader.offset_shaders);
for (s32 g = 0; g != buf->MeshHeader.numShader; ++g)
{
file->read(&skin, sizeof(skin));
io::path name;
cutFilenameExtension(name, skin.name);
name.replace('\\', '/');
buf->Shader = name;
}
//! read texture coordinates
file->seek(offset + buf->MeshHeader.offset_st);
file->read(buf->Tex.pointer(), buf->MeshHeader.numVertices * sizeof(SMD3TexCoord));
//! read vertices
file->seek(offset + meshHeader.vertexStart);
file->read(buf->Vertices.pointer(), Mesh->MD3Header.numFrames * meshHeader.numVertices * sizeof(SMD3Vertex));
//! read indices
file->seek(offset + meshHeader.offset_triangles);
file->read(buf->Indices.pointer(), meshHeader.numTriangles * sizeof(SMD3Face));
//! store meshBuffer
Mesh->Buffer.push_back(buf);
offset += meshHeader.offset_end;
}
// Init Mesh Interpolation
for (i = 0; i != Mesh->Buffer.size(); ++i)
{
IMeshBuffer * buffer = createMeshBuffer(Mesh->Buffer[i], fs, driver);
MeshIPol->addMeshBuffer(buffer);
buffer->drop();
}
MeshIPol->recalculateBoundingBox();
// Init Tag Interpolation
for (i = 0; i != (u32)Mesh->MD3Header.numTags; ++i)
{
TagListIPol.push_back(Mesh->TagList[i]);
}
return true;
}
SMD3Mesh * CAnimatedMeshMD3::getOriginalMesh()
{
return Mesh;
}
//! Returns an axis aligned bounding box
const core::aabbox3d<f32>& CAnimatedMeshMD3::getBoundingBox() const
{
return MeshIPol->BoundingBox;
}
//! Returns the type of the animated mesh.
E_ANIMATED_MESH_TYPE CAnimatedMeshMD3::getMeshType() const
{
return EAMT_MD3;
}
} // end namespace scene
} // end namespace irr
#endif // _IRR_COMPILE_WITH_MD3_LOADER_

View File

@ -1,135 +0,0 @@
// Copyright (C) 2002-2012 Nikolaus Gebhardt / Thomas Alten
// This file is part of the "Irrlicht Engine".
// For conditions of distribution and use, see copyright notice in irrlicht.h
#ifndef __C_ANIMATED_MESH_MD3_H_INCLUDED__
#define __C_ANIMATED_MESH_MD3_H_INCLUDED__
#include "IAnimatedMeshMD3.h"
#include "IReadFile.h"
#include "IFileSystem.h"
#include "irrArray.h"
#include "irrString.h"
#include "SMesh.h"
#include "SMeshBuffer.h"
#include "IQ3Shader.h"
namespace irr
{
namespace scene
{
class CAnimatedMeshMD3 : public IAnimatedMeshMD3
{
public:
//! constructor
CAnimatedMeshMD3();
//! destructor
virtual ~CAnimatedMeshMD3();
//! loads a quake3 md3 file
bool loadModelFile(u32 modelIndex, io::IReadFile* file,
io::IFileSystem* fs, video::IVideoDriver* driver);
// IAnimatedMeshMD3
virtual void setInterpolationShift(u32 shift, u32 loopMode) _IRR_OVERRIDE_;
virtual SMD3Mesh* getOriginalMesh() _IRR_OVERRIDE_;
virtual SMD3QuaternionTagList* getTagList(s32 frame, s32 detailLevel, s32 startFrameLoop, s32 endFrameLoop) _IRR_OVERRIDE_;
//IAnimatedMesh
virtual u32 getFrameCount() const _IRR_OVERRIDE_;
//! Gets the default animation speed of the animated mesh.
/** \return Amount of frames per second. If the amount is 0, it is a static, non animated mesh. */
virtual f32 getAnimationSpeed() const _IRR_OVERRIDE_
{
return FramesPerSecond;
}
//! Gets the frame count of the animated mesh.
/** \param fps Frames per second to play the animation with. If the amount is 0, it is not animated.
The actual speed is set in the scene node the mesh is instantiated in.*/
virtual void setAnimationSpeed(f32 fps) _IRR_OVERRIDE_
{
FramesPerSecond=fps;
}
virtual IMesh* getMesh(s32 frame, s32 detailLevel,
s32 startFrameLoop, s32 endFrameLoop) _IRR_OVERRIDE_;
virtual const core::aabbox3d<f32>& getBoundingBox() const _IRR_OVERRIDE_;
virtual E_ANIMATED_MESH_TYPE getMeshType() const _IRR_OVERRIDE_;
//! returns amount of mesh buffers.
virtual u32 getMeshBufferCount() const _IRR_OVERRIDE_;
//! returns pointer to a mesh buffer
virtual IMeshBuffer* getMeshBuffer(u32 nr) const _IRR_OVERRIDE_;
//! Returns pointer to a mesh buffer which fits a material
virtual IMeshBuffer* getMeshBuffer(const video::SMaterial &material) const _IRR_OVERRIDE_;
virtual void setMaterialFlag(video::E_MATERIAL_FLAG flag, bool newvalue) _IRR_OVERRIDE_;
//! set user axis aligned bounding box
virtual void setBoundingBox(const core::aabbox3df& box) _IRR_OVERRIDE_;
//! set the hardware mapping hint, for driver
virtual void setHardwareMappingHint(E_HARDWARE_MAPPING newMappingHint, E_BUFFER_TYPE buffer=EBT_VERTEX_AND_INDEX) _IRR_OVERRIDE_;
//! flags the meshbuffer as changed, reloads hardware buffers
virtual void setDirty(E_BUFFER_TYPE buffer=EBT_VERTEX_AND_INDEX) _IRR_OVERRIDE_;
private:
//! animates one frame
inline void Animate(u32 frame);
video::SMaterial Material;
//! hold original compressed MD3 Info
SMD3Mesh *Mesh;
u32 IPolShift;
u32 LoopMode;
f32 Scaling;
//! Cache Info
struct SCacheInfo
{
SCacheInfo(s32 frame=-1, s32 start=-1, s32 end=-1 ) :
Frame(frame), startFrameLoop(start),
endFrameLoop(end)
{}
bool operator == ( const SCacheInfo &other ) const
{
return 0 == memcmp ( this, &other, sizeof ( SCacheInfo ) );
}
s32 Frame;
s32 startFrameLoop;
s32 endFrameLoop;
};
SCacheInfo Current;
//! return a Mesh per frame
SMesh* MeshIPol;
SMD3QuaternionTagList TagListIPol;
IMeshBuffer* createMeshBuffer(const SMD3MeshBuffer* source,
io::IFileSystem* fs, video::IVideoDriver* driver);
void buildVertexArray(u32 frameA, u32 frameB, f32 interpolate,
const SMD3MeshBuffer* source,
SMeshBufferLightMap* dest);
void buildTagArray(u32 frameA, u32 frameB, f32 interpolate);
f32 FramesPerSecond;
};
} // end namespace scene
} // end namespace irr
#endif

View File

@ -7,12 +7,6 @@
#include "ISceneManager.h"
#include "S3DVertex.h"
#include "os.h"
#ifdef _IRR_COMPILE_WITH_SHADOW_VOLUME_SCENENODE_
#include "CShadowVolumeSceneNode.h"
#else
#include "IShadowVolumeSceneNode.h"
#endif // _IRR_COMPILE_WITH_SHADOW_VOLUME_SCENENODE_
#include "IAnimatedMeshMD3.h"
#include "CSkinnedMesh.h"
#include "IDummyTransformationSceneNode.h"
#include "IBoneSceneNode.h"
@ -20,6 +14,7 @@
#include "IMesh.h"
#include "IMeshCache.h"
#include "IAnimatedMesh.h"
#include "IFileSystem.h"
#include "quaternion.h"
@ -41,7 +36,7 @@ CAnimatedMeshSceneNode::CAnimatedMeshSceneNode(IAnimatedMesh* mesh,
TransitionTime(0), Transiting(0.f), TransitingBlend(0.f),
JointMode(EJUOR_NONE), JointsUsed(false),
Looping(true), ReadOnlyMaterials(false), RenderFromIdentity(false),
LoopCallBack(0), PassCount(0), Shadow(0), MD3Special(0)
LoopCallBack(0), PassCount(0)
{
#ifdef _DEBUG
setDebugName("CAnimatedMeshSceneNode");
@ -54,15 +49,6 @@ CAnimatedMeshSceneNode::CAnimatedMeshSceneNode(IAnimatedMesh* mesh,
//! destructor
CAnimatedMeshSceneNode::~CAnimatedMeshSceneNode()
{
if (MD3Special)
MD3Special->drop();
if (Mesh)
Mesh->drop();
if (Shadow)
Shadow->drop();
if (LoopCallBack)
LoopCallBack->drop();
}
@ -294,9 +280,6 @@ void CAnimatedMeshSceneNode::render()
driver->setTransform(video::ETS_WORLD, AbsoluteTransformation);
if (Shadow && PassCount==1)
Shadow->updateShadowVolumes();
// for debug purposes only:
bool renderMeshes = true;
@ -416,40 +399,6 @@ void CAnimatedMeshSceneNode::render()
}
}
}
// show tag for quake3 models
if (Mesh->getMeshType() == EAMT_MD3)
{
IAnimatedMesh * arrow =
SceneManager->addArrowMesh (
"__tag_show",
0xFF0000FF, 0xFF000088,
4, 8, 5.f, 4.f, 0.5f,
1.f);
if (!arrow)
{
arrow = SceneManager->getMesh ( "__tag_show" );
}
IMesh *arrowMesh = arrow->getMesh(0);
core::matrix4 matr;
SMD3QuaternionTagList *taglist = ((IAnimatedMeshMD3*)Mesh)->getTagList(
(s32)getFrameNr(), 255,
getStartFrame(), getEndFrame());
if (taglist)
{
for ( u32 ts = 0; ts != taglist->size(); ++ts )
{
(*taglist)[ts].setto(matr);
driver->setTransform(video::ETS_WORLD, matr );
for ( u32 a = 0; a != arrowMesh->getMeshBufferCount(); ++a )
driver->drawMeshBuffer(arrowMesh->getMeshBuffer(a));
}
}
}
}
// show mesh
@ -550,28 +499,6 @@ u32 CAnimatedMeshSceneNode::getMaterialCount() const
}
//! Creates shadow volume scene node as child of this node
//! and returns a pointer to it.
IShadowVolumeSceneNode* CAnimatedMeshSceneNode::addShadowVolumeSceneNode(
const IMesh* shadowMesh, s32 id, bool zfailmethod, f32 infinity)
{
#ifdef _IRR_COMPILE_WITH_SHADOW_VOLUME_SCENENODE_
if (!SceneManager->getVideoDriver()->queryFeature(video::EVDF_STENCIL_BUFFER))
return 0;
if (!shadowMesh)
shadowMesh = Mesh; // if null is given, use the mesh of node
if (Shadow)
Shadow->drop();
Shadow = new CShadowVolumeSceneNode(shadowMesh, this, SceneManager, id, zfailmethod, infinity);
return Shadow;
#else
return 0;
#endif
}
//! Returns a pointer to a child node, which has the same transformation as
//! the corresponding joint, if the mesh in this scene node is a skinned mesh.
IBoneSceneNode* CAnimatedMeshSceneNode::getJointNode(const c8* jointName)
@ -660,12 +587,6 @@ u32 CAnimatedMeshSceneNode::getJointCount() const
//! or to remove attached childs.
bool CAnimatedMeshSceneNode::removeChild(ISceneNode* child)
{
if (child && Shadow == child)
{
Shadow->drop();
Shadow = 0;
}
if (ISceneNode::removeChild(child))
{
if (JointsUsed) //stop weird bugs caused while changing parents as the joints are being created
@ -686,41 +607,6 @@ bool CAnimatedMeshSceneNode::removeChild(ISceneNode* child)
}
//! Starts a MD2 animation.
bool CAnimatedMeshSceneNode::setMD2Animation(EMD2_ANIMATION_TYPE anim)
{
if (!Mesh || Mesh->getMeshType() != EAMT_MD2)
return false;
IAnimatedMeshMD2* md = (IAnimatedMeshMD2*)Mesh;
s32 begin, end, speed;
md->getFrameLoop(anim, begin, end, speed);
setAnimationSpeed( f32(speed) );
setFrameLoop(begin, end);
return true;
}
//! Starts a special MD2 animation.
bool CAnimatedMeshSceneNode::setMD2Animation(const c8* animationName)
{
if (!Mesh || Mesh->getMeshType() != EAMT_MD2)
return false;
IAnimatedMeshMD2* md = (IAnimatedMeshMD2*)Mesh;
s32 begin, end, speed;
if (!md->getFrameLoop(animationName, begin, end, speed))
return false;
setAnimationSpeed( (f32)speed );
setFrameLoop(begin, end);
return true;
}
//! Sets looping mode which is on by default. If set to false,
//! animations will not be looped.
void CAnimatedMeshSceneNode::setLoopMode(bool playAnimationLooped)
@ -863,50 +749,10 @@ void CAnimatedMeshSceneNode::setMesh(IAnimatedMesh* mesh)
}
// returns the absolute transformation for a special MD3 Tag if the mesh is a md3 mesh,
// or the absolutetransformation if it's a normal scenenode
const SMD3QuaternionTag* CAnimatedMeshSceneNode::getMD3TagTransformation(const core::stringc& tagname)
{
return MD3Special ? MD3Special->AbsoluteTagList.get(tagname) : 0;
}
//! updates the absolute position based on the relative and the parents position
void CAnimatedMeshSceneNode::updateAbsolutePosition()
{
IAnimatedMeshSceneNode::updateAbsolutePosition();
if (!Mesh || Mesh->getMeshType() != EAMT_MD3)
return;
SMD3QuaternionTagList *taglist;
taglist = ( (IAnimatedMeshMD3*) Mesh )->getTagList ( (s32)getFrameNr(),255,getStartFrame (),getEndFrame () );
if (taglist)
{
if (!MD3Special)
{
MD3Special = new SMD3Special();
}
SMD3QuaternionTag parent ( MD3Special->Tagname );
if (Parent && Parent->getType() == ESNT_ANIMATED_MESH)
{
const SMD3QuaternionTag * p = ((IAnimatedMeshSceneNode*) Parent)->getMD3TagTransformation
( MD3Special->Tagname );
if (p)
parent = *p;
}
SMD3QuaternionTag relative( RelativeTranslation, RelativeRotation );
MD3Special->AbsoluteTagList.set_used ( taglist->size () );
for ( u32 i=0; i!= taglist->size (); ++i )
{
MD3Special->AbsoluteTagList[i].position = parent.position + (*taglist)[i].position + relative.position;
MD3Special->AbsoluteTagList[i].rotation = parent.rotation * (*taglist)[i].rotation * relative.rotation;
}
}
}
//! Set the joint update mode (0-unused, 1-get joints only, 2-set joints only, 3-move and set)
@ -1110,13 +956,9 @@ ISceneNode* CAnimatedMeshSceneNode::clone(ISceneNode* newParent, ISceneManager*
if (newNode->LoopCallBack)
newNode->LoopCallBack->grab();
newNode->PassCount = PassCount;
newNode->Shadow = Shadow;
if (newNode->Shadow)
newNode->Shadow->grab();
newNode->JointChildSceneNodes = JointChildSceneNodes;
newNode->PretransitingSave = PretransitingSave;
newNode->RenderFromIdentity = RenderFromIdentity;
newNode->MD3Special = MD3Special;
return newNode;
}

View File

@ -78,11 +78,6 @@ namespace scene
//! returns amount of materials used by this scene node.
virtual u32 getMaterialCount() const _IRR_OVERRIDE_;
//! Creates shadow volume scene node as child of this node
//! and returns a pointer to it.
virtual IShadowVolumeSceneNode* addShadowVolumeSceneNode(const IMesh* shadowMesh,
s32 id, bool zfailmethod=true, f32 infinity=1000.0f) _IRR_OVERRIDE_;
//! Returns a pointer to a child node, which has the same transformation as
//! the corresponding joint, if the mesh in this scene node is a skinned mesh.
virtual IBoneSceneNode* getJointNode(const c8* jointName) _IRR_OVERRIDE_;
@ -98,12 +93,6 @@ namespace scene
//! or to remove attached child.
virtual bool removeChild(ISceneNode* child) _IRR_OVERRIDE_;
//! Starts a MD2 animation.
virtual bool setMD2Animation(EMD2_ANIMATION_TYPE anim) _IRR_OVERRIDE_;
//! Starts a special MD2 animation.
virtual bool setMD2Animation(const c8* animationName) _IRR_OVERRIDE_;
//! Returns the current displayed frame number.
virtual f32 getFrameNr() const _IRR_OVERRIDE_;
//! Returns the current start frame number.
@ -134,10 +123,6 @@ namespace scene
//! Returns type of the scene node
virtual ESCENE_NODE_TYPE getType() const _IRR_OVERRIDE_ { return ESNT_ANIMATED_MESH; }
// returns the absolute transformation for a special MD3 Tag if the mesh is a md3 mesh,
// or the absolutetransformation if it's a normal scenenode
const SMD3QuaternionTag* getMD3TagTransformation( const core::stringc & tagname) _IRR_OVERRIDE_;
//! updates the absolute position based on the relative and the parents position
virtual void updateAbsolutePosition() _IRR_OVERRIDE_;
@ -195,25 +180,8 @@ namespace scene
IAnimationEndCallBack* LoopCallBack;
s32 PassCount;
IShadowVolumeSceneNode* Shadow;
core::array<IBoneSceneNode* > JointChildSceneNodes;
core::array<core::matrix4> PretransitingSave;
// Quake3 Model
struct SMD3Special : public virtual IReferenceCounted
{
core::stringc Tagname;
SMD3QuaternionTagList AbsoluteTagList;
SMD3Special & operator = (const SMD3Special & copyMe)
{
Tagname = copyMe.Tagname;
AbsoluteTagList = copyMe.AbsoluteTagList;
return *this;
}
};
SMD3Special *MD3Special;
};
} // end namespace scene

View File

@ -10,7 +10,6 @@
#ifdef _IRR_COMPILE_WITH_B3D_LOADER_
#include "CB3DMeshFileLoader.h"
#include "CMeshTextureLoader.h"
#include "IVideoDriver.h"
#include "IFileSystem.h"
@ -33,8 +32,6 @@ CB3DMeshFileLoader::CB3DMeshFileLoader(scene::ISceneManager* smgr)
#ifdef _DEBUG
setDebugName("CB3DMeshFileLoader");
#endif
TextureLoader = new CMeshTextureLoader( SceneManager->getFileSystem(), SceneManager->getVideoDriver() );
}
@ -55,9 +52,6 @@ IAnimatedMesh* CB3DMeshFileLoader::createMesh(io::IReadFile* file)
if (!file)
return 0;
if ( getMeshTextureLoader() )
getMeshTextureLoader()->setMeshFile(file);
B3DFile = file;
AnimatedMesh = new scene::CSkinnedMesh();
ShowWarning = true; // If true a warning is issued if too many textures are used
@ -283,7 +277,6 @@ bool CB3DMeshFileLoader::readChunkMESH(CSkinnedMesh::SJoint *inJoint)
if (brushID!=-1)
{
loadTextures(Materials[brushID]);
meshBuffer->Material=Materials[brushID].Material;
}
@ -467,7 +460,6 @@ bool CB3DMeshFileLoader::readChunkTRIS(scene::SSkinMeshBuffer *meshBuffer, u32 m
if (triangle_brush_id != -1)
{
loadTextures(Materials[triangle_brush_id]);
B3dMaterial = &Materials[triangle_brush_id];
meshBuffer->Material = B3dMaterial->Material;
}
@ -1035,46 +1027,6 @@ bool CB3DMeshFileLoader::readChunkBRUS()
}
void CB3DMeshFileLoader::loadTextures(SB3dMaterial& material) const
{
if ( getMeshTextureLoader() )
{
if ( SceneManager->getParameters()->existsAttribute(B3D_TEXTURE_PATH) )
getMeshTextureLoader()->setTexturePath( SceneManager->getParameters()->getAttributeAsString(B3D_TEXTURE_PATH) );
}
const bool previous32BitTextureFlag = SceneManager->getVideoDriver()->getTextureCreationFlag(video::ETCF_ALWAYS_32_BIT);
SceneManager->getVideoDriver()->setTextureCreationFlag(video::ETCF_ALWAYS_32_BIT, true);
// read texture from disk
// note that mipmaps might be disabled by Flags & 0x8
const bool doMipMaps = SceneManager->getVideoDriver()->getTextureCreationFlag(video::ETCF_CREATE_MIP_MAPS);
for (u32 i=0; i<video::MATERIAL_MAX_TEXTURES; ++i)
{
SB3dTexture* B3dTexture = material.Textures[i];
if (B3dTexture && B3dTexture->TextureName.size() && !material.Material.getTexture(i))
{
if (!SceneManager->getParameters()->getAttributeAsBool(B3D_LOADER_IGNORE_MIPMAP_FLAG))
SceneManager->getVideoDriver()->setTextureCreationFlag(video::ETCF_CREATE_MIP_MAPS, (B3dTexture->Flags & 0x8) ? true:false);
{
video::ITexture* tex = getMeshTextureLoader() ? getMeshTextureLoader()->getTexture(B3dTexture->TextureName) : NULL;
material.Material.setTexture(i, tex);
}
if (material.Textures[i]->Flags & 0x10) // Clamp U
material.Material.TextureLayer[i].TextureWrapU=video::ETC_CLAMP;
if (material.Textures[i]->Flags & 0x20) // Clamp V
material.Material.TextureLayer[i].TextureWrapV=video::ETC_CLAMP;
if (material.Textures[i]->Flags & 0x20) // Clamp R
material.Material.TextureLayer[i].TextureWrapW=video::ETC_CLAMP;
}
}
SceneManager->getVideoDriver()->setTextureCreationFlag(video::ETCF_CREATE_MIP_MAPS, doMipMaps);
SceneManager->getVideoDriver()->setTextureCreationFlag(video::ETCF_ALWAYS_32_BIT, previous32BitTextureFlag);
}
void CB3DMeshFileLoader::readString(core::stringc& newstring)
{
newstring="";

View File

@ -54,8 +54,6 @@ private:
bool readChunkTEXS();
bool readChunkBRUS();
void loadTextures(SB3dMaterial& material) const;
void readString(core::stringc& newstring);
void readFloats(f32* vec, u32 count);

View File

@ -1,107 +0,0 @@
// Copyright (C) 2002-2012 Nikolaus Gebhardt
// This file is part of the "Irrlicht Engine".
// For conditions of distribution and use, see copyright notice in irrlicht.h
#include "IrrCompileConfig.h"
#ifdef _IRR_COMPILE_WITH_BSP_LOADER_
#include "CBSPMeshFileLoader.h"
#include "CQ3LevelMesh.h"
namespace irr
{
namespace scene
{
//! Constructor
CBSPMeshFileLoader::CBSPMeshFileLoader(scene::ISceneManager* smgr,
io::IFileSystem* fs)
: FileSystem(fs), SceneManager(smgr)
{
#ifdef _DEBUG
setDebugName("CBSPMeshFileLoader");
#endif
if (FileSystem)
FileSystem->grab();
}
//! destructor
CBSPMeshFileLoader::~CBSPMeshFileLoader()
{
if (FileSystem)
FileSystem->drop();
}
//! returns true if the file maybe is able to be loaded by this class
//! based on the file extension (e.g. ".bsp")
bool CBSPMeshFileLoader::isALoadableFileExtension(const io::path& filename) const
{
return core::hasFileExtension ( filename, "bsp", "shader", "cfg" );
}
//! creates/loads an animated mesh from the file.
//! \return Pointer to the created mesh. Returns 0 if loading failed.
//! If you no longer need the mesh, you should call IAnimatedMesh::drop().
//! See IReferenceCounted::drop() for more information.
IAnimatedMesh* CBSPMeshFileLoader::createMesh(io::IReadFile* file)
{
s32 type = core::isFileExtension ( file->getFileName(), "bsp", "shader", "cfg" );
CQ3LevelMesh* q = 0;
switch ( type )
{
case 1:
q = new CQ3LevelMesh(FileSystem, SceneManager, LoadParam);
// determine real shaders in LoadParam
if ( 0 == LoadParam.loadAllShaders )
{
q->getShader("scripts/common.shader");
q->getShader("scripts/sfx.shader");
q->getShader("scripts/gfx.shader");
q->getShader("scripts/liquid.shader");
q->getShader("scripts/models.shader");
q->getShader("scripts/walls.shader");
//q->getShader("scripts/sky.shader");
}
if ( q->loadFile(file) )
return q;
q->drop();
break;
case 2:
q = new CQ3LevelMesh(FileSystem, SceneManager,LoadParam);
q->getShader( file );
return q;
break;
case 3:
// load quake 3 loading parameter
if ( file->getFileName() == "levelparameter.cfg" )
{
file->read ( &LoadParam, sizeof ( LoadParam ) );
}
else
{
q = new CQ3LevelMesh(FileSystem, SceneManager,LoadParam);
q->getConfiguration( file );
return q;
}
break;
}
return 0;
}
} // end namespace scene
} // end namespace irr
#endif // _IRR_COMPILE_WITH_BSP_LOADER_

View File

@ -1,52 +0,0 @@
// Copyright (C) 2002-2012 Nikolaus Gebhardt
// This file is part of the "Irrlicht Engine".
// For conditions of distribution and use, see copyright notice in irrlicht.h
#ifndef __C_BSP_MESH_FILE_LOADER_H_INCLUDED__
#define __C_BSP_MESH_FILE_LOADER_H_INCLUDED__
#include "IMeshLoader.h"
#include "IFileSystem.h"
#include "IVideoDriver.h"
#include "ISceneManager.h"
#include "IQ3Shader.h"
namespace irr
{
namespace scene
{
//! Meshloader capable of loading Quake 3 BSP files and shaders
class CBSPMeshFileLoader : public IMeshLoader
{
public:
//! Constructor
CBSPMeshFileLoader(scene::ISceneManager* smgr, io::IFileSystem* fs);
//! destructor
virtual ~CBSPMeshFileLoader();
//! returns true if the file maybe is able to be loaded by this class
//! based on the file extension (e.g. ".bsp")
virtual bool isALoadableFileExtension(const io::path& filename) const _IRR_OVERRIDE_;
//! creates/loads an animated mesh from the file.
//! \return Pointer to the created mesh. Returns 0 if loading failed.
//! If you no longer need the mesh, you should call IAnimatedMesh::drop().
//! See IReferenceCounted::drop() for more information.
virtual IAnimatedMesh* createMesh(io::IReadFile* file) _IRR_OVERRIDE_;
private:
io::IFileSystem* FileSystem;
scene::ISceneManager* SceneManager;
quake3::Q3LevelLoadParameter LoadParam;
};
} // end namespace scene
} // end namespace irr
#endif

View File

@ -67,12 +67,6 @@ void CBoneSceneNode::OnAnimate(u32 timeMs)
{
if (IsVisible)
{
// animate this node with all animators
ISceneNodeAnimatorList::Iterator ait = Animators.begin();
for (; ait != Animators.end(); ++ait)
(*ait)->animateNode(this, timeMs);
// update absolute position
//updateAbsolutePosition();

File diff suppressed because it is too large Load Diff

View File

@ -1,859 +0,0 @@
// Copyright (C) 2002-2012 Nikolaus Gebhardt
// This file is part of the "Irrlicht Engine".
// For conditions of distribution and use, see copyright notice in irrlicht.h
//
// This file was written by Saurav Mohapatra and modified by Nikolaus Gebhardt.
// See CCSMLoader.h for details.
#include "IrrCompileConfig.h"
#ifdef _IRR_COMPILE_WITH_CSM_LOADER_
#include "CCSMLoader.h"
#include "CMeshTextureLoader.h"
#include "os.h"
#include "IFileSystem.h"
#include "IReadFile.h"
#include "ISceneManager.h"
#include "IAttributes.h"
#include "SMesh.h"
#include "IVideoDriver.h"
#include "SAnimatedMesh.h"
#include "SMeshBufferLightMap.h"
#ifdef _DEBUG
#define _IRR_DEBUG_CSM_LOADER_
#endif
namespace irr
{
namespace scene
{
//
// the CSM data types
//
struct color_rgb_t
{
s32 red;
s32 green;
s32 blue;
color_rgb_t() : red(0), green(0), blue(0) {}
void clear() { red=0; green=0; blue=0; }
video::SColor toSColor() const { return video::SColor(255, red, green, blue); }
};
//
// A Binary File Reader
//
struct BinaryFileReader
{
BinaryFileReader(io::IReadFile* pFile) : file(pFile) { }
size_t readBuffer(void* buffer, s32 len)
{
return file->read(buffer,len);
}
s32 readLong();
f32 readFloat();
void readString(core::stringc &str);
void readVec3f(core::vector3df* v);
void readVec2f(core::vector2df* v);
void readColorRGB(color_rgb_t* color);
io::IReadFile *file;
};
//
// The file header
//
class Header
{
public:
enum E_CSM_VERSION
{
VERSION_4 = 4,
VERSION_4_1 = 5
};
Header(){ clear(); }
s32 getVersion() const { return version; }
void clear(){ version = 0; }
void load(BinaryFileReader* pReader)
{
version = pReader->readLong();
}
private:
s32 version;
};
//
// The groups
//
class Group
{
public:
Group(){ clear(); }
~Group(){ clear(); }
void clear();
void load(BinaryFileReader* pReader);
s32 getFlags() const { return flags; }
s32 getParentGroupID() const { return parentGroup; }
const core::stringc& getProperties() const { return props; }
video::SColor getColor() const { return color.toSColor(); }
private:
s32 flags;
s32 parentGroup;
core::stringc props;
color_rgb_t color;
};
//
// The visgroups
//
class VisGroup
{
public:
VisGroup(){ clear(); }
~VisGroup(){ clear(); }
void clear();
void load(BinaryFileReader* pReader);
s32 getFlags() const{ return flags; }
const core::stringc& getName() const{ return name; }
video::SColor getColor() const{ return color.toSColor(); }
private:
core::stringc name;
s32 flags;
color_rgb_t color;
};
//
// Lightmaps
//
class LightMap
{
public:
LightMap() : pixelData(0){ clear(); }
~LightMap(){ clear(); }
void clear();
void load(BinaryFileReader* pReader);
s32 getWidth() const{ return width; }
s32 getHeight() const{ return height; }
s32* getPixelData() const{ return pixelData; }
private:
s32 width;
s32 height;
s32* pixelData;
};
struct Triangle
{
s32 a,b,c;
};
struct Line
{
s32 a,b;
};
class Vertex
{
public:
Vertex(){ clear(); }
~Vertex(){ clear(); }
void clear();
void load(BinaryFileReader* pReader);
const core::vector3df& getPosition() const { return position; }
const core::vector3df& getNormal() const { return normal; }
video::SColor getColor() const { return color.toSColor(); }
const core::vector3df& getTextureCoordinates() const { return texCoords; }
const core::vector3df& getLightMapCoordinates() const { return lmapCoords; }
private:
core::vector3df position;
core::vector3df normal;
color_rgb_t color;
core::vector3df texCoords;
core::vector3df lmapCoords;
};
class Surface
{
public:
Surface() { clear(); }
~Surface(){ clear(); }
void clear();
void load(BinaryFileReader *pReader);
s32 getFlags() const{ return flags; }
const core::stringc& getTextureName() const{ return textureName; }
s32 getLightMapId() const{ return lightMapId; }
const core::vector2df* getUVOffset() const{ return &uvOffset; }
const core::vector2df* getUVScale() const{ return &uvScale; }
f32 getUVRotation() const{ return uvRotation; }
u32 getVertexCount() const{ return vertices.size(); }
const Vertex& getVertexAt(const s32 index) const{ return vertices[index]; }
u32 getTriangleCount() const{ return triangles.size(); }
const Triangle& getTriangleAt(const s32 index) const{ return triangles[index]; }
private:
s32 flags;
core::stringc textureName;
s32 lightMapId;
core::vector2df uvOffset;
core::vector2df uvScale;
f32 uvRotation;
core::array<Vertex> vertices;
core::array<Triangle> triangles;
core::array<Line> lines;
};
class Mesh
{
public:
Mesh(){ clear(); }
~Mesh(){ clear(); }
void clear();
void load(BinaryFileReader* pReader, bool bReadVisGroups);
s32 getFlags() const { return flags; }
s32 getGroupID() const { return groupId; }
const core::stringc& getProperties() const { return props; }
video::SColor getColor() const { return color.toSColor(); }
const core::vector3df* getPosition() const { return &position; }
s32 getVisgroupID() const { return visgroupId; }
s32 getSurfaceCount() const { return surfaces.size(); }
const Surface* getSurfaceAt(const s32 index) const { return surfaces[index]; }
private:
s32 flags;
s32 groupId;
core::stringc props;
color_rgb_t color;
core::vector3df position;
s32 visgroupId;
core::array<Surface*> surfaces;
};
class Entity
{
public:
Entity() { clear(); }
~Entity() { clear(); }
void clear();
void load(BinaryFileReader* pReader);
s32 getVisgroupID() const { return visgroupId; }
s32 getGroupID() const { return groupId; }
const core::stringc& getProperties() const { return props; }
const core::vector3df* getPosition() const { return &position; }
private:
s32 visgroupId;
s32 groupId;
core::stringc props;
core::vector3df position;
};
class CameraData
{
public:
CameraData(){ clear(); }
~CameraData(){ clear(); }
void clear();
void load(BinaryFileReader* pReader);
const core::vector3df* getPosition(){ return &position; }
f32 getPitch(){ return pitch; }
f32 getYaw(){ return yaw; }
private:
core::vector3df position;
f32 pitch;
f32 yaw;
};
//
// A CSM File
//
class CSMFile
{
public:
CSMFile(){ clear(); }
~CSMFile(){ clear(); }
void clear();
void load(BinaryFileReader* pReader);
const Header* getHeader() const{ return &header; }
u32 getGroupCount() const{ return groups.size(); }
const Group* getGroupAt(const s32 index) const{ return groups[index]; }
u32 getVisGroupCount() const{ return visgroups.size(); }
const VisGroup* getVisGroupAt(const s32 index) const{ return visgroups[index]; }
u32 getLightMapCount() const{ return lightmaps.size(); }
const LightMap* getLightMapAt(const s32 index) const { return lightmaps[index]; }
u32 getMeshCount() const{ return meshes.size(); }
const Mesh* getMeshAt(const s32 index) const{ return meshes[index]; }
u32 getEntityCount() const{ return entities.size(); }
const Entity* getEntityAt(const s32 index) const{ return entities[index]; }
const CameraData* getCameraData() const{ return &cameraData; }
private:
Header header;
core::array<Group*> groups;
core::array<VisGroup*> visgroups;
core::array<LightMap*> lightmaps;
core::array<Mesh*> meshes;
core::array<Entity*> entities;
CameraData cameraData;
};
CCSMLoader::CCSMLoader(scene::ISceneManager* manager, io::IFileSystem* fs)
: FileSystem(fs), SceneManager(manager)
{
#ifdef _DEBUG
setDebugName("CCSMLoader");
#endif
TextureLoader = new CMeshTextureLoader( FileSystem, SceneManager->getVideoDriver() );
}
//! returns true if the file maybe is able to be loaded by this class
//! based on the file extension (e.g. ".bsp")
bool CCSMLoader::isALoadableFileExtension(const io::path& filename) const
{
return core::hasFileExtension ( filename, "csm" );
}
//! creates/loads an animated mesh from the file.
IAnimatedMesh* CCSMLoader::createMesh(io::IReadFile* file)
{
if ( getMeshTextureLoader() )
getMeshTextureLoader()->setMeshFile(file);
scene::IMesh* m = createCSMMesh(file);
if (!m)
return 0;
SAnimatedMesh* am = new SAnimatedMesh();
am->Type = EAMT_CSM;
am->addMesh(m);
m->drop();
am->recalculateBoundingBox();
return am;
}
scene::IMesh* CCSMLoader::createCSMMesh(io::IReadFile* file)
{
if (!file)
return 0;
BinaryFileReader reader(file);
CSMFile csmFile;
csmFile.load(&reader);
return createIrrlichtMesh(&csmFile, file->getFileName());
}
scene::IMesh* CCSMLoader::createIrrlichtMesh(const CSMFile* csmFile, const io::path& lmprefix)
{
if ( getMeshTextureLoader() )
{
if ( SceneManager->getParameters()->existsAttribute(CSM_TEXTURE_PATH) )
getMeshTextureLoader()->setTexturePath( SceneManager->getParameters()->getAttributeAsString(CSM_TEXTURE_PATH) );
}
scene::SMesh *pMesh = new scene::SMesh();
video::IVideoDriver* driver = SceneManager->getVideoDriver();
for(u32 l = 0; l<csmFile->getLightMapCount(); l++)
{
const LightMap* lmap = csmFile->getLightMapAt(l);
io::path lmapName = lmprefix;
lmapName += "LMAP_";
lmapName += io::path(l+1);
os::Printer::log("CCSMLoader loading light map", lmapName.c_str());
video::IImage* lmapImg = driver->createImageFromData(
video::ECF_A8R8G8B8,
core::dimension2d<u32>(lmap->getWidth(),lmap->getHeight()),
lmap->getPixelData());
driver->addTexture(lmapName.c_str(), lmapImg);
lmapImg->drop();
}
for(u32 m = 0; m<csmFile->getMeshCount(); m++)
{
const Mesh* mshPtr = csmFile->getMeshAt(m);
for(s32 s = 0; s < mshPtr->getSurfaceCount(); s++)
{
const Surface* surface = mshPtr->getSurfaceAt(s);
video::ITexture* texture = getMeshTextureLoader() ? getMeshTextureLoader()->getTexture(surface->getTextureName()) : NULL;
// same lightmap name as above where they are created
io::path lmapName = lmprefix;
lmapName += "LMAP_";
lmapName += io::path(surface->getLightMapId());
scene::SMeshBufferLightMap *buffer = new scene::SMeshBufferLightMap();
buffer->Material.setTexture(0, texture);
if (surface->getLightMapId())
{
buffer->Material.setTexture(1, driver->getTexture(lmapName));
buffer->Material.Lighting = false;
buffer->Material.MaterialType = video::EMT_LIGHTMAP_ADD;
}
buffer->Vertices.reallocate(surface->getVertexCount());
for(u32 v = 0; v < surface->getVertexCount(); ++v)
{
const Vertex& vtxPtr = surface->getVertexAt(v);
video::S3DVertex2TCoords vtx;
vtx.Pos = vtxPtr.getPosition();
vtx.Normal = vtxPtr.getPosition();
vtx.Color=vtxPtr.getColor();
vtx.TCoords.set(vtxPtr.getTextureCoordinates().X, 1.f-vtxPtr.getTextureCoordinates().Y);
vtx.TCoords2.set(vtxPtr.getLightMapCoordinates().X, 1.f-vtxPtr.getLightMapCoordinates().Y);
buffer->Vertices.push_back(vtx);
}
buffer->Indices.reallocate(surface->getTriangleCount()*3);
for(u32 t = 0; t < surface->getTriangleCount(); ++t)
{
const Triangle& tri = surface->getTriangleAt(t);
buffer->Indices.push_back(tri.c);
buffer->Indices.push_back(tri.b);
buffer->Indices.push_back(tri.a);
}
buffer->recalculateBoundingBox();
pMesh->addMeshBuffer(buffer);
buffer->drop();
}
}
pMesh->recalculateBoundingBox();
return pMesh;
}
void Group::clear()
{
color.clear();
flags = 0;
parentGroup = 0;
props = "";
}
void Group::load(BinaryFileReader* pReader)
{
flags = pReader->readLong();
parentGroup = pReader->readLong();
pReader->readString(props);
pReader->readColorRGB(&color);
}
void VisGroup::clear()
{
color.clear();
flags = 0;
name = "";
}
void VisGroup::load(BinaryFileReader* pReader)
{
pReader->readString(name);
flags = pReader->readLong();
pReader->readColorRGB(&color);
}
void LightMap::clear()
{
delete[] pixelData;
pixelData = 0;
width = height = 0;
}
void LightMap::load(BinaryFileReader* pReader)
{
width = pReader->readLong();
height = pReader->readLong();
pixelData = new s32[width * height];
pReader->readBuffer(pixelData, width * height * sizeof(s32));
}
void Mesh::clear()
{
flags = 0;
groupId = 0;
visgroupId = 0;
props = "";
color.clear();
position.set(0,0,0);
for(u32 s = 0; s < surfaces.size(); s++)
{
delete surfaces[s];
}
surfaces.clear();
}
void Mesh::load(BinaryFileReader* pReader, bool bReadVisGroups)
{
flags = pReader->readLong();
groupId = pReader->readLong();
pReader->readString(props);
pReader->readColorRGB(&color);
pReader->readVec3f(&position);
if(bReadVisGroups)
visgroupId = pReader->readLong();
else
visgroupId = 0;
s32 count = pReader->readLong();
for(s32 i = 0; i < count; i++)
{
Surface* surf = new Surface();
surf->load(pReader);
surfaces.push_back(surf);
}
}
void Surface::clear()
{
flags = 0;
lightMapId = 0;
textureName = "";
uvOffset.set(0.0f,0.0f);
uvScale.set(0.0f,0.0f);
uvRotation = 0.0f;
triangles.clear();
lines.clear();
vertices.clear();
}
void Surface::load(BinaryFileReader* pReader)
{
flags = pReader->readLong();
pReader->readString(textureName);
textureName.replace('\\', '/');
lightMapId = pReader->readLong();
pReader->readVec2f(&uvOffset);
pReader->readVec2f(&uvScale);
uvRotation = pReader->readFloat();
s32 vtxCount = pReader->readLong();
s32 triCount = pReader->readLong();
s32 lineCount = pReader->readLong();
for(s32 v = 0; v < vtxCount; v++)
{
vertices.push_back(Vertex());
vertices.getLast().load(pReader);
}
for(s32 t = 0; t < triCount; t++)
{
Triangle tri;
pReader->readBuffer(&tri, sizeof(tri));
triangles.push_back(tri);
}
for(s32 l = 0; l < lineCount; l++)
{
Line line;
pReader->readBuffer(&line,sizeof(line));
lines.push_back(line);
}
}
void Vertex::clear()
{
position.set(0,0,0);
normal.set(0,0,0);
color.clear();
texCoords.set(0,0,0);
lmapCoords.set(0,0,0);
}
void Vertex::load(BinaryFileReader* pReader)
{
pReader->readVec3f(&position);
pReader->readVec3f(&normal);
pReader->readColorRGB(&color);
pReader->readVec3f(&texCoords);
pReader->readVec3f(&lmapCoords);
}
void Entity::clear()
{
visgroupId = groupId = 0;
props = "";
position.set(0,0,0);
}
void Entity::load(BinaryFileReader* pReader)
{
visgroupId = pReader->readLong();
groupId = pReader->readLong();
pReader->readString(props);
pReader->readVec3f(&position);
}
void CameraData::clear()
{
position.set(0,0,0);
pitch = 0;
yaw = 0;
}
void CameraData::load(BinaryFileReader* pReader)
{
pReader->readVec3f(&position);
pitch = pReader->readFloat();
yaw = pReader->readFloat();
}
void CSMFile::clear()
{
header.clear();
cameraData.clear();
u32 x =0;
for( x= 0; x < groups.size(); x++)
delete groups[x];
groups.clear();
for(x= 0; x < visgroups.size(); x++)
delete visgroups[x];
visgroups.clear();
for(x= 0; x < lightmaps.size(); x++)
delete lightmaps[x];
lightmaps.clear();
for(x= 0; x < meshes.size(); x++)
delete meshes[x];
meshes.clear();
for(x= 0; x < entities.size(); x++)
delete entities[x];
entities.clear();
}
void CSMFile::load(BinaryFileReader* pReader)
{
clear();
header.load(pReader);
//groups
{
const s32 count = pReader->readLong();
#ifdef _IRR_DEBUG_CSM_LOADER_
os::Printer::log("CSM Version", core::stringc(header.getVersion()).c_str());
os::Printer::log("Loading groups. Count", core::stringc(count));
#endif
groups.reallocate(count);
for (s32 i = 0; i < count; i++)
{
Group* grp = new Group();
grp->load(pReader);
groups.push_back(grp);
}
}
const bool bHasVGroups = (header.getVersion() == Header::VERSION_4_1);
if (bHasVGroups)
{
//visgroups
const s32 count = pReader->readLong();
#ifdef _IRR_DEBUG_CSM_LOADER_
os::Printer::log("Loading visgroups. Count", core::stringc(count));
#endif
visgroups.reallocate(count);
for (s32 i = 0; i < count; i++)
{
VisGroup* grp = new VisGroup();
grp->load(pReader);
visgroups.push_back(grp);
}
}
//lightmaps
{
const s32 count = pReader->readLong();
#ifdef _IRR_DEBUG_CSM_LOADER_
os::Printer::log("Loading lightmaps. Count", core::stringc(count));
#endif
lightmaps.reallocate(count);
for(s32 i = 0; i < count; i++)
{
LightMap* lm = new LightMap();
lm->load(pReader);
lightmaps.push_back(lm);
}
}
//meshes
{
const s32 count = pReader->readLong();
#ifdef _IRR_DEBUG_CSM_LOADER_
os::Printer::log("Loading meshes. Count", core::stringc(count));
#endif
meshes.reallocate(count);
for(s32 i = 0; i < count; i++)
{
Mesh* mesh = new Mesh();
mesh->load(pReader,bHasVGroups);
meshes.push_back(mesh);
}
}
//entities
{
const s32 count = pReader->readLong();
#ifdef _IRR_DEBUG_CSM_LOADER_
os::Printer::log("Loading entitites. Count", core::stringc(count));
#endif
entities.reallocate(count);
for(s32 i = 0; i < count; i++)
{
Entity* ent = new Entity();
ent->load(pReader);
entities.push_back(ent);
}
}
//camera data
#ifdef _IRR_DEBUG_CSM_LOADER_
os::Printer::log("Loading camera data.");
#endif
cameraData.load(pReader);
}
s32 BinaryFileReader::readLong()
{
int ret = 0;
readBuffer(&ret,sizeof(int));
#ifdef __BIG_ENDIAN__
ret = os::Byteswap::byteswap(ret);
#endif
return ret;
}
f32 BinaryFileReader::readFloat()
{
float ret = 0;
readBuffer(&ret,sizeof(float));
#ifdef __BIG_ENDIAN__
ret = os::Byteswap::byteswap(ret);
#endif
return ret;
}
void BinaryFileReader::readString(core::stringc &str)
{
str = "";
c8 c;
readBuffer(&c,sizeof(char));
while(c != 0)
{
str += c;
readBuffer(&c,sizeof(char));
}
}
void BinaryFileReader::readVec3f(core::vector3df* v)
{
v->X = readFloat();
v->Y = readFloat();
v->Z = readFloat();
}
void BinaryFileReader::readVec2f(core::vector2df* v)
{
v->X = readFloat();
v->Y = readFloat();
}
void BinaryFileReader::readColorRGB(color_rgb_t* color)
{
readBuffer(color,sizeof(color_rgb_t));
}
} // end namespace
} // end namespace
#endif // _IRR_COMPILE_WITH_CSM_LOADER_

View File

@ -1,81 +0,0 @@
// Copyright (C) 2002-2012 Nikolaus Gebhardt
// This file is part of the "Irrlicht Engine".
// For conditions of distribution and use, see copyright notice in irrlicht.h
//
// This Loader has been originally written by Saurav Mohapatra. I (Nikolaus Gebhardt)
// modified some minor things and integrated it into Irrlicht 0.9. Thanks a lot
// to Saurav Mohapatra for his work on this and that he gave me his permission to
// add it into Irrlicht.
// I did some changes to Saurav Mohapatra's loader, so I'm writing this down here:
// - Replaced all dependencies to STL and stdio with irr:: methods/constructs.
// - Moved everything into namespace irr::scene
// - Replaced logging with Irrlicht's internal logger.
// - Removed dependency to IrrlichtDevice
// - Moved all internal structures into CCSMLoader.cpp
// - Made the texture root parameter dependent on a ISceneManager string parameter
// - removed exceptions
// - Implemented CCCSMLoader as IMeshLoader
// - Fixed some problems with memory leaks
// - Fixed bounding box calculation
//
// The original readme of this file looks like this:
//
// This component provides a loader for the Cartography shop 4.x .csm maps for Irrlicht Engine.
// This is a part of the M_TRIX Project.
// This is licensed under the ZLib/LibPNG license
// The IrrCSM library is written by Saurav Mohapatra.
//
// Features
//
// The IrrCSM library features the following capabilities
//
// * Loads the .csm 4.0 and 4.1 files transparently
// * Presents the loaded file as irr::scene::IAnimatedMesh for easy creation of IOctreeSceneNode
// * Loads the textures given the correct texture root. hence map and textures can be in separate directories
//
// For more information go to http://www.geocities.com/standard_template/irrcsm/downloads.html
#ifndef __CSM_LOADER_H_INCLUDED__
#define __CSM_LOADER_H_INCLUDED__
#include "irrArray.h"
#include "IMesh.h"
#include "irrString.h"
#include "IFileSystem.h"
#include "IMeshLoader.h"
namespace irr
{
namespace scene
{
class CSMFile;
class ISceneManager;
class CCSMLoader : public scene::IMeshLoader
{
public:
CCSMLoader(ISceneManager* manager, io::IFileSystem* fs);
//! returns true if the file maybe is able to be loaded by this class
//! based on the file extension (e.g. ".bsp")
virtual bool isALoadableFileExtension(const io::path& filename) const _IRR_OVERRIDE_;
//! creates/loads an animated mesh from the file.
virtual IAnimatedMesh* createMesh(io::IReadFile* file) _IRR_OVERRIDE_;
private:
scene::IMesh* createCSMMesh(io::IReadFile* file);
scene::IMesh* createIrrlichtMesh(const CSMFile* csmFile, const io::path& lmprefix);
io::IFileSystem* FileSystem;
scene::ISceneManager* SceneManager;
};
} // end namespace
} // end namespace
#endif

View File

@ -110,18 +110,7 @@ const core::matrix4& CCameraSceneNode::getViewMatrixAffector() const
//! for changing their position, look at target or whatever.
bool CCameraSceneNode::OnEvent(const SEvent& event)
{
if (!InputReceiverEnabled)
return false;
// send events to event receiving animators
ISceneNodeAnimatorList::Iterator ait = Animators.begin();
for (; ait != Animators.end(); ++ait)
if ((*ait)->isEventReceiverEnabled() && (*ait)->OnEvent(event))
return true;
// if nobody processed the event, return false
// animators have been deleted; nothing happens here now!
return false;
}
@ -289,9 +278,6 @@ void CCameraSceneNode::updateMatrices()
//! returns the axis aligned bounding box of this node
const core::aabbox3d<f32>& CCameraSceneNode::getBoundingBox() const
{
// NOTE: We deliberately don't return the boundingbox of the ViewArea. People can access that already.
// We want to prevent cameras from having their bounding box colliding in the SceneCollisionManager.
// If another boundingbox is ever necessary then please move BoundingBox to ICameraSceneNode and make it accessible (via a setter or an enum with options).
return BoundingBox;
}

View File

@ -1,246 +0,0 @@
// Copyright (C) 2002-2012 Nikolaus Gebhardt
// This file is part of the "Irrlicht Engine".
// For conditions of distribution and use, see copyright notice in irrlicht.h
#include "IrrCompileConfig.h"
#ifdef _IRR_COMPILE_WITH_CUBE_SCENENODE_
#include "CCubeSceneNode.h"
#include "IVideoDriver.h"
#include "ISceneManager.h"
#include "S3DVertex.h"
#include "SMeshBuffer.h"
#include "os.h"
#ifdef _IRR_COMPILE_WITH_SHADOW_VOLUME_SCENENODE_
#include "CShadowVolumeSceneNode.h"
#else
#include "IShadowVolumeSceneNode.h"
#endif // _IRR_COMPILE_WITH_SHADOW_VOLUME_SCENENODE_
namespace irr
{
namespace scene
{
/*
011 111
/6,8------/5 y
/ | / | ^ z
/ | / | | /
010 3,9-------2 | |/
| 7- - -10,4 101 *---->x
| / | /
|/ | /
0------11,1/
000 100
*/
//! constructor
CCubeSceneNode::CCubeSceneNode(f32 size, ISceneNode* parent, ISceneManager* mgr,
s32 id, const core::vector3df& position,
const core::vector3df& rotation, const core::vector3df& scale)
: IMeshSceneNode(parent, mgr, id, position, rotation, scale),
Mesh(0), Shadow(0), Size(size)
{
#ifdef _DEBUG
setDebugName("CCubeSceneNode");
#endif
setSize();
}
CCubeSceneNode::~CCubeSceneNode()
{
if (Shadow)
Shadow->drop();
if (Mesh)
Mesh->drop();
}
void CCubeSceneNode::setSize()
{
if (Mesh)
Mesh->drop();
Mesh = SceneManager->getGeometryCreator()->createCubeMesh(core::vector3df(Size));
}
//! renders the node.
void CCubeSceneNode::render()
{
video::IVideoDriver* driver = SceneManager->getVideoDriver();
driver->setTransform(video::ETS_WORLD, AbsoluteTransformation);
if (Shadow)
Shadow->updateShadowVolumes();
// for debug purposes only:
video::SMaterial mat = Mesh->getMeshBuffer(0)->getMaterial();
// overwrite half transparency
if (DebugDataVisible & scene::EDS_HALF_TRANSPARENCY)
mat.MaterialType = video::EMT_TRANSPARENT_ADD_COLOR;
driver->setMaterial(mat);
driver->drawMeshBuffer(Mesh->getMeshBuffer(0));
// for debug purposes only:
if (DebugDataVisible)
{
video::SMaterial m;
m.Lighting = false;
m.AntiAliasing=0;
driver->setMaterial(m);
if (DebugDataVisible & scene::EDS_BBOX)
{
driver->draw3DBox(Mesh->getMeshBuffer(0)->getBoundingBox(), video::SColor(255,255,255,255));
}
if (DebugDataVisible & scene::EDS_BBOX_BUFFERS)
{
driver->draw3DBox(Mesh->getMeshBuffer(0)->getBoundingBox(),
video::SColor(255,190,128,128));
}
if (DebugDataVisible & scene::EDS_NORMALS)
{
// draw normals
const f32 debugNormalLength = SceneManager->getParameters()->getAttributeAsFloat(DEBUG_NORMAL_LENGTH);
const video::SColor debugNormalColor = SceneManager->getParameters()->getAttributeAsColor(DEBUG_NORMAL_COLOR);
const u32 count = Mesh->getMeshBufferCount();
for (u32 i=0; i != count; ++i)
{
driver->drawMeshBufferNormals(Mesh->getMeshBuffer(i), debugNormalLength, debugNormalColor);
}
}
// show mesh
if (DebugDataVisible & scene::EDS_MESH_WIRE_OVERLAY)
{
m.Wireframe = true;
driver->setMaterial(m);
driver->drawMeshBuffer(Mesh->getMeshBuffer(0));
}
}
}
//! returns the axis aligned bounding box of this node
const core::aabbox3d<f32>& CCubeSceneNode::getBoundingBox() const
{
return Mesh->getMeshBuffer(0)->getBoundingBox();
}
//! Removes a child from this scene node.
//! Implemented here, to be able to remove the shadow properly, if there is one,
//! or to remove attached childs.
bool CCubeSceneNode::removeChild(ISceneNode* child)
{
if (child && Shadow == child)
{
Shadow->drop();
Shadow = 0;
}
return ISceneNode::removeChild(child);
}
//! Creates shadow volume scene node as child of this node
//! and returns a pointer to it.
IShadowVolumeSceneNode* CCubeSceneNode::addShadowVolumeSceneNode(
const IMesh* shadowMesh, s32 id, bool zfailmethod, f32 infinity)
{
#ifdef _IRR_COMPILE_WITH_SHADOW_VOLUME_SCENENODE_
if (!SceneManager->getVideoDriver()->queryFeature(video::EVDF_STENCIL_BUFFER))
return 0;
if (!shadowMesh)
shadowMesh = Mesh; // if null is given, use the mesh of node
if (Shadow)
Shadow->drop();
Shadow = new CShadowVolumeSceneNode(shadowMesh, this, SceneManager, id, zfailmethod, infinity);
return Shadow;
#else
return 0;
#endif
}
void CCubeSceneNode::OnRegisterSceneNode()
{
if (IsVisible)
SceneManager->registerNodeForRendering(this);
ISceneNode::OnRegisterSceneNode();
}
//! returns the material based on the zero based index i.
video::SMaterial& CCubeSceneNode::getMaterial(u32 i)
{
return Mesh->getMeshBuffer(0)->getMaterial();
}
//! returns amount of materials used by this scene node.
u32 CCubeSceneNode::getMaterialCount() const
{
return 1;
}
//! Writes attributes of the scene node.
void CCubeSceneNode::serializeAttributes(io::IAttributes* out, io::SAttributeReadWriteOptions* options) const
{
ISceneNode::serializeAttributes(out, options);
out->addFloat("Size", Size);
}
//! Reads attributes of the scene node.
void CCubeSceneNode::deserializeAttributes(io::IAttributes* in, io::SAttributeReadWriteOptions* options)
{
f32 newSize = in->getAttributeAsFloat("Size");
newSize = core::max_(newSize, 0.0001f);
if (newSize != Size)
{
Size = newSize;
setSize();
}
ISceneNode::deserializeAttributes(in, options);
}
//! Creates a clone of this scene node and its children.
ISceneNode* CCubeSceneNode::clone(ISceneNode* newParent, ISceneManager* newManager)
{
if (!newParent)
newParent = Parent;
if (!newManager)
newManager = SceneManager;
CCubeSceneNode* nb = new CCubeSceneNode(Size, newParent,
newManager, ID, RelativeTranslation);
nb->cloneMembers(this, newManager);
nb->getMaterial(0) = getMaterial(0);
nb->Shadow = Shadow;
if ( nb->Shadow )
nb->Shadow->grab();
if ( newParent )
nb->drop();
return nb;
}
} // end namespace scene
} // end namespace irr
#endif // _IRR_COMPILE_WITH_CUBE_SCENENODE_

View File

@ -1,93 +0,0 @@
// Copyright (C) 2002-2012 Nikolaus Gebhardt
// This file is part of the "Irrlicht Engine".
// For conditions of distribution and use, see copyright notice in irrlicht.h
#ifndef __C_CUBE_SCENE_NODE_H_INCLUDED__
#define __C_CUBE_SCENE_NODE_H_INCLUDED__
#include "IMeshSceneNode.h"
#include "SMesh.h"
namespace irr
{
namespace scene
{
class CCubeSceneNode : public IMeshSceneNode
{
public:
//! constructor
CCubeSceneNode(f32 size, ISceneNode* parent, ISceneManager* mgr, s32 id,
const core::vector3df& position = core::vector3df(0,0,0),
const core::vector3df& rotation = core::vector3df(0,0,0),
const core::vector3df& scale = core::vector3df(1.0f, 1.0f, 1.0f));
virtual ~CCubeSceneNode();
virtual void OnRegisterSceneNode() _IRR_OVERRIDE_;
//! renders the node.
virtual void render() _IRR_OVERRIDE_;
//! returns the axis aligned bounding box of this node
virtual const core::aabbox3d<f32>& getBoundingBox() const _IRR_OVERRIDE_;
//! returns the material based on the zero based index i. To get the amount
//! of materials used by this scene node, use getMaterialCount().
//! This function is needed for inserting the node into the scene hierarchy on a
//! optimal position for minimizing renderstate changes, but can also be used
//! to directly modify the material of a scene node.
virtual video::SMaterial& getMaterial(u32 i) _IRR_OVERRIDE_;
//! returns amount of materials used by this scene node.
virtual u32 getMaterialCount() const _IRR_OVERRIDE_;
//! Returns type of the scene node
virtual ESCENE_NODE_TYPE getType() const _IRR_OVERRIDE_ { return ESNT_CUBE; }
//! Creates shadow volume scene node as child of this node
//! and returns a pointer to it.
virtual IShadowVolumeSceneNode* addShadowVolumeSceneNode(const IMesh* shadowMesh,
s32 id, bool zfailmethod=true, f32 infinity=10000.0f) _IRR_OVERRIDE_;
//! Writes attributes of the scene node.
virtual void serializeAttributes(io::IAttributes* out, io::SAttributeReadWriteOptions* options=0) const _IRR_OVERRIDE_;
//! Reads attributes of the scene node.
virtual void deserializeAttributes(io::IAttributes* in, io::SAttributeReadWriteOptions* options=0) _IRR_OVERRIDE_;
//! Creates a clone of this scene node and its children.
virtual ISceneNode* clone(ISceneNode* newParent=0, ISceneManager* newManager=0) _IRR_OVERRIDE_;
//! Sets a new mesh to display
virtual void setMesh(IMesh* mesh) _IRR_OVERRIDE_ {}
//! Returns the current mesh
virtual IMesh* getMesh(void) _IRR_OVERRIDE_ { return Mesh; }
//! Sets if the scene node should not copy the materials of the mesh but use them in a read only style.
/* In this way it is possible to change the materials a mesh causing all mesh scene nodes
referencing this mesh to change too. */
virtual void setReadOnlyMaterials(bool readonly) _IRR_OVERRIDE_ {}
//! Returns if the scene node should not copy the materials of the mesh but use them in a read only style
virtual bool isReadOnlyMaterials() const _IRR_OVERRIDE_ { return false; }
//! Removes a child from this scene node.
//! Implemented here, to be able to remove the shadow properly, if there is one,
//! or to remove attached child.
virtual bool removeChild(ISceneNode* child) _IRR_OVERRIDE_;
private:
void setSize();
IMesh* Mesh;
IShadowVolumeSceneNode* Shadow;
f32 Size;
};
} // end namespace scene
} // end namespace irr
#endif

File diff suppressed because it is too large Load Diff

View File

@ -1,513 +0,0 @@
// Copyright (C) 2002-2012 Nikolaus Gebhardt
// This file is part of the "Irrlicht Engine".
// For conditions of distribution and use, see copyright notice in irrlicht.h
#ifndef __C_VIDEO_DIRECTX_9_H_INCLUDED__
#define __C_VIDEO_DIRECTX_9_H_INCLUDED__
#include "IrrCompileConfig.h"
#ifdef _IRR_COMPILE_WITH_DIRECT3D_9_
#ifdef _IRR_WINDOWS_
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#endif
#include "CNullDriver.h"
#include "SIrrCreationParameters.h"
#include "IMaterialRendererServices.h"
#if defined(__BORLANDC__) || defined (__BCPLUSPLUS__)
#include "irrMath.h" // needed by borland for sqrtf define
#endif
#include <d3d9.h>
namespace irr
{
namespace video
{
class CD3D9CallBridge;
class CD3D9RenderTarget;
class CD3D9Texture;
class CD3D9Driver : public CNullDriver, IMaterialRendererServices
{
public:
friend class CD3D9CallBridge;
friend class CD3D9RenderTarget;
friend class CD3D9Texture;
//! constructor
CD3D9Driver(const SIrrlichtCreationParameters& params, io::IFileSystem* io);
//! destructor
virtual ~CD3D9Driver();
virtual bool beginScene(u16 clearFlag, SColor clearColor = SColor(255,0,0,0), f32 clearDepth = 1.f, u8 clearStencil = 0,
const SExposedVideoData& videoData = SExposedVideoData(), core::rect<s32>* sourceRect = 0) _IRR_OVERRIDE_;
virtual bool endScene() _IRR_OVERRIDE_;
//! queries the features of the driver, returns true if feature is available
virtual bool queryFeature(E_VIDEO_DRIVER_FEATURE feature) const _IRR_OVERRIDE_;
//! sets transformation
virtual void setTransform(E_TRANSFORMATION_STATE state, const core::matrix4& mat) _IRR_OVERRIDE_;
//! sets a material
virtual void setMaterial(const SMaterial& material) _IRR_OVERRIDE_;
virtual bool setRenderTargetEx(IRenderTarget* target, u16 clearFlag, SColor clearColor = SColor(255,0,0,0),
f32 clearDepth = 1.f, u8 clearStencil = 0) _IRR_OVERRIDE_;
//! sets a viewport
virtual void setViewPort(const core::rect<s32>& area) _IRR_OVERRIDE_;
//! gets the area of the current viewport
virtual const core::rect<s32>& getViewPort() const _IRR_OVERRIDE_;
struct SHWBufferLink_d3d9 : public SHWBufferLink
{
SHWBufferLink_d3d9(const scene::IMeshBuffer *_MeshBuffer):
SHWBufferLink(_MeshBuffer),
vertexBuffer(0), indexBuffer(0),
vertexBufferSize(0), indexBufferSize(0) {}
IDirect3DVertexBuffer9* vertexBuffer;
IDirect3DIndexBuffer9* indexBuffer;
u32 vertexBufferSize;
u32 indexBufferSize;
};
bool updateVertexHardwareBuffer(SHWBufferLink_d3d9 *HWBuffer);
bool updateIndexHardwareBuffer(SHWBufferLink_d3d9 *HWBuffer);
//! updates hardware buffer if needed
virtual bool updateHardwareBuffer(SHWBufferLink *HWBuffer) _IRR_OVERRIDE_;
//! Create hardware buffer from mesh
virtual SHWBufferLink *createHardwareBuffer(const scene::IMeshBuffer* mb) _IRR_OVERRIDE_;
//! Delete hardware buffer (only some drivers can)
virtual void deleteHardwareBuffer(SHWBufferLink *HWBuffer) _IRR_OVERRIDE_;
//! Draw hardware buffer
virtual void drawHardwareBuffer(SHWBufferLink *HWBuffer) _IRR_OVERRIDE_;
//! Create occlusion query.
/** Use node for identification and mesh for occlusion test. */
virtual void addOcclusionQuery(scene::ISceneNode* node,
const scene::IMesh* mesh=0) _IRR_OVERRIDE_;
//! Remove occlusion query.
virtual void removeOcclusionQuery(scene::ISceneNode* node) _IRR_OVERRIDE_;
//! Run occlusion query. Draws mesh stored in query.
/** If the mesh shall not be rendered visible, use
overrideMaterial to disable the color and depth buffer. */
virtual void runOcclusionQuery(scene::ISceneNode* node, bool visible=false) _IRR_OVERRIDE_;
//! Update occlusion query. Retrieves results from GPU.
/** If the query shall not block, set the flag to false.
Update might not occur in this case, though */
virtual void updateOcclusionQuery(scene::ISceneNode* node, bool block=true) _IRR_OVERRIDE_;
//! Return query result.
/** Return value is the number of visible pixels/fragments.
The value is a safe approximation, i.e. can be larger then the
actual value of pixels. */
virtual u32 getOcclusionQueryResult(scene::ISceneNode* node) const _IRR_OVERRIDE_;
//! Create render target.
virtual IRenderTarget* addRenderTarget() _IRR_OVERRIDE_;
//! draws a vertex primitive list
virtual void drawVertexPrimitiveList(const void* vertices, u32 vertexCount,
const void* indexList, u32 primitiveCount,
E_VERTEX_TYPE vType, scene::E_PRIMITIVE_TYPE pType,
E_INDEX_TYPE iType) _IRR_OVERRIDE_;
//! draws a vertex primitive list in 2d
virtual void draw2DVertexPrimitiveList(const void* vertices, u32 vertexCount,
const void* indexList, u32 primitiveCount,
E_VERTEX_TYPE vType, scene::E_PRIMITIVE_TYPE pType,
E_INDEX_TYPE iType) _IRR_OVERRIDE_;
//! draws an 2d image, using a color (if color is other then Color(255,255,255,255)) and the alpha channel of the texture if wanted.
virtual void draw2DImage(const video::ITexture* texture, const core::position2d<s32>& destPos,
const core::rect<s32>& sourceRect, const core::rect<s32>* clipRect = 0,
SColor color=SColor(255,255,255,255), bool useAlphaChannelOfTexture=false) _IRR_OVERRIDE_;
//! Draws a part of the texture into the rectangle.
virtual void draw2DImage(const video::ITexture* texture, const core::rect<s32>& destRect,
const core::rect<s32>& sourceRect, const core::rect<s32>* clipRect = 0,
const video::SColor* const colors=0, bool useAlphaChannelOfTexture=false) _IRR_OVERRIDE_;
//! Draws a set of 2d images, using a color and the alpha channel of the texture.
virtual void draw2DImageBatch(const video::ITexture* texture,
const core::array<core::position2d<s32> >& positions,
const core::array<core::rect<s32> >& sourceRects,
const core::rect<s32>* clipRect=0,
SColor color=SColor(255,255,255,255),
bool useAlphaChannelOfTexture=false) _IRR_OVERRIDE_;
//!Draws an 2d rectangle with a gradient.
virtual void draw2DRectangle(const core::rect<s32>& pos,
SColor colorLeftUp, SColor colorRightUp, SColor colorLeftDown, SColor colorRightDown,
const core::rect<s32>* clip) _IRR_OVERRIDE_;
//! Draws a 2d line.
virtual void draw2DLine(const core::position2d<s32>& start,
const core::position2d<s32>& end,
SColor color=SColor(255,255,255,255)) _IRR_OVERRIDE_;
//! Draws a pixel.
virtual void drawPixel(u32 x, u32 y, const SColor & color) _IRR_OVERRIDE_;
//! Draws a 3d line.
virtual void draw3DLine(const core::vector3df& start,
const core::vector3df& end, SColor color = SColor(255,255,255,255)) _IRR_OVERRIDE_;
//! Draws a 3d box.
virtual void draw3DBox( const core::aabbox3d<f32>& box, SColor color = SColor(255,255,255,255 ) ) _IRR_OVERRIDE_;
//! initialises the Direct3D API
bool initDriver(HWND hwnd, bool pureSoftware);
//! \return Returns the name of the video driver. Example: In case of the DIRECT3D8
//! driver, it would return "Direct3D8.1".
virtual const wchar_t* getName() const _IRR_OVERRIDE_;
//! deletes all dynamic lights there are
virtual void deleteAllDynamicLights() _IRR_OVERRIDE_;
//! adds a dynamic light, returning an index to the light
//! \param light: the light data to use to create the light
//! \return An index to the light, or -1 if an error occurs
virtual s32 addDynamicLight(const SLight& light) _IRR_OVERRIDE_;
//! Turns a dynamic light on or off
//! \param lightIndex: the index returned by addDynamicLight
//! \param turnOn: true to turn the light on, false to turn it off
virtual void turnLightOn(s32 lightIndex, bool turnOn) _IRR_OVERRIDE_;
//! returns the maximal amount of dynamic lights the device can handle
virtual u32 getMaximalDynamicLightAmount() const _IRR_OVERRIDE_;
//! Sets the dynamic ambient light color. The default color is
//! (0,0,0,0) which means it is dark.
//! \param color: New color of the ambient light.
virtual void setAmbientLight(const SColorf& color) _IRR_OVERRIDE_;
//! Draws a shadow volume into the stencil buffer.
virtual void drawStencilShadowVolume(const core::array<core::vector3df>& triangles, bool zfail=true, u32 debugDataVisible=0) _IRR_OVERRIDE_;
//! Fills the stencil shadow with color.
virtual void drawStencilShadow(bool clearStencilBuffer=false,
video::SColor leftUpEdge = video::SColor(0,0,0,0),
video::SColor rightUpEdge = video::SColor(0,0,0,0),
video::SColor leftDownEdge = video::SColor(0,0,0,0),
video::SColor rightDownEdge = video::SColor(0,0,0,0)) _IRR_OVERRIDE_;
//! Returns the maximum amount of primitives (mostly vertices) which
//! the device is able to render with one drawIndexedTriangleList
//! call.
virtual u32 getMaximalPrimitiveCount() const _IRR_OVERRIDE_;
//! Sets the fog mode.
virtual void setFog(SColor color, E_FOG_TYPE fogType, f32 start,
f32 end, f32 density, bool pixelFog, bool rangeFog) _IRR_OVERRIDE_;
//! Only used by the internal engine. Used to notify the driver that
//! the window was resized.
virtual void OnResize(const core::dimension2d<u32>& size) _IRR_OVERRIDE_;
//! Can be called by an IMaterialRenderer to make its work easier.
virtual void setBasicRenderStates(const SMaterial& material, const SMaterial& lastMaterial,
bool resetAllRenderstates) _IRR_OVERRIDE_;
//! Returns type of video driver
virtual E_DRIVER_TYPE getDriverType() const _IRR_OVERRIDE_;
//! Returns the transformation set by setTransform
virtual const core::matrix4& getTransform(E_TRANSFORMATION_STATE state) const _IRR_OVERRIDE_;
//! Get a vertex shader constant index.
virtual s32 getVertexShaderConstantID(const c8* name) _IRR_OVERRIDE_;
//! Get a pixel shader constant index.
virtual s32 getPixelShaderConstantID(const c8* name) _IRR_OVERRIDE_;
//! Sets a vertex shader constant.
virtual void setVertexShaderConstant(const f32* data, s32 startRegister, s32 constantAmount=1) _IRR_OVERRIDE_;
//! Sets a pixel shader constant.
virtual void setPixelShaderConstant(const f32* data, s32 startRegister, s32 constantAmount=1) _IRR_OVERRIDE_;
//! Sets a constant for the vertex shader based on an index.
virtual bool setVertexShaderConstant(s32 index, const f32* floats, int count) _IRR_OVERRIDE_;
//! Int interface for the above.
virtual bool setVertexShaderConstant(s32 index, const s32* ints, int count) _IRR_OVERRIDE_;
//! Uint interface for the above.
virtual bool setVertexShaderConstant(s32 index, const u32* ints, int count) _IRR_OVERRIDE_;
//! Sets a constant for the pixel shader based on an index.
virtual bool setPixelShaderConstant(s32 index, const f32* floats, int count) _IRR_OVERRIDE_;
//! Int interface for the above.
virtual bool setPixelShaderConstant(s32 index, const s32* ints, int count) _IRR_OVERRIDE_;
//! Uint interface for the above.
virtual bool setPixelShaderConstant(s32 index, const u32* ints, int count) _IRR_OVERRIDE_;
//! Returns a pointer to the IVideoDriver interface. (Implementation for
//! IMaterialRendererServices)
virtual IVideoDriver* getVideoDriver() _IRR_OVERRIDE_;
//! Creates a render target texture.
virtual ITexture* addRenderTargetTexture(const core::dimension2d<u32>& size,
const io::path& name, const ECOLOR_FORMAT format = ECF_UNKNOWN) _IRR_OVERRIDE_;
//! Creates a render target texture for a cubemap
ITexture* addRenderTargetTextureCubemap(const irr::u32 sideLen,
const io::path& name, const ECOLOR_FORMAT format) _IRR_OVERRIDE_;
virtual void clearBuffers(u16 flag, SColor color = SColor(255,0,0,0), f32 depth = 1.f, u8 stencil = 0) _IRR_OVERRIDE_;
//! Returns an image created from the last rendered frame.
virtual IImage* createScreenShot(video::ECOLOR_FORMAT format=video::ECF_UNKNOWN, video::E_RENDER_TARGET target=video::ERT_FRAME_BUFFER) _IRR_OVERRIDE_;
//! Set/unset a clipping plane.
virtual bool setClipPlane(u32 index, const core::plane3df& plane, bool enable=false) _IRR_OVERRIDE_;
//! Enable/disable a clipping plane.
virtual void enableClipPlane(u32 index, bool enable) _IRR_OVERRIDE_;
//! Returns the graphics card vendor name.
virtual core::stringc getVendorInfo() _IRR_OVERRIDE_ {return VendorName;}
//! Enable the 2d override material
virtual void enableMaterial2D(bool enable=true) _IRR_OVERRIDE_;
//! Check if the driver was recently reset.
virtual bool checkDriverReset() _IRR_OVERRIDE_ {return DriverWasReset;}
//! Get the current color format of the color buffer
/** \return Color format of the color buffer. */
virtual ECOLOR_FORMAT getColorFormat() const _IRR_OVERRIDE_;
//! Returns the maximum texture size supported.
virtual core::dimension2du getMaxTextureSize() const _IRR_OVERRIDE_;
//! Check if the driver supports creating textures with the given color format
virtual bool queryTextureFormat(ECOLOR_FORMAT format) const _IRR_OVERRIDE_;
//! Used by some SceneNodes to check if a material should be rendered in the transparent render pass
virtual bool needsTransparentRenderPass(const irr::video::SMaterial& material) const _IRR_OVERRIDE_;
//! Get the current color format of the color buffer
/** \return Color format of the color buffer as D3D color value. */
D3DFORMAT getD3DColorFormat() const;
//! Get D3D color format from Irrlicht color format.
D3DFORMAT getD3DFormatFromColorFormat(ECOLOR_FORMAT format) const;
//! Get Irrlicht color format from D3D color format.
ECOLOR_FORMAT getColorFormatFromD3DFormat(D3DFORMAT format) const;
//! Get D3D blending factor.
u32 getD3DBlend(E_BLEND_FACTOR factor) const;
//! Get D3D modulate.
u32 getD3DModulate(E_MODULATE_FUNC func) const;
//! Get bridge calls.
CD3D9CallBridge* getBridgeCalls() const;
private:
//! enumeration for rendering modes such as 2d and 3d for minimizing the switching of renderStates.
enum E_RENDER_MODE
{
ERM_NONE = 0, // no render state has been set yet.
ERM_2D, // 2d drawing rendermode
ERM_3D, // 3d rendering mode
ERM_STENCIL_FILL, // stencil fill mode
ERM_SHADOW_VOLUME_ZFAIL, // stencil volume draw mode
ERM_SHADOW_VOLUME_ZPASS // stencil volume draw mode
};
//! sets right vertex shader
void setVertexShader(video::E_VERTEX_TYPE newType);
//! sets the needed renderstates
bool setRenderStates3DMode();
//! sets the needed renderstates
void setRenderStates2DMode(bool alpha, bool texture, bool alphaChannel);
//! sets the needed renderstates
void setRenderStatesStencilFillMode(bool alpha);
//! sets the needed renderstates
void setRenderStatesStencilShadowMode(bool zfail, u32 debugDataVisible);
//! sets the current Texture
bool setActiveTexture(u32 stage, const video::ITexture* texture);
//! resets the device
bool reset();
//! Try to get back a lost device
bool retrieveDevice(int numTries, int msSleepBetweenTries=100);
virtual ITexture* createDeviceDependentTexture(const io::path& name, IImage* image) _IRR_OVERRIDE_;
virtual ITexture* createDeviceDependentTextureCubemap(const io::path& name, const core::array<IImage*>& image) _IRR_OVERRIDE_;
//! Adds a new material renderer to the VideoDriver, using pixel and/or
//! vertex shaders to render geometry.
s32 addShaderMaterial(const c8* vertexShaderProgram, const c8* pixelShaderProgram,
IShaderConstantSetCallBack* callback,
E_MATERIAL_TYPE baseMaterial, s32 userData) _IRR_OVERRIDE_;
//! Adds a new material renderer to the VideoDriver, based on a high level shading
//! language.
virtual s32 addHighLevelShaderMaterial(
const c8* vertexShaderProgram,
const c8* vertexShaderEntryPointName,
E_VERTEX_SHADER_TYPE vsCompileTarget,
const c8* pixelShaderProgram,
const c8* pixelShaderEntryPointName,
E_PIXEL_SHADER_TYPE psCompileTarget,
const c8* geometryShaderProgram,
const c8* geometryShaderEntryPointName = "main",
E_GEOMETRY_SHADER_TYPE gsCompileTarget = EGST_GS_4_0,
scene::E_PRIMITIVE_TYPE inType = scene::EPT_TRIANGLES,
scene::E_PRIMITIVE_TYPE outType = scene::EPT_TRIANGLE_STRIP,
u32 verticesOut = 0,
IShaderConstantSetCallBack* callback = 0,
E_MATERIAL_TYPE baseMaterial = video::EMT_SOLID,
s32 userData = 0) _IRR_OVERRIDE_;
void createMaterialRenderers();
void draw2D3DVertexPrimitiveList(const void* vertices,
u32 vertexCount, const void* indexList, u32 primitiveCount,
E_VERTEX_TYPE vType, scene::E_PRIMITIVE_TYPE pType,
E_INDEX_TYPE iType, bool is3D);
D3DTEXTUREADDRESS getTextureWrapMode(const u8 clamp);
inline D3DCOLORVALUE colorToD3D(const SColor& col)
{
const f32 f = 1.0f / 255.0f;
D3DCOLORVALUE v;
v.r = col.getRed() * f;
v.g = col.getGreen() * f;
v.b = col.getBlue() * f;
v.a = col.getAlpha() * f;
return v;
}
CD3D9CallBridge* BridgeCalls;
E_RENDER_MODE CurrentRenderMode;
D3DPRESENT_PARAMETERS present;
SMaterial Material, LastMaterial;
bool ResetRenderStates; // bool to make all renderstates be reseted if set.
bool Transformation3DChanged;
const ITexture* CurrentTexture[MATERIAL_MAX_TEXTURES];
bool LastTextureMipMapsAvailable[MATERIAL_MAX_TEXTURES];
core::matrix4 Matrices[ETS_COUNT]; // matrices of the 3d mode we need to restore when we switch back from the 2d mode.
HINSTANCE D3DLibrary;
IDirect3D9* pID3D;
IDirect3DDevice9* pID3DDevice;
IDirect3DSurface9* BackBufferSurface;
IDirect3DSurface9* DepthStencilSurface;
core::array<bool> ActiveRenderTarget;
HWND WindowId;
core::rect<s32>* SceneSourceRect;
D3DCAPS9 Caps;
SIrrlichtCreationParameters Params;
E_VERTEX_TYPE LastVertexType;
core::stringc VendorName;
u16 VendorID;
u32 MaxTextureUnits;
u32 MaxFixedPipelineTextureUnits;
u32 MaxUserClipPlanes;
f32 MaxLightDistance;
s32 LastSetLight;
enum E_CACHE_2D_ATTRIBUTES
{
EC2D_ALPHA = 0x1,
EC2D_TEXTURE = 0x2,
EC2D_ALPHA_CHANNEL = 0x4
};
ECOLOR_FORMAT ColorFormat;
D3DFORMAT D3DColorFormat;
bool DeviceLost;
bool DriverWasReset;
bool OcclusionQuerySupport;
bool AlphaToCoverageSupport;
};
//! This bridge between Irrlicht pseudo D3D9 calls
//! and true D3D9 calls.
class CD3D9CallBridge
{
public:
CD3D9CallBridge(IDirect3DDevice9* p, CD3D9Driver* driver);
// Reset to default state.
void reset();
// Blending calls.
void setBlendOperation(DWORD mode);
void setBlendFunc(DWORD source, DWORD destination);
void setBlendFuncSeparate(DWORD sourceRGB, DWORD destinationRGB, DWORD sourceAlpha, DWORD destinationAlpha);
void setBlend(bool enable);
private:
IDirect3DDevice9* pID3DDevice;
DWORD BlendOperation;
DWORD BlendSourceRGB;
DWORD BlendDestinationRGB;
DWORD BlendSourceAlpha;
DWORD BlendDestinationAlpha;
bool Blend;
bool BlendSeparate;
bool FeatureBlendSeparate;
};
} // end namespace video
} // end namespace irr
#endif // _IRR_COMPILE_WITH_DIRECT3D_9_
#endif // __C_VIDEO_DIRECTX_9_H_INCLUDED__

View File

@ -1,424 +0,0 @@
// Copyright (C) 2002-2012 Nikolaus Gebhardt
// This file is part of the "Irrlicht Engine".
// For conditions of distribution and use, see copyright notice in irrlicht.h
#include "IrrCompileConfig.h"
#ifdef _IRR_COMPILE_WITH_DIRECT3D_9_
#include "CD3D9HLSLMaterialRenderer.h"
#include "IShaderConstantSetCallBack.h"
#include "IVideoDriver.h"
#include "os.h"
#include "irrString.h"
#ifndef _IRR_D3D_NO_SHADER_DEBUGGING
#include <stdio.h>
#endif
namespace irr
{
namespace video
{
//! Public constructor
CD3D9HLSLMaterialRenderer::CD3D9HLSLMaterialRenderer(IDirect3DDevice9* d3ddev,
video::IVideoDriver* driver, s32& outMaterialTypeNr,
const c8* vertexShaderProgram,
const c8* vertexShaderEntryPointName,
E_VERTEX_SHADER_TYPE vsCompileTarget,
const c8* pixelShaderProgram,
const c8* pixelShaderEntryPointName,
E_PIXEL_SHADER_TYPE psCompileTarget,
IShaderConstantSetCallBack* callback,
IMaterialRenderer* baseMaterial,
s32 userData)
: CD3D9ShaderMaterialRenderer(d3ddev, driver, callback, baseMaterial, userData),
VSConstantsTable(0), PSConstantsTable(0)
{
#ifdef _DEBUG
setDebugName("CD3D9HLSLMaterialRenderer");
#endif
outMaterialTypeNr = -1;
// now create shaders
if (vsCompileTarget < 0 || vsCompileTarget > EVST_COUNT)
{
os::Printer::log("Invalid HLSL vertex shader compilation target", ELL_ERROR);
return;
}
if (!createHLSLVertexShader(vertexShaderProgram,
vertexShaderEntryPointName, VERTEX_SHADER_TYPE_NAMES[vsCompileTarget]))
return;
if (!createHLSLPixelShader(pixelShaderProgram,
pixelShaderEntryPointName, PIXEL_SHADER_TYPE_NAMES[psCompileTarget]))
return;
// register myself as new material
outMaterialTypeNr = Driver->addMaterialRenderer(this);
}
//! Destructor
CD3D9HLSLMaterialRenderer::~CD3D9HLSLMaterialRenderer()
{
if (VSConstantsTable)
VSConstantsTable->Release();
if (PSConstantsTable)
PSConstantsTable->Release();
}
bool CD3D9HLSLMaterialRenderer::createHLSLVertexShader(const char* vertexShaderProgram,
const char* shaderEntryPointName,
const char* shaderTargetName)
{
if (!vertexShaderProgram)
return true;
LPD3DXBUFFER buffer = 0;
LPD3DXBUFFER errors = 0;
#ifdef _IRR_D3D_NO_SHADER_DEBUGGING
size_t dataLen_t = strlen(vertexShaderProgram);
UINT dataLen = (UINT)dataLen_t;
if ( dataLen != dataLen_t )
return false;
// compile without debug info
HRESULT h = stubD3DXCompileShader(
vertexShaderProgram,
dataLen,
0, // macros
0, // no includes
shaderEntryPointName,
shaderTargetName,
0, // no flags
&buffer,
&errors,
&VSConstantsTable);
#else
// compile shader and emit some debug information to
// make it possible to debug the shader in visual studio
static int irr_dbg_hlsl_file_nr = 0;
++irr_dbg_hlsl_file_nr;
char tmp[32];
sprintf(tmp, "irr_d3d9_dbg_hlsl_%d.vsh", irr_dbg_hlsl_file_nr);
FILE* f = fopen(tmp, "wb");
fwrite(vertexShaderProgram, strlen(vertexShaderProgram), 1, f);
fflush(f);
fclose(f);
HRESULT h = stubD3DXCompileShaderFromFile(
tmp,
0, // macros
0, // no includes
shaderEntryPointName,
shaderTargetName,
D3DXSHADER_DEBUG | D3DXSHADER_SKIPOPTIMIZATION,
&buffer,
&errors,
&VSConstantsTable);
#endif
if (FAILED(h))
{
os::Printer::log("HLSL vertex shader compilation failed:", ELL_ERROR);
if (errors)
{
os::Printer::log((c8*)errors->GetBufferPointer(), ELL_ERROR);
errors->Release();
if (buffer)
buffer->Release();
}
return false;
}
if (errors)
errors->Release();
if (buffer)
{
if (FAILED(pID3DDevice->CreateVertexShader((DWORD*)buffer->GetBufferPointer(),
&VertexShader)))
{
os::Printer::log("Could not create hlsl vertex shader.", ELL_ERROR);
buffer->Release();
return false;
}
buffer->Release();
return true;
}
return false;
}
bool CD3D9HLSLMaterialRenderer::createHLSLPixelShader(const char* pixelShaderProgram,
const char* shaderEntryPointName,
const char* shaderTargetName)
{
if (!pixelShaderProgram)
return true;
LPD3DXBUFFER buffer = 0;
LPD3DXBUFFER errors = 0;
DWORD flags = 0;
#ifdef D3DXSHADER_ENABLE_BACKWARDS_COMPATIBILITY
if (Driver->queryFeature(video::EVDF_VERTEX_SHADER_2_0) || Driver->queryFeature(video::EVDF_VERTEX_SHADER_3_0))
// this one's for newer DX SDKs which don't support ps_1_x anymore
// instead they'll silently compile 1_x as 2_x when using this flag
flags |= D3DXSHADER_ENABLE_BACKWARDS_COMPATIBILITY;
#endif
#if defined(_IRR_D3D_USE_LEGACY_HLSL_COMPILER) && defined(D3DXSHADER_USE_LEGACY_D3DX9_31_DLL)
#ifdef D3DXSHADER_ENABLE_BACKWARDS_COMPATIBILITY
else
#endif
flags |= D3DXSHADER_USE_LEGACY_D3DX9_31_DLL;
#endif
#ifdef _IRR_D3D_NO_SHADER_DEBUGGING
size_t dataLen_t = strlen(pixelShaderProgram);
UINT dataLen = (UINT)dataLen_t;
if ( dataLen != dataLen_t )
return false;
// compile without debug info
HRESULT h = stubD3DXCompileShader(
pixelShaderProgram,
dataLen,
0, // macros
0, // no includes
shaderEntryPointName,
shaderTargetName,
flags,
&buffer,
&errors,
&PSConstantsTable);
#else
// compile shader and emit some debug information to
// make it possible to debug the shader in visual studio
static int irr_dbg_hlsl_file_nr = 0;
++irr_dbg_hlsl_file_nr;
char tmp[32];
sprintf(tmp, "irr_d3d9_dbg_hlsl_%d.psh", irr_dbg_hlsl_file_nr);
FILE* f = fopen(tmp, "wb");
fwrite(pixelShaderProgram, strlen(pixelShaderProgram), 1, f);
fflush(f);
fclose(f);
HRESULT h = stubD3DXCompileShaderFromFile(
tmp,
0, // macros
0, // no includes
shaderEntryPointName,
shaderTargetName,
flags | D3DXSHADER_DEBUG | D3DXSHADER_SKIPOPTIMIZATION,
&buffer,
&errors,
&PSConstantsTable);
#endif
if (FAILED(h))
{
os::Printer::log("HLSL pixel shader compilation failed:", ELL_ERROR);
if (errors)
{
os::Printer::log((c8*)errors->GetBufferPointer(), ELL_ERROR);
errors->Release();
if (buffer)
buffer->Release();
}
return false;
}
if (errors)
errors->Release();
if (buffer)
{
if (FAILED(pID3DDevice->CreatePixelShader((DWORD*)buffer->GetBufferPointer(),
&PixelShader)))
{
os::Printer::log("Could not create hlsl pixel shader.", ELL_ERROR);
buffer->Release();
return false;
}
buffer->Release();
return true;
}
return false;
}
s32 CD3D9HLSLMaterialRenderer::getVariableID(bool vertexShader, const c8* name)
{
LPD3DXCONSTANTTABLE tbl = vertexShader ? VSConstantsTable : PSConstantsTable;
if (!tbl)
return -1;
D3DXCONSTANTTABLE_DESC tblDesc;
if (!FAILED(tbl->GetDesc(&tblDesc)))
{
for (u32 i = 0; i < tblDesc.Constants; ++i)
{
D3DXHANDLE curConst = tbl->GetConstant(NULL, i);
D3DXCONSTANT_DESC constDesc;
UINT ucount = 1;
if (!FAILED(tbl->GetConstantDesc(curConst, &constDesc, &ucount)))
if(strcmp(name, constDesc.Name) == 0)
return i;
}
}
core::stringc s = "HLSL Variable to get ID not found: '";
s += name;
s += "'. Available variables are:";
os::Printer::log(s.c_str(), ELL_WARNING);
printHLSLVariables(tbl);
return -1;
}
bool CD3D9HLSLMaterialRenderer::setVariable(bool vertexShader, s32 index,
const f32* floats, int count)
{
LPD3DXCONSTANTTABLE tbl = vertexShader ? VSConstantsTable : PSConstantsTable;
if (index < 0 || !tbl)
return false;
// currently we only support top level parameters.
// Should be enough for the beginning. (TODO)
D3DXHANDLE hndl = tbl->GetConstant(NULL, index);
if (!hndl)
return false;
D3DXCONSTANT_DESC Description;
UINT ucount = 1;
tbl->GetConstantDesc(hndl, &Description, &ucount);
if(Description.RegisterSet != D3DXRS_SAMPLER)
{
HRESULT hr = tbl->SetFloatArray(pID3DDevice, hndl, floats, count);
if (FAILED(hr))
{
os::Printer::log("Error setting float array for HLSL variable", ELL_WARNING);
return false;
}
}
return true;
}
bool CD3D9HLSLMaterialRenderer::setVariable(bool vertexShader, s32 index,
const s32* ints, int count)
{
LPD3DXCONSTANTTABLE tbl = vertexShader ? VSConstantsTable : PSConstantsTable;
if (index < 0 || !tbl)
return false;
// currently we only support top level parameters.
// Should be enough for the beginning. (TODO)
D3DXHANDLE hndl = tbl->GetConstant(NULL, index);
if (!hndl)
return false;
D3DXCONSTANT_DESC Description;
UINT ucount = 1;
tbl->GetConstantDesc(hndl, &Description, &ucount);
if(Description.RegisterSet != D3DXRS_SAMPLER)
{
HRESULT hr = tbl->SetIntArray(pID3DDevice, hndl, ints, count);
if (FAILED(hr))
{
os::Printer::log("Error setting int array for HLSL variable", ELL_WARNING);
return false;
}
}
return true;
}
bool CD3D9HLSLMaterialRenderer::setVariable(bool vertexShader, s32 index,
const u32* ints, int count)
{
os::Printer::log("Error DirectX 9 does not support unsigned integer constants in shaders.", ELL_ERROR);
return false;
}
bool CD3D9HLSLMaterialRenderer::OnRender(IMaterialRendererServices* service, E_VERTEX_TYPE vtxtype)
{
if (VSConstantsTable)
VSConstantsTable->SetDefaults(pID3DDevice);
return CD3D9ShaderMaterialRenderer::OnRender(service, vtxtype);
}
void CD3D9HLSLMaterialRenderer::printHLSLVariables(LPD3DXCONSTANTTABLE table)
{
// currently we only support top level parameters.
// Should be enough for the beginning. (TODO)
// print out constant names
D3DXCONSTANTTABLE_DESC tblDesc;
HRESULT hr = table->GetDesc(&tblDesc);
if (!FAILED(hr))
{
for (int i=0; i<(int)tblDesc.Constants; ++i)
{
D3DXCONSTANT_DESC d;
UINT n = 1;
D3DXHANDLE cHndl = table->GetConstant(NULL, i);
if (!FAILED(table->GetConstantDesc(cHndl, &d, &n)))
{
core::stringc s = " '";
s += d.Name;
s += "' Registers:[begin:";
s += (int)d.RegisterIndex;
s += ", count:";
s += (int)d.RegisterCount;
s += "]";
os::Printer::log(s.c_str());
}
}
}
}
} // end namespace video
} // end namespace irr
#endif // _IRR_COMPILE_WITH_DIRECT3D_9_

View File

@ -1,87 +0,0 @@
// Copyright (C) 2002-2012 Nikolaus Gebhardt
// This file is part of the "Irrlicht Engine".
// For conditions of distribution and use, see copyright notice in irrlicht.h
#ifndef __C_D3D9_HLSL_MATERIAL_RENDERER_H_INCLUDED__
#define __C_D3D9_HLSL_MATERIAL_RENDERER_H_INCLUDED__
#include "IrrCompileConfig.h"
#ifdef _IRR_WINDOWS_
#ifdef _IRR_COMPILE_WITH_DIRECT3D_9_
#include "CD3D9ShaderMaterialRenderer.h"
#include "IGPUProgrammingServices.h"
namespace irr
{
namespace video
{
class IVideoDriver;
class IShaderConstantSetCallBack;
class IMaterialRenderer;
//! Class for using vertex and pixel shaders via HLSL with D3D9
class CD3D9HLSLMaterialRenderer : public CD3D9ShaderMaterialRenderer
{
public:
//! Public constructor
CD3D9HLSLMaterialRenderer(IDirect3DDevice9* d3ddev, video::IVideoDriver* driver,
s32& outMaterialTypeNr,
const c8* vertexShaderProgram,
const c8* vertexShaderEntryPointName,
E_VERTEX_SHADER_TYPE vsCompileTarget,
const c8* pixelShaderProgram,
const c8* pixelShaderEntryPointName,
E_PIXEL_SHADER_TYPE psCompileTarget,
IShaderConstantSetCallBack* callback,
IMaterialRenderer* baseMaterial,
s32 userData);
//! Destructor
~CD3D9HLSLMaterialRenderer();
virtual s32 getVariableID(bool vertexShader, const c8* name);
//! sets a variable in the shader.
//! \param vertexShader: True if this should be set in the vertex shader, false if
//! in the pixel shader.
//! \param index: Index of the variable
//! \param floats: Pointer to array of floats
//! \param count: Amount of floats in array.
virtual bool setVariable(bool vertexShader, s32 index, const f32* floats, int count);
//! Int interface for the above.
virtual bool setVariable(bool vertexShader, s32 index, const s32* ints, int count);
//! Uint interface for the above.
virtual bool setVariable(bool vertexShader, s32 index, const u32* ints, int count);
bool OnRender(IMaterialRendererServices* service, E_VERTEX_TYPE vtxtype) _IRR_OVERRIDE_;
protected:
bool createHLSLVertexShader(const char* vertexShaderProgram,
const char* shaderEntryPointName,
const char* shaderTargetName);
bool createHLSLPixelShader(const char* pixelShaderProgram,
const char* shaderEntryPointName,
const char* shaderTargetName);
void printHLSLVariables(LPD3DXCONSTANTTABLE table);
LPD3DXCONSTANTTABLE VSConstantsTable;
LPD3DXCONSTANTTABLE PSConstantsTable;
};
} // end namespace video
} // end namespace irr
#endif
#endif
#endif

View File

@ -1,584 +0,0 @@
// Copyright (C) 2002-2012 Nikolaus Gebhardt
// This file is part of the "Irrlicht Engine".
// For conditions of distribution and use, see copyright notice in irrlicht.h
#ifndef __C_D3D9_MATERIAL_RENDERER_H_INCLUDED__
#define __C_D3D9_MATERIAL_RENDERER_H_INCLUDED__
#include "IrrCompileConfig.h"
#ifdef _IRR_WINDOWS_
#ifdef _IRR_COMPILE_WITH_DIRECT3D_9_
#if defined(__BORLANDC__) || defined (__BCPLUSPLUS__)
#include "irrMath.h" // needed by borland for sqrtf define
#endif
#include <d3d9.h>
#include "IMaterialRenderer.h"
#include "CD3D9Driver.h"
namespace irr
{
namespace video
{
namespace
{
D3DMATRIX UnitMatrixD3D9;
D3DMATRIX SphereMapMatrixD3D9;
inline void setTextureColorStage(IDirect3DDevice9* dev, DWORD i,
DWORD arg1, DWORD op, DWORD arg2)
{
dev->SetTextureStageState(i, D3DTSS_COLOROP, op);
dev->SetTextureStageState(i, D3DTSS_COLORARG1, arg1);
dev->SetTextureStageState(i, D3DTSS_COLORARG2, arg2);
}
inline void setTextureColorStage(IDirect3DDevice9* dev, DWORD i, DWORD arg1)
{
dev->SetTextureStageState(i, D3DTSS_COLOROP, D3DTOP_SELECTARG1);
dev->SetTextureStageState(i, D3DTSS_COLORARG1, arg1);
}
inline void setTextureAlphaStage(IDirect3DDevice9* dev, DWORD i,
DWORD arg1, DWORD op, DWORD arg2)
{
dev->SetTextureStageState(i, D3DTSS_ALPHAOP, op);
dev->SetTextureStageState(i, D3DTSS_ALPHAARG1, arg1);
dev->SetTextureStageState(i, D3DTSS_ALPHAARG2, arg2);
}
inline void setTextureAlphaStage(IDirect3DDevice9* dev, DWORD i, DWORD arg1)
{
dev->SetTextureStageState(i, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1);
dev->SetTextureStageState(i, D3DTSS_ALPHAARG1, arg1);
}
} // anonymous namespace
//! Base class for all internal D3D9 material renderers
class CD3D9MaterialRenderer : public IMaterialRenderer
{
public:
//! Constructor
CD3D9MaterialRenderer(IDirect3DDevice9* d3ddev, CD3D9Driver* driver)
: pID3DDevice(d3ddev), Driver(driver)
{
}
virtual s32 getVariableID(bool vertexShader, const c8* name)
{
os::Printer::log("Invalid material to set variable in.");
return -1;
}
//! sets a variable in the shader.
//! \param vertexShader: True if this should be set in the vertex shader, false if
//! in the pixel shader.
//! \param index: Index of the variable
//! \param floats: Pointer to array of floats
//! \param count: Amount of floats in array.
virtual bool setVariable(bool vertexShader, s32 index, const f32* floats, int count)
{
os::Printer::log("Invalid material to set variable in.");
return false;
}
//! Int interface for the above.
virtual bool setVariable(bool vertexShader, s32 index, const s32* ints, int count)
{
os::Printer::log("Invalid material to set variable in.");
return false;
}
//! Uint interface for the above.
virtual bool setVariable(bool vertexShader, s32 index, const u32* ints, int count)
{
os::Printer::log("Invalid material to set variable in.");
return false;
}
protected:
IDirect3DDevice9* pID3DDevice;
CD3D9Driver* Driver;
};
//! Solid material renderer
class CD3D9MaterialRenderer_SOLID : public CD3D9MaterialRenderer
{
public:
CD3D9MaterialRenderer_SOLID(IDirect3DDevice9* p, CD3D9Driver* d)
: CD3D9MaterialRenderer(p, d) {}
virtual void OnSetMaterial(const SMaterial& material, const SMaterial& lastMaterial,
bool resetAllRenderstates, IMaterialRendererServices* services) _IRR_OVERRIDE_
{
services->setBasicRenderStates(material, lastMaterial, resetAllRenderstates);
if (material.MaterialType != lastMaterial.MaterialType || resetAllRenderstates)
{
setTextureColorStage(pID3DDevice, 0,
D3DTA_TEXTURE, D3DTOP_MODULATE, D3DTA_DIFFUSE);
}
pID3DDevice->SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_DISABLE);
}
};
//! Generic Texture Blend
class CD3D9MaterialRenderer_ONETEXTURE_BLEND : public CD3D9MaterialRenderer
{
public:
CD3D9MaterialRenderer_ONETEXTURE_BLEND(IDirect3DDevice9* p, CD3D9Driver* d)
: CD3D9MaterialRenderer(p, d) {}
virtual void OnSetMaterial(const SMaterial& material, const SMaterial& lastMaterial,
bool resetAllRenderstates, IMaterialRendererServices* services) _IRR_OVERRIDE_
{
services->setBasicRenderStates(material, lastMaterial, resetAllRenderstates);
// if (material.MaterialType != lastMaterial.MaterialType ||
// material.MaterialTypeParam != lastMaterial.MaterialTypeParam ||
// resetAllRenderstates)
{
E_BLEND_FACTOR srcRGBFact,dstRGBFact,srcAlphaFact,dstAlphaFact;
E_MODULATE_FUNC modulate;
u32 alphaSource;
unpack_textureBlendFuncSeparate(srcRGBFact, dstRGBFact, srcAlphaFact, dstAlphaFact, modulate, alphaSource, material.MaterialTypeParam);
Driver->getBridgeCalls()->setBlend(true);
Driver->getBridgeCalls()->setBlendFuncSeparate(Driver->getD3DBlend(srcRGBFact), Driver->getD3DBlend(dstRGBFact),
Driver->getD3DBlend(srcAlphaFact), Driver->getD3DBlend(dstAlphaFact));
setTextureColorStage(pID3DDevice, 0,
D3DTA_TEXTURE, Driver->getD3DModulate(modulate), D3DTA_DIFFUSE);
if (textureBlendFunc_hasAlpha(srcRGBFact) || textureBlendFunc_hasAlpha(dstRGBFact) ||
textureBlendFunc_hasAlpha(srcAlphaFact) || textureBlendFunc_hasAlpha(dstAlphaFact))
{
if (alphaSource==EAS_VERTEX_COLOR)
{
setTextureAlphaStage(pID3DDevice, 0, D3DTA_DIFFUSE);
}
else if (alphaSource==EAS_TEXTURE)
{
setTextureAlphaStage(pID3DDevice, 0, D3DTA_TEXTURE);
}
else
{
setTextureAlphaStage(pID3DDevice, 0,
D3DTA_TEXTURE, D3DTOP_MODULATE, D3DTA_DIFFUSE);
}
}
pID3DDevice->SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_DISABLE);
}
}
virtual void OnUnsetMaterial() _IRR_OVERRIDE_
{
Driver->getBridgeCalls()->setBlend(false);
}
//! Returns if the material is transparent.
/** The scene management needs to know this for being able to sort the
materials by opaque and transparent.
The return value could be optimized, but we'd need to know the
MaterialTypeParam for it. */
virtual bool isTransparent() const _IRR_OVERRIDE_
{
return true;
}
};
//! Solid 2 layer material renderer
class CD3D9MaterialRenderer_SOLID_2_LAYER : public CD3D9MaterialRenderer
{
public:
CD3D9MaterialRenderer_SOLID_2_LAYER(IDirect3DDevice9* p, CD3D9Driver* d)
: CD3D9MaterialRenderer(p, d) {}
virtual void OnSetMaterial(const SMaterial& material, const SMaterial& lastMaterial,
bool resetAllRenderstates, IMaterialRendererServices* services) _IRR_OVERRIDE_
{
services->setBasicRenderStates(material, lastMaterial, resetAllRenderstates);
if (material.MaterialType != lastMaterial.MaterialType || resetAllRenderstates)
{
setTextureColorStage(pID3DDevice, 0, D3DTA_TEXTURE);
pID3DDevice->SetTextureStageState(1, D3DTSS_TEXCOORDINDEX, 0);
pID3DDevice->SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_BLENDDIFFUSEALPHA);
}
}
};
//! Transparent add color material renderer
class CD3D9MaterialRenderer_TRANSPARENT_ADD_COLOR : public CD3D9MaterialRenderer
{
public:
CD3D9MaterialRenderer_TRANSPARENT_ADD_COLOR(IDirect3DDevice9* p, CD3D9Driver* d)
: CD3D9MaterialRenderer(p, d) {}
virtual void OnSetMaterial(const SMaterial& material, const SMaterial& lastMaterial,
bool resetAllRenderstates, IMaterialRendererServices* services) _IRR_OVERRIDE_
{
services->setBasicRenderStates(material, lastMaterial, resetAllRenderstates);
Driver->getBridgeCalls()->setBlend(true);
Driver->getBridgeCalls()->setBlendFunc(D3DBLEND_ONE, D3DBLEND_INVSRCCOLOR);
if (material.MaterialType != lastMaterial.MaterialType || resetAllRenderstates)
{
setTextureColorStage(pID3DDevice, 0,
D3DTA_TEXTURE, D3DTOP_MODULATE, D3DTA_DIFFUSE);
pID3DDevice->SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_DISABLE);
}
}
virtual void OnUnsetMaterial() _IRR_OVERRIDE_
{
Driver->getBridgeCalls()->setBlend(false);
}
//! Returns if the material is transparent. The scene management needs to know this
//! for being able to sort the materials by opaque and transparent.
virtual bool isTransparent() const _IRR_OVERRIDE_
{
return true;
}
};
//! Transparent vertex alpha material renderer
class CD3D9MaterialRenderer_TRANSPARENT_VERTEX_ALPHA : public CD3D9MaterialRenderer
{
public:
CD3D9MaterialRenderer_TRANSPARENT_VERTEX_ALPHA(IDirect3DDevice9* p, CD3D9Driver* d)
: CD3D9MaterialRenderer(p, d) {}
virtual void OnSetMaterial(const SMaterial& material, const SMaterial& lastMaterial,
bool resetAllRenderstates, IMaterialRendererServices* services) _IRR_OVERRIDE_
{
services->setBasicRenderStates(material, lastMaterial, resetAllRenderstates);
Driver->getBridgeCalls()->setBlend(true);
Driver->getBridgeCalls()->setBlendFunc(D3DBLEND_SRCALPHA, D3DBLEND_INVSRCALPHA);
if (material.MaterialType != lastMaterial.MaterialType || resetAllRenderstates)
{
setTextureColorStage(pID3DDevice, 0,
D3DTA_TEXTURE, D3DTOP_MODULATE, D3DTA_DIFFUSE);
setTextureAlphaStage(pID3DDevice, 0, D3DTA_DIFFUSE);
pID3DDevice->SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_DISABLE);
}
}
virtual void OnUnsetMaterial() _IRR_OVERRIDE_
{
Driver->getBridgeCalls()->setBlend(false);
}
//! Returns if the material is transparent. The scene management needs to know this
//! for being able to sort the materials by opaque and transparent.
virtual bool isTransparent() const _IRR_OVERRIDE_
{
return true;
}
};
//! Transparent alpha channel material renderer
class CD3D9MaterialRenderer_TRANSPARENT_ALPHA_CHANNEL : public CD3D9MaterialRenderer
{
public:
CD3D9MaterialRenderer_TRANSPARENT_ALPHA_CHANNEL(IDirect3DDevice9* p, CD3D9Driver* d)
: CD3D9MaterialRenderer(p, d) {}
virtual void OnSetMaterial(const SMaterial& material, const SMaterial& lastMaterial,
bool resetAllRenderstates, IMaterialRendererServices* services) _IRR_OVERRIDE_
{
services->setBasicRenderStates(material, lastMaterial, resetAllRenderstates);
Driver->getBridgeCalls()->setBlend(true);
Driver->getBridgeCalls()->setBlendFunc(D3DBLEND_SRCALPHA, D3DBLEND_INVSRCALPHA);
if (material.MaterialType != lastMaterial.MaterialType || resetAllRenderstates
|| material.MaterialTypeParam != lastMaterial.MaterialTypeParam )
{
setTextureColorStage(pID3DDevice, 0,
D3DTA_TEXTURE, D3DTOP_MODULATE, D3DTA_CURRENT);
setTextureAlphaStage(pID3DDevice, 0, D3DTA_TEXTURE);
pID3DDevice->SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_DISABLE);
pID3DDevice->SetRenderState(D3DRS_ALPHAREF, core::floor32(material.MaterialTypeParam * 255.f));
pID3DDevice->SetRenderState(D3DRS_ALPHAFUNC, D3DCMP_GREATEREQUAL);
pID3DDevice->SetRenderState(D3DRS_ALPHATESTENABLE, TRUE);
}
}
virtual void OnUnsetMaterial() _IRR_OVERRIDE_
{
pID3DDevice->SetRenderState(D3DRS_ALPHATESTENABLE, FALSE);
Driver->getBridgeCalls()->setBlend(false);
}
//! Returns if the material is transparent. The scene management needs to know this
//! for being able to sort the materials by opaque and transparent.
virtual bool isTransparent() const _IRR_OVERRIDE_
{
return true;
}
};
//! Transparent alpha channel material renderer
class CD3D9MaterialRenderer_TRANSPARENT_ALPHA_CHANNEL_REF : public CD3D9MaterialRenderer
{
public:
CD3D9MaterialRenderer_TRANSPARENT_ALPHA_CHANNEL_REF(IDirect3DDevice9* p, CD3D9Driver* d)
: CD3D9MaterialRenderer(p, d) {}
virtual void OnSetMaterial(const SMaterial& material, const SMaterial& lastMaterial,
bool resetAllRenderstates, IMaterialRendererServices* services) _IRR_OVERRIDE_
{
services->setBasicRenderStates(material, lastMaterial, resetAllRenderstates);
if (material.MaterialType != lastMaterial.MaterialType || resetAllRenderstates)
{
setTextureColorStage(pID3DDevice, 0,
D3DTA_TEXTURE, D3DTOP_MODULATE, D3DTA_CURRENT);
setTextureAlphaStage(pID3DDevice, 0, D3DTA_TEXTURE);
pID3DDevice->SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_DISABLE);
// 127 is required by EMT_TRANSPARENT_ALPHA_CHANNEL_REF
pID3DDevice->SetRenderState(D3DRS_ALPHAREF, 127);
pID3DDevice->SetRenderState(D3DRS_ALPHAFUNC, D3DCMP_GREATEREQUAL);
pID3DDevice->SetRenderState(D3DRS_ALPHATESTENABLE, TRUE);
}
}
virtual void OnUnsetMaterial() _IRR_OVERRIDE_
{
pID3DDevice->SetRenderState(D3DRS_ALPHATESTENABLE, FALSE);
}
//! Returns if the material is transparent. The scene management needs to know this
//! for being able to sort the materials by opaque and transparent.
virtual bool isTransparent() const _IRR_OVERRIDE_
{
return false; // this material is not really transparent because it does no blending.
}
};
//! material renderer for all kinds of lightmaps
class CD3D9MaterialRenderer_LIGHTMAP : public CD3D9MaterialRenderer
{
public:
CD3D9MaterialRenderer_LIGHTMAP(IDirect3DDevice9* p, CD3D9Driver* d)
: CD3D9MaterialRenderer(p, d) {}
virtual void OnSetMaterial(const SMaterial& material, const SMaterial& lastMaterial,
bool resetAllRenderstates, IMaterialRendererServices* services) _IRR_OVERRIDE_
{
services->setBasicRenderStates(material, lastMaterial, resetAllRenderstates);
if (material.MaterialType != lastMaterial.MaterialType || resetAllRenderstates)
{
if (material.MaterialType >= EMT_LIGHTMAP_LIGHTING)
{
// with lighting
setTextureColorStage(pID3DDevice, 0,
D3DTA_TEXTURE, D3DTOP_MODULATE, D3DTA_DIFFUSE);
}
else
{
setTextureColorStage(pID3DDevice, 0, D3DTA_TEXTURE);
}
pID3DDevice->SetTextureStageState(1, D3DTSS_TEXCOORDINDEX, 1);
setTextureColorStage(pID3DDevice, 1,
D3DTA_TEXTURE,
(material.MaterialType == EMT_LIGHTMAP_ADD)?
D3DTOP_ADD:
(material.MaterialType == EMT_LIGHTMAP_M4 || material.MaterialType == EMT_LIGHTMAP_LIGHTING_M4)?
D3DTOP_MODULATE4X:
(material.MaterialType == EMT_LIGHTMAP_M2 || material.MaterialType == EMT_LIGHTMAP_LIGHTING_M2)?
D3DTOP_MODULATE2X:
D3DTOP_MODULATE,
D3DTA_CURRENT);
}
}
};
//! material renderer for detail maps
class CD3D9MaterialRenderer_DETAIL_MAP : public CD3D9MaterialRenderer
{
public:
CD3D9MaterialRenderer_DETAIL_MAP(IDirect3DDevice9* p, CD3D9Driver* d)
: CD3D9MaterialRenderer(p, d) {}
virtual void OnSetMaterial(const SMaterial& material, const SMaterial& lastMaterial,
bool resetAllRenderstates, IMaterialRendererServices* services) _IRR_OVERRIDE_
{
services->setBasicRenderStates(material, lastMaterial, resetAllRenderstates);
if (material.MaterialType != lastMaterial.MaterialType || resetAllRenderstates)
{
setTextureColorStage(pID3DDevice, 0,
D3DTA_TEXTURE, D3DTOP_MODULATE, D3DTA_DIFFUSE);
setTextureColorStage(pID3DDevice, 1,
D3DTA_TEXTURE, D3DTOP_ADDSIGNED, D3DTA_CURRENT);
pID3DDevice->SetTextureStageState(1, D3DTSS_TEXCOORDINDEX, 1);
}
}
};
//! sphere map material renderer
class CD3D9MaterialRenderer_SPHERE_MAP : public CD3D9MaterialRenderer
{
public:
CD3D9MaterialRenderer_SPHERE_MAP(IDirect3DDevice9* p, CD3D9Driver* d)
: CD3D9MaterialRenderer(p, d) {}
virtual void OnSetMaterial(const SMaterial& material, const SMaterial& lastMaterial,
bool resetAllRenderstates, IMaterialRendererServices* services) _IRR_OVERRIDE_
{
services->setBasicRenderStates(material, lastMaterial, resetAllRenderstates);
if (material.MaterialType != lastMaterial.MaterialType || resetAllRenderstates)
{
setTextureColorStage(pID3DDevice, 0,
D3DTA_TEXTURE, D3DTOP_MODULATE, D3DTA_DIFFUSE);
pID3DDevice->SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_DISABLE);
pID3DDevice->SetTransform( D3DTS_TEXTURE0, &SphereMapMatrixD3D9 );
pID3DDevice->SetTextureStageState( 0, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_COUNT2 );
pID3DDevice->SetTextureStageState( 0, D3DTSS_TEXCOORDINDEX, D3DTSS_TCI_CAMERASPACENORMAL );
}
}
virtual void OnUnsetMaterial() _IRR_OVERRIDE_
{
pID3DDevice->SetTextureStageState( 0, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_DISABLE );
pID3DDevice->SetTextureStageState( 0, D3DTSS_TEXCOORDINDEX, 0);
pID3DDevice->SetTransform( D3DTS_TEXTURE0, &UnitMatrixD3D9 );
}
};
//! reflection 2 layer material renderer
class CD3D9MaterialRenderer_REFLECTION_2_LAYER : public CD3D9MaterialRenderer
{
public:
CD3D9MaterialRenderer_REFLECTION_2_LAYER(IDirect3DDevice9* p, CD3D9Driver* d)
: CD3D9MaterialRenderer(p, d) {}
virtual void OnSetMaterial(const SMaterial& material, const SMaterial& lastMaterial,
bool resetAllRenderstates, IMaterialRendererServices* services) _IRR_OVERRIDE_
{
services->setBasicRenderStates(material, lastMaterial, resetAllRenderstates);
if (material.MaterialType != lastMaterial.MaterialType || resetAllRenderstates)
{
setTextureColorStage(pID3DDevice, 0,
D3DTA_TEXTURE, D3DTOP_MODULATE, D3DTA_DIFFUSE);
setTextureColorStage(pID3DDevice, 1,
D3DTA_TEXTURE, D3DTOP_MODULATE, D3DTA_CURRENT);
pID3DDevice->SetTransform( D3DTS_TEXTURE1, &SphereMapMatrixD3D9 );
pID3DDevice->SetTextureStageState( 1, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_COUNT2 );
pID3DDevice->SetTextureStageState( 1, D3DTSS_TEXCOORDINDEX, D3DTSS_TCI_CAMERASPACEREFLECTIONVECTOR);
}
}
virtual void OnUnsetMaterial() _IRR_OVERRIDE_
{
pID3DDevice->SetTextureStageState( 1, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_DISABLE );
pID3DDevice->SetTextureStageState( 1, D3DTSS_TEXCOORDINDEX, 1);
pID3DDevice->SetTransform( D3DTS_TEXTURE1, &UnitMatrixD3D9 );
}
};
//! reflection 2 layer material renderer
class CD3D9MaterialRenderer_TRANSPARENT_REFLECTION_2_LAYER : public CD3D9MaterialRenderer
{
public:
CD3D9MaterialRenderer_TRANSPARENT_REFLECTION_2_LAYER(IDirect3DDevice9* p, CD3D9Driver* d)
: CD3D9MaterialRenderer(p, d) {}
virtual void OnSetMaterial(const SMaterial& material, const SMaterial& lastMaterial,
bool resetAllRenderstates, IMaterialRendererServices* services) _IRR_OVERRIDE_
{
services->setBasicRenderStates(material, lastMaterial, resetAllRenderstates);
Driver->getBridgeCalls()->setBlend(true);
Driver->getBridgeCalls()->setBlendFunc(D3DBLEND_SRCALPHA, D3DBLEND_INVSRCALPHA);
if (material.MaterialType != lastMaterial.MaterialType || resetAllRenderstates)
{
setTextureColorStage(pID3DDevice, 0,
D3DTA_TEXTURE, D3DTOP_MODULATE, D3DTA_DIFFUSE);
setTextureAlphaStage(pID3DDevice, 0, D3DTA_DIFFUSE);
setTextureColorStage(pID3DDevice, 1,
D3DTA_TEXTURE, D3DTOP_MODULATE, D3DTA_CURRENT);
setTextureAlphaStage(pID3DDevice, 1, D3DTA_CURRENT);
pID3DDevice->SetTransform(D3DTS_TEXTURE1, &SphereMapMatrixD3D9 );
pID3DDevice->SetTextureStageState(1, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_COUNT2 );
pID3DDevice->SetTextureStageState(1, D3DTSS_TEXCOORDINDEX, D3DTSS_TCI_CAMERASPACEREFLECTIONVECTOR);
}
}
virtual void OnUnsetMaterial() _IRR_OVERRIDE_
{
pID3DDevice->SetTextureStageState(1, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_DISABLE);
pID3DDevice->SetTextureStageState(1, D3DTSS_TEXCOORDINDEX, 1);
pID3DDevice->SetTransform(D3DTS_TEXTURE1, &UnitMatrixD3D9);
Driver->getBridgeCalls()->setBlend(false);
}
//! Returns if the material is transparent. The scene management needs to know this
//! for being able to sort the materials by opaque and transparent.
virtual bool isTransparent() const _IRR_OVERRIDE_
{
return true;
}
};
} // end namespace video
} // end namespace irr
#endif
#endif
#endif

View File

@ -1,306 +0,0 @@
// Copyright (C) 2002-2012 Nikolaus Gebhardt
// This file is part of the "Irrlicht Engine".
// For conditions of distribution and use, see copyright notice in irrlicht.h
#include "IrrCompileConfig.h"
#ifdef _IRR_COMPILE_WITH_DIRECT3D_9_
#include "CD3D9NormalMapRenderer.h"
#include "IVideoDriver.h"
#include "IMaterialRendererServices.h"
#include "os.h"
#include "SLight.h"
namespace irr
{
namespace video
{
// 1.1 Shaders with two lights and vertex based attenuation
// Irrlicht Engine D3D9 render path normal map vertex shader
const char D3D9_NORMAL_MAP_VSH[] =
";Irrlicht Engine 0.8 D3D9 render path normal map vertex shader\n"\
"; c0-3: Transposed world matrix \n"\
"; c8-11: Transposed worldViewProj matrix (Projection * View * World) \n"\
"; c12: Light01 position \n"\
"; c13: x,y,z: Light01 color; .w: 1/LightRadius<75> \n"\
"; c14: Light02 position \n"\
"; c15: x,y,z: Light02 color; .w: 1/LightRadius<75> \n"\
"vs.1.1\n"\
"dcl_position v0 ; position \n"\
"dcl_normal v1 ; normal \n"\
"dcl_color v2 ; color \n"\
"dcl_texcoord0 v3 ; texture coord \n"\
"dcl_texcoord1 v4 ; tangent \n"\
"dcl_texcoord2 v5 ; binormal \n"\
"\n"\
"def c95, 0.5, 0.5, 0.5, 0.5 ; used for moving light vector to ps \n"\
"\n"\
"m4x4 oPos, v0, c8 ; transform position to clip space with worldViewProj matrix\n"\
"\n"\
"m3x3 r5, v4, c0 ; transform tangent U\n"\
"m3x3 r7, v1, c0 ; transform normal W\n"\
"m3x3 r6, v5, c0 ; transform binormal V\n"\
"\n"\
"m4x4 r4, v0, c0 ; vertex into world position\n"\
"add r2, c12, -r4 ; vtxpos - lightpos1\n"\
"add r3, c14, -r4 ; vtxpos - lightpos2\n"\
"\n"\
"dp3 r8.x, r5, r2 ; transform the light vector 1 with U, V, W\n"\
"dp3 r8.y, r6, r2 \n"\
"dp3 r8.z, r7, r2 \n"\
"dp3 r9.x, r5, r3 ; transform the light vector 2 with U, V, W\n"\
"dp3 r9.y, r6, r3 \n"\
"dp3 r9.z, r7, r3 \n"\
"\n"\
"dp3 r8.w, r8, r8 ; normalize light vector 1 (r8)\n"\
"rsq r8.w, r8.w \n"\
"mul r8, r8, r8.w \n"\
"dp3 r9.w, r9, r9 ; normalize light vector 2 (r9)\n"\
"rsq r9.w, r9.w \n"\
"mul r9, r9, r9.w \n"\
"\n"\
"mad oT2.xyz, r8.xyz, c95, c95 ; move light vector 1 from -1..1 into 0..1 \n"\
"mad oT3.xyz, r9.xyz, c95, c95 ; move light vector 2 from -1..1 into 0..1 \n"\
"\n"\
" ; calculate attenuation of light 1 \n"\
"dp3 r2.x, r2.xyz, r2.xyz ; r2.x = r2.x<> + r2.y<> + r2.z<> \n"\
"mul r2.x, r2.x, c13.w ; r2.x * attenutation \n"\
"rsq r2, r2.x ; r2.xyzw = 1/sqrt(r2.x * attenutation)\n"\
"mul oD0, r2, c13 ; resulting light color = lightcolor * attenuation \n"\
"\n"\
" ; calculate attenuation of light 2 \n"\
"dp3 r3.x, r3.xyz, r3.xyz ; r3.x = r3.x<> + r3.y<> + r3.z<> \n"\
"mul r3.x, r3.x, c15.w ; r2.x * attenutation \n"\
"rsq r3, r3.x ; r2.xyzw = 1/sqrt(r2.x * attenutation)\n"\
"mul oD1, r3, c15 ; resulting light color = lightcolor * attenuation \n"\
"\n"\
"mov oT0.xy, v3.xy ; move out texture coordinates 1\n"\
"mov oT1.xy, v3.xy ; move out texture coordinates 2\n"\
"mov oD0.a, v2.a ; move out original alpha value \n"\
"\n";
// Irrlicht Engine D3D9 render path normal map pixel shader
const char D3D9_NORMAL_MAP_PSH_1_1[] =
";Irrlicht Engine 0.8 D3D9 render path normal map pixel shader\n"\
";Input: \n"\
";t0: color map texture coord \n"\
";t1: normal map texture coords \n"\
";t2: light 1 vector in tangent space \n"\
";v0: light 1 color \n"\
";t3: light 2 vector in tangent space \n"\
";v1: light 2 color \n"\
";v0.a: vertex alpha value \n"\
"ps.1.1 \n"\
"tex t0 ; sample color map \n"\
"tex t1 ; sample normal map\n"\
"texcoord t2 ; fetch light vector 1\n"\
"texcoord t3 ; fetch light vector 2\n"\
"\n"\
"dp3_sat r0, t1_bx2, t2_bx2 ; normal dot light 1 (_bx2 because moved into 0..1)\n"\
"mul r0, r0, v0 ; luminance1 * light color 1 \n"\
"\n"\
"dp3_sat r1, t1_bx2, t3_bx2 ; normal dot light 2 (_bx2 because moved into 0..1)\n"\
"mad r0, r1, v1, r0 ; (luminance2 * light color 2) + luminance 1 \n"\
"\n"\
"mul r0.xyz, t0, r0 ; total luminance * base color\n"\
"+mov r0.a, v0.a ; write interpolated vertex alpha value \n"\
"\n"\
"";
// Higher-quality normal map pixel shader (requires PS 2.0)
// uses per-pixel normalization for improved accuracy
const char D3D9_NORMAL_MAP_PSH_2_0[] =
";Irrlicht Engine 0.8 D3D9 render path normal map pixel shader\n"\
";Input: \n"\
";t0: color map texture coord \n"\
";t1: normal map texture coords \n"\
";t2: light 1 vector in tangent space \n"\
";v0: light 1 color \n"\
";t3: light 2 vector in tangent space \n"\
";v1: light 2 color \n"\
";v0.a: vertex alpha value \n"\
"ps_2_0 \n"\
"def c0, 0, 0, 0, 0\n"\
"def c1, 1.0, 1.0, 1.0, 1.0\n"\
"def c2, 2.0, 2.0, 2.0, 2.0\n"\
"def c3, -.5, -.5, -.5, -.5\n"\
"dcl t0\n"\
"dcl t1\n"\
"dcl t2\n"\
"dcl t3\n"\
"dcl v1\n"\
"dcl v0\n"\
"dcl_2d s0\n"\
"dcl_2d s1\n"\
"texld r0, t0, s0 ; sample color map into r0 \n"\
"texld r4, t0, s1 ; sample normal map into r4\n"\
"add r4, r4, c3 ; bias the normal vector\n"\
"add r5, t2, c3 ; bias the light 1 vector into r5\n"\
"add r6, t3, c3 ; bias the light 2 vector into r6\n"\
"nrm r1, r4 ; normalize the normal vector into r1\n"\
"nrm r2, r5 ; normalize the light1 vector into r2\n"\
"nrm r3, r6 ; normalize the light2 vector into r3\n"\
"dp3 r2, r2, r1 ; let r2 = normal DOT light 1 vector\n"\
"max r2, r2, c0 ; clamp result to positive numbers\n"\
"mul r2, r2, v0 ; let r2 = luminance1 * light color 1 \n"\
"dp3 r3, r3, r1 ; let r3 = normal DOT light 2 vector\n"\
"max r3, r3, c0 ; clamp result to positive numbers\n"\
"mad r2, r3, v1, r2 ; let r2 = (luminance2 * light color 2) + (luminance2 * light color 1) \n"\
"mul r2, r2, r0 ; let r2 = total luminance * base color\n"\
"mov r2.w, v0.w ; write interpolated vertex alpha value \n"\
"mov oC0, r2 ; copy r2 to the output register \n"\
"\n"\
"";
CD3D9NormalMapRenderer::CD3D9NormalMapRenderer(
IDirect3DDevice9* d3ddev, video::IVideoDriver* driver,
s32& outMaterialTypeNr, IMaterialRenderer* baseMaterial)
: CD3D9ShaderMaterialRenderer(d3ddev, driver, 0, baseMaterial)
{
#ifdef _DEBUG
setDebugName("CD3D9NormalMapRenderer");
#endif
// set this as callback. We could have done this in
// the initialization list, but some compilers don't like it.
CallBack = this;
// basically, this thing simply compiles the hardcoded shaders
// if the hardware is able to do them, otherwise it maps to the
// base material
if (!driver->queryFeature(video::EVDF_PIXEL_SHADER_1_1) ||
!driver->queryFeature(video::EVDF_VERTEX_SHADER_1_1))
{
// this hardware is not able to do shaders. Fall back to
// base material.
outMaterialTypeNr = driver->addMaterialRenderer(this);
return;
}
// check if already compiled normal map shaders are there.
video::IMaterialRenderer* renderer = driver->getMaterialRenderer(EMT_NORMAL_MAP_SOLID);
if (renderer)
{
// use the already compiled shaders
video::CD3D9NormalMapRenderer* nmr = (video::CD3D9NormalMapRenderer*)renderer;
VertexShader = nmr->VertexShader;
if (VertexShader)
VertexShader->AddRef();
PixelShader = nmr->PixelShader;
if (PixelShader)
PixelShader->AddRef();
outMaterialTypeNr = driver->addMaterialRenderer(this);
}
else
{
// compile shaders on our own
if (driver->queryFeature(video::EVDF_PIXEL_SHADER_2_0))
{
init(outMaterialTypeNr, D3D9_NORMAL_MAP_VSH, D3D9_NORMAL_MAP_PSH_2_0);
}
else
{
init(outMaterialTypeNr, D3D9_NORMAL_MAP_VSH, D3D9_NORMAL_MAP_PSH_1_1);
}
}
// something failed, use base material
if (-1==outMaterialTypeNr)
driver->addMaterialRenderer(this);
}
CD3D9NormalMapRenderer::~CD3D9NormalMapRenderer()
{
if (CallBack == this)
CallBack = 0;
}
bool CD3D9NormalMapRenderer::OnRender(IMaterialRendererServices* service, E_VERTEX_TYPE vtxtype)
{
if (vtxtype != video::EVT_TANGENTS)
{
os::Printer::log("Error: Normal map renderer only supports vertices of type EVT_TANGENTS", ELL_ERROR);
return false;
}
return CD3D9ShaderMaterialRenderer::OnRender(service, vtxtype);
}
//! Returns the render capability of the material.
s32 CD3D9NormalMapRenderer::getRenderCapability() const
{
if (Driver->queryFeature(video::EVDF_PIXEL_SHADER_1_1) &&
Driver->queryFeature(video::EVDF_VERTEX_SHADER_1_1))
return 0;
return 1;
}
//! Called by the engine when the vertex and/or pixel shader constants
//! for an material renderer should be set.
void CD3D9NormalMapRenderer::OnSetConstants(IMaterialRendererServices* services, s32 userData)
{
video::IVideoDriver* driver = services->getVideoDriver();
// set transposed world matrix
services->setVertexShaderConstant(driver->getTransform(video::ETS_WORLD).getTransposed().pointer(), 0, 4);
// set transposed worldViewProj matrix
core::matrix4 worldViewProj(driver->getTransform(video::ETS_PROJECTION));
worldViewProj *= driver->getTransform(video::ETS_VIEW);
worldViewProj *= driver->getTransform(video::ETS_WORLD);
services->setVertexShaderConstant(worldViewProj.getTransposed().pointer(), 8, 4);
// here we've got to fetch the fixed function lights from the
// driver and set them as constants
u32 cnt = driver->getDynamicLightCount();
for (u32 i=0; i<2; ++i)
{
SLight light;
if (i<cnt)
light = driver->getDynamicLight(i);
else
{
light.DiffuseColor.set(0,0,0); // make light dark
light.Radius = 1.0f;
}
light.DiffuseColor.a = 1.0f/(light.Radius*light.Radius); // set attenuation
services->setVertexShaderConstant(reinterpret_cast<const f32*>(&light.Position), 12+(i*2), 1);
services->setVertexShaderConstant(reinterpret_cast<const f32*>(&light.DiffuseColor), 13+(i*2), 1);
}
// this is not really necessary in d3d9 (used a def instruction), but to be sure:
f32 c95[] = {0.5f, 0.5f, 0.5f, 0.5f};
services->setVertexShaderConstant(c95, 95, 1);
}
} // end namespace video
} // end namespace irr
#endif // _IRR_COMPILE_WITH_DIRECT3D_9_

View File

@ -1,56 +0,0 @@
// Copyright (C) 2002-2012 Nikolaus Gebhardt
// This file is part of the "Irrlicht Engine".
// For conditions of distribution and use, see copyright notice in irrlicht.h
#ifndef __C_D3D9_NORMAL_MAPMATERIAL_RENDERER_H_INCLUDED__
#define __C_D3D9_NORMAL_MAPMATERIAL_RENDERER_H_INCLUDED__
#include "IrrCompileConfig.h"
#ifdef _IRR_WINDOWS_
#ifdef _IRR_COMPILE_WITH_DIRECT3D_9_
#if defined(__BORLANDC__) || defined (__BCPLUSPLUS__)
#include "irrMath.h" // needed by borland for sqrtf define
#endif
#include <d3d9.h>
#include "CD3D9ShaderMaterialRenderer.h"
#include "IShaderConstantSetCallBack.h"
namespace irr
{
namespace video
{
//! Renderer for normal maps
class CD3D9NormalMapRenderer :
public CD3D9ShaderMaterialRenderer, IShaderConstantSetCallBack
{
public:
CD3D9NormalMapRenderer(
IDirect3DDevice9* d3ddev, video::IVideoDriver* driver,
s32& outMaterialTypeNr, IMaterialRenderer* baseMaterial);
~CD3D9NormalMapRenderer();
//! Called by the engine when the vertex and/or pixel shader constants for an
//! material renderer should be set.
virtual void OnSetConstants(IMaterialRendererServices* services, s32 userData) _IRR_OVERRIDE_;
virtual bool OnRender(IMaterialRendererServices* service, E_VERTEX_TYPE vtxtype) _IRR_OVERRIDE_;
//! Returns the render capability of the material.
virtual s32 getRenderCapability() const _IRR_OVERRIDE_;
private:
};
} // end namespace video
} // end namespace irr
#endif
#endif
#endif

View File

@ -1,409 +0,0 @@
// Copyright (C) 2002-2012 Nikolaus Gebhardt
// This file is part of the "Irrlicht Engine".
// For conditions of distribution and use, see copyright notice in irrlicht.h
#include "IrrCompileConfig.h"
#ifdef _IRR_COMPILE_WITH_DIRECT3D_9_
#include "CD3D9ParallaxMapRenderer.h"
#include "IMaterialRendererServices.h"
#include "IVideoDriver.h"
#include "os.h"
#include "SLight.h"
//#define SHADER_EXTERNAL_DEBUG
#ifdef SHADER_EXTERNAL_DEBUG
#include "CReadFile.h"
#endif
namespace irr
{
namespace video
{
// 1.1/1.4 Shaders with two lights and vertex based attenuation
// Irrlicht Engine D3D9 render path normal map vertex shader
const char D3D9_PARALLAX_MAP_VSH[] =
";Irrlicht Engine 0.10 D3D9 render path parallax mapping vertex shader\n"\
"; c0-3: Transposed world matrix \n"\
"; c4: Eye position \n"\
"; c8-11: Transposed worldViewProj matrix (Projection * View * World) \n"\
"; c12: Light01 position \n"\
"; c13: x,y,z: Light01 color; .w: 1/LightRadius<75> \n"\
"; c14: Light02 position \n"\
"; c15: x,y,z: Light02 color; .w: 1/LightRadius<75> \n"\
"vs.1.1\n"\
"dcl_position v0 ; position \n"\
"dcl_normal v1 ; normal \n"\
"dcl_color v2 ; color \n"\
"dcl_texcoord0 v3 ; texture coord \n"\
"dcl_texcoord1 v4 ; tangent \n"\
"dcl_texcoord2 v5 ; binormal \n"\
"\n"\
"def c95, 0.5, 0.5, 0.5, 0.5 ; used for moving light vector to ps \n"\
"def c96, -1, 1, 1, 1 ; somewhere I've got a bug. flipping the vectors with this fixes it. \n"\
"\n"\
"m4x4 oPos, v0, c8 ; transform position to clip space with worldViewProj matrix\n"\
"\n"\
"m3x3 r5, v4, c0 ; transform tangent U\n"\
"m3x3 r7, v1, c0 ; transform normal W\n"\
"m3x3 r6, v5, c0 ; transform binormal V\n"\
"\n"\
"m4x4 r4, v0, c0 ; vertex into world position\n"\
"add r2, c12, -r4 ; vtxpos - light1 pos\n"\
"add r3, c14, -r4 ; vtxpos - light2 pos\n"\
"add r1, -c4, r4 ; eye - vtxpos \n"\
"\n"\
"dp3 r8.x, r5, r2 ; transform the light1 vector with U, V, W\n"\
"dp3 r8.y, r6, r2 \n"\
"dp3 r8.z, r7, r2 \n"\
"dp3 r9.x, r5, r3 ; transform the light2 vector with U, V, W\n"\
"dp3 r9.y, r6, r3 \n"\
"dp3 r9.z, r7, r3 \n"\
"dp3 r10.x, r5, r1 ; transform the eye vector with U, V, W\n"\
"dp3 r10.y, r6, r1 \n"\
"dp3 r10.z, r7, r1 \n"\
"\n"\
"dp3 r8.w, r8, r8 ; normalize light vector 1 (r8)\n"\
"rsq r8.w, r8.w \n"\
"mul r8, r8, r8.w \n"\
";mul r8, r8, c96 \n"\
"dp3 r9.w, r9, r9 ; normalize light vector 2 (r9)\n"\
"rsq r9.w, r9.w \n"\
"mul r9, r9, r9.w \n"\
";mul r9, r9, c96 \n"\
"dp3 r10.w, r10, r10 ; normalize eye vector (r10)\n"\
"rsq r10.w, r10.w \n"\
"mul r10, r10, r10.w \n"\
"mul r10, r10, c96 \n"\
"\n"\
"\n"\
"mad oT2.xyz, r8.xyz, c95, c95 ; move light vector 1 from -1..1 into 0..1 \n"\
"mad oT3.xyz, r9.xyz, c95, c95 ; move light vector 2 from -1..1 into 0..1 \n"\
"mad oT4.xyz, r10.xyz, c95, c95 ; move eye vector from -1..1 into 0..1 \n"\
"\n"\
" ; calculate attenuation of light 1 \n"\
"dp3 r2.x, r2.xyz, r2.xyz ; r2.x = r2.x<> + r2.y<> + r2.z<> \n"\
"mul r2.x, r2.x, c13.w ; r2.x * attenutation \n"\
"rsq r2, r2.x ; r2.xyzw = 1/sqrt(r2.x * attenutation)\n"\
"mul oD0, r2, c13 ; resulting light color = lightcolor * attenuation \n"\
"\n"\
" ; calculate attenuation of light 2 \n"\
"dp3 r3.x, r3.xyz, r3.xyz ; r3.x = r3.x<> + r3.y<> + r3.z<> \n"\
"mul r3.x, r3.x, c15.w ; r2.x * attenutation \n"\
"rsq r3, r3.x ; r2.xyzw = 1/sqrt(r2.x * attenutation)\n"\
"mul oD1, r3, c15 ; resulting light color = lightcolor * attenuation \n"\
"\n"\
"mov oT0.xy, v3.xy ; move out texture coordinates 1\n"\
"mov oT1.xy, v3.xy ; move out texture coordinates 2\n"\
"mov oD0.a, v2.a ; move out original alpha value \n"\
"\n";
// Irrlicht Engine D3D9 render path normal map pixel shader version 1.4
const char D3D9_PARALLAX_MAP_PSH[] =
";Irrlicht Engine 0.10 D3D9 render path parallax mapping pixel shader \n"\
";Input: \n"\
";t0: color map texture coord \n"\
";t1: normal map texture coords \n"\
";t2: light 1 vector in tangent space \n"\
";t4: eye vector in tangent space \n"\
";v0: light 1 color \n"\
";t3: light 2 vector in tangent space \n"\
";v1: light 2 color \n"\
";v0.a: vertex alpha value \n"\
" \n"\
"ps.1.4 \n"\
" \n"\
";def c6, 0.02f, 0.02f, 0.02f, 0.0f ; scale factor, now set in callback \n"\
"def c5, 0.5f, 0.5f, 0.5f, 0.0f ; for specular division \n"\
" \n"\
"texld r1, t1 ; sample (normal.x, normal.y, normal.z, height) \n"\
"texcrd r4.xyz, t4 ; fetch eye vector \n"\
"texcrd r0.xyz, t0 ; color map \n"\
" \n"\
"; original parallax mapping: \n"\
";mul r3, r1_bx2.wwww, c6; ; r3 = (height, height, height) * scale \n"\
";mad r2.xyz, r3, r4_bx2, r0 ; newTexCoord = height * eye + oldTexCoord \n"\
" \n"\
"; modified parallax mapping to reduce swimming effect: \n"\
"mul r3, r1_bx2.wwww, r1_bx2.zzzz ; (nh,nh,nh,nh) = (h,h,h,h) * (n.z,n.z,n.z,n.z,) \n"\
"mul r3, r3, c6; ; r3 = (nh, nh, nh) * scale \n"\
"mad r2.xyz, r3, r4_bx2, r0 ; newTexCoord = height * eye + oldTexCoord \n"\
" \n"\
"phase \n"\
" \n"\
"texld r0, r2 ; load diffuse texture with new tex coord \n"\
"texld r1, r2 ; sample normal map \n"\
"texcrd r2.xyz, t2 ; fetch light vector 1 \n"\
"texcrd r3.xyz, t3 ; fetch light vector 2 \n"\
" \n"\
"dp3_sat r5, r1_bx2, r2_bx2 ; normal dot light 1 (_bx2 because moved into 0..1) \n"\
"mul r5, r5, v0 ; luminance1 * light color 1 \n"\
" \n"\
"dp3_sat r3, r1_bx2, r3_bx2 ; normal dot light 2 (_bx2 because moved into 0..1) \n"\
"mad r3, r3, v1, r5 ; (luminance2 * light color 2) + luminance1 \n"\
" \n"\
"mul r0.xyz, r0, r3 ; total luminance * base color \n"\
"+mov r0.a, v0.a ; write original alpha value \n"\
"\n";
// Irrlicht Engine D3D9 render path normal map pixel shader version 2.0
const char D3D9_PARALLAX_MAP_PSH_20[] =
";Irrlicht Engine D3D9 render path parallax mapping pixel shader \n"\
";Input: \n"\
" \n"\
";t0: color map texture coord \n"\
";t1: normal map texture coords \n"\
";t2: light 1 vector in tangent space \n"\
";t4: eye vector in tangent space \n"\
";v0: light 1 color \n"\
";t3: light 2 vector in tangent space \n"\
";v1: light 2 color \n"\
";v0.a: vertex alpha value \n"\
" \n"\
"ps.2.0 \n"\
" \n"\
"dcl_2d s0 ; Declare the s0 register to be the sampler for stage 0 \n"\
"dcl t0.xy ; Declare t0 to have 2D texture coordinates from stage 0 \n"\
"dcl t1.xy ; Declare t0 to have 2D texture coordinates from stage 0 \n"\
"dcl_2d s1 ; Declare the s1 register to be the sampler for stage 1 \n"\
" \n"\
"dcl t2.xyz ; \n"\
"dcl t3.xyz ; \n"\
"dcl t4.xyz ; \n"\
"dcl v0.xyzw; \n"\
"dcl v1.xyzw; \n"\
" \n"\
"def c0, -1.0f, -1.0f, -1.0f, -1.0f ; for _bx2 emulation \n"\
"def c1, 2.0f, 2.0f, 2.0f, 2.0f ; for _bx2 emulation \n"\
"mov r11, c1; \n"\
" \n"\
"texld r1, t1, s1 ; sample (normal.x, normal.y, normal.z, height) \n"\
"mov r4.xyz, t4 ; fetch eye vector \n"\
"mov r0.xy, t0 ; color map \n"\
" \n"\
"; original parallax mapping: \n"\
"; emulate ps1x _bx2, so substract 0.5f and multiply by 2 \n"\
"mad r1.xyz, r1, r11, c0; \n"\
" \n"\
"mul r3, r1.wwww, c6; ; r3 = (height, height, height) * scale \n"\
" \n"\
"; emulate ps1x _bx2, so substract 0.5f and multiply by 2 \n"\
"mad r4.xyz, r4, r11, c0; \n"\
" \n"\
"mad r2.xy, r3, r4, r0 ; newTexCoord = height * eye + oldTexCoord \n"\
" \n"\
"; modified parallax mapping to avoid swimming: \n"\
";mul r3, r1_bx2.wwww, r1_bx2.zzzz ; r3 = (h,h,h,h) * (n.z, n.z, n.z, n.z,) \n"\
";mul r3, r3, c6; ; r3 = (nh, nh, nh) * scale \n"\
";mad r2.xyz, r3, r4_bx2, r0 ; newTexCoord = height * eye + oldTexCoord \n"\
" \n"\
"texld r0, r2, s0 ; load diffuse texture with new tex coord \n"\
"texld r1, r2, s1 ; sample normal map \n"\
"mov r2.xyz, t2 ; fetch light vector 1 \n"\
"mov r3.xyz, t3 ; fetch light vector 2 \n"\
" \n"\
"; emulate ps1x _bx2, so substract 0.5f and multiply by 2 \n"\
"mad r1.xyz, r1, r11, c0; \n"\
"mad r2.xyz, r2, r11, c0; \n"\
"mad r3.xyz, r3, r11, c0; \n"\
" \n"\
"dp3_sat r2, r1, r2 ; normal dot light 1 (_bx2 because moved into 0..1) \n"\
"mul r2, r2, v0 ; luminance1 * light color 1 \n"\
" \n"\
"dp3_sat r3, r1, r3 ; normal dot light 2 (_bx2 because moved into 0..1) \n"\
"mad r3, r3, v1, r2 ; (luminance2 * light color 2) + luminance1 \n"\
" \n"\
"mul r0.xyz, r0, r3 ; total luminance * base color \n"\
"mov r0.a, v0.a ; write original alpha value \n"\
"mov oC0, r0; \n"\
"\n";
CD3D9ParallaxMapRenderer::CD3D9ParallaxMapRenderer(
IDirect3DDevice9* d3ddev, video::IVideoDriver* driver,
s32& outMaterialTypeNr, IMaterialRenderer* baseMaterial)
: CD3D9ShaderMaterialRenderer(d3ddev, driver, 0, baseMaterial),
CurrentScale(0.0f)
{
#ifdef _DEBUG
setDebugName("CD3D9ParallaxMapRenderer");
#endif
// set this as callback. We could have done this in
// the initialization list, but some compilers don't like it.
CallBack = this;
// basically, this thing simply compiles these hardcoded shaders if the
// hardware is able to do them, otherwise it maps to the base material
if (!driver->queryFeature(video::EVDF_PIXEL_SHADER_1_4) ||
!driver->queryFeature(video::EVDF_VERTEX_SHADER_1_1))
{
// this hardware is not able to do shaders. Fall back to
// base material.
outMaterialTypeNr = driver->addMaterialRenderer(this);
return;
}
// check if already compiled parallax map shaders are there.
video::IMaterialRenderer* renderer = driver->getMaterialRenderer(EMT_PARALLAX_MAP_SOLID);
if (renderer)
{
// use the already compiled shaders
video::CD3D9ParallaxMapRenderer* nmr = (video::CD3D9ParallaxMapRenderer*)renderer;
VertexShader = nmr->VertexShader;
if (VertexShader)
VertexShader->AddRef();
PixelShader = nmr->PixelShader;
if (PixelShader)
PixelShader->AddRef();
outMaterialTypeNr = driver->addMaterialRenderer(this);
}
else
{
#ifdef SHADER_EXTERNAL_DEBUG
// quickly load shader from external file
io::CReadFile* file = new io::CReadFile("parallax.psh");
s32 sz = file->getSize();
char* s = new char[sz+1];
file->read(s, sz);
s[sz] = 0;
init(outMaterialTypeNr, D3D9_PARALLAX_MAP_VSH, s);
delete [] s;
file->drop();
#else
// compile shaders on our own
init(outMaterialTypeNr, D3D9_PARALLAX_MAP_VSH, D3D9_PARALLAX_MAP_PSH);
#endif // SHADER_EXTERNAL_DEBUG
}
// something failed, use base material
if (-1==outMaterialTypeNr)
driver->addMaterialRenderer(this);
}
CD3D9ParallaxMapRenderer::~CD3D9ParallaxMapRenderer()
{
if (CallBack == this)
CallBack = 0;
}
bool CD3D9ParallaxMapRenderer::OnRender(IMaterialRendererServices* service, E_VERTEX_TYPE vtxtype)
{
if (vtxtype != video::EVT_TANGENTS)
{
os::Printer::log("Error: Parallax map renderer only supports vertices of type EVT_TANGENTS", ELL_ERROR);
return false;
}
return CD3D9ShaderMaterialRenderer::OnRender(service, vtxtype);
}
void CD3D9ParallaxMapRenderer::OnSetMaterial(const video::SMaterial& material,
const video::SMaterial& lastMaterial,
bool resetAllRenderstates, video::IMaterialRendererServices* services)
{
CD3D9ShaderMaterialRenderer::OnSetMaterial(material, lastMaterial,
resetAllRenderstates, services);
CurrentScale = material.MaterialTypeParam;
}
//! Returns the render capability of the material.
s32 CD3D9ParallaxMapRenderer::getRenderCapability() const
{
if (Driver->queryFeature(video::EVDF_PIXEL_SHADER_1_4) &&
Driver->queryFeature(video::EVDF_VERTEX_SHADER_1_1))
return 0;
return 1;
}
//! Called by the engine when the vertex and/or pixel shader constants
//! for an material renderer should be set.
void CD3D9ParallaxMapRenderer::OnSetConstants(IMaterialRendererServices* services, s32 userData)
{
video::IVideoDriver* driver = services->getVideoDriver();
// set transposed world matrix
services->setVertexShaderConstant(driver->getTransform(video::ETS_WORLD).getTransposed().pointer(), 0, 4);
// set eye position
// The viewpoint is at (0., 0., 0.) in eye space.
// Turning this into a vector [0 0 0 1] and multiply it by
// the inverse of the view matrix, the resulting vector is the
// object space location of the camera.
f32 floats[4] = {0,0,0,1};
core::matrix4 minv = driver->getTransform(video::ETS_VIEW);
minv.makeInverse();
minv.multiplyWith1x4Matrix(floats);
services->setVertexShaderConstant(floats, 4, 1);
// set transposed worldViewProj matrix
core::matrix4 worldViewProj;
worldViewProj = driver->getTransform(video::ETS_PROJECTION);
worldViewProj *= driver->getTransform(video::ETS_VIEW);
worldViewProj *= driver->getTransform(video::ETS_WORLD);
services->setVertexShaderConstant(worldViewProj.getTransposed().pointer(), 8, 4);
// here we've got to fetch the fixed function lights from the
// driver and set them as constants
const u32 cnt = driver->getDynamicLightCount();
for (u32 i=0; i<2; ++i)
{
SLight light;
if (i<cnt)
light = driver->getDynamicLight(i);
else
{
light.DiffuseColor.set(0,0,0); // make light dark
light.Radius = 1.0f;
}
light.DiffuseColor.a = 1.0f/(light.Radius*light.Radius); // set attenuation
services->setVertexShaderConstant(reinterpret_cast<const f32*>(&light.Position), 12+(i*2), 1);
services->setVertexShaderConstant(reinterpret_cast<const f32*>(&light.DiffuseColor), 13+(i*2), 1);
}
// this is not really necessary in d3d9 (used a def instruction), but to be sure:
f32 c95[] = {0.5f, 0.5f, 0.5f, 0.5f};
services->setVertexShaderConstant(c95, 95, 1);
f32 c96[] = {-1, 1, 1, 1};
services->setVertexShaderConstant(c96, 96, 1);
// set scale factor
f32 factor = 0.02f; // default value
if (CurrentScale != 0)
factor = CurrentScale;
f32 c6[] = {factor, factor, factor, 0};
services->setPixelShaderConstant(c6, 6, 1);
}
} // end namespace video
} // end namespace irr
#endif // _IRR_COMPILE_WITH_DIRECT3D_9_

View File

@ -1,63 +0,0 @@
// Copyright (C) 2002-2012 Nikolaus Gebhardt
// This file is part of the "Irrlicht Engine".
// For conditions of distribution and use, see copyright notice in irrlicht.h
#ifndef __C_D3D9_PARALLAX_MAPMATERIAL_RENDERER_H_INCLUDED__
#define __C_D3D9_PARALLAX_MAPMATERIAL_RENDERER_H_INCLUDED__
#include "IrrCompileConfig.h"
#ifdef _IRR_WINDOWS_
#ifdef _IRR_COMPILE_WITH_DIRECT3D_9_
#if defined(__BORLANDC__) || defined (__BCPLUSPLUS__)
#include "irrMath.h" // needed by borland for sqrtf define
#endif
#include <d3d9.h>
#include "CD3D9ShaderMaterialRenderer.h"
#include "IShaderConstantSetCallBack.h"
namespace irr
{
namespace video
{
//! Renderer for normal maps using parallax mapping
class CD3D9ParallaxMapRenderer :
public CD3D9ShaderMaterialRenderer, IShaderConstantSetCallBack
{
public:
CD3D9ParallaxMapRenderer(
IDirect3DDevice9* d3ddev, video::IVideoDriver* driver,
s32& outMaterialTypeNr, IMaterialRenderer* baseMaterial);
~CD3D9ParallaxMapRenderer();
//! Called by the engine when the vertex and/or pixel shader constants for an
//! material renderer should be set.
virtual void OnSetConstants(IMaterialRendererServices* services, s32 userData) _IRR_OVERRIDE_;
virtual bool OnRender(IMaterialRendererServices* service, E_VERTEX_TYPE vtxtype) _IRR_OVERRIDE_;
//! Returns the render capability of the material.
virtual s32 getRenderCapability() const _IRR_OVERRIDE_;
virtual void OnSetMaterial(const SMaterial& material) _IRR_OVERRIDE_ { }
virtual void OnSetMaterial(const video::SMaterial& material,
const video::SMaterial& lastMaterial,
bool resetAllRenderstates, video::IMaterialRendererServices* services) _IRR_OVERRIDE_;
private:
f32 CurrentScale;
};
} // end namespace video
} // end namespace irr
#endif
#endif
#endif

View File

@ -1,281 +0,0 @@
// Copyright (C) 2015 Patryk Nadrowski
// This file is part of the "Irrlicht Engine".
// For conditions of distribution and use, see copyright notice in irrlicht.h
#include "CD3D9RenderTarget.h"
#ifdef _IRR_COMPILE_WITH_DIRECT3D_9_
#include "IImage.h"
#include "irrMath.h"
#include "irrString.h"
#include "CD3D9Driver.h"
#include "CD3D9Texture.h"
namespace irr
{
namespace video
{
CD3D9RenderTarget::CD3D9RenderTarget(CD3D9Driver* driver) : DepthStencilSurface(0), Driver(driver)
{
#ifdef _DEBUG
setDebugName("CD3D9RenderTarget");
#endif
DriverType = EDT_DIRECT3D9;
Size = Driver->getScreenSize();
}
CD3D9RenderTarget::~CD3D9RenderTarget()
{
for (u32 i = 0; i < Surface.size(); ++i)
{
if (Surface[i])
Surface[i]->Release();
}
if (DepthStencilSurface)
DepthStencilSurface->Release();
for (u32 i = 0; i < Texture.size(); ++i)
{
if (Texture[i])
Texture[i]->drop();
}
if (DepthStencil)
DepthStencil->drop();
}
void CD3D9RenderTarget::setTexture(const core::array<ITexture*>& texture, ITexture* depthStencil, const core::array<E_CUBE_SURFACE>& cubeSurfaces)
{
bool needSizeUpdate = false;
// Set color attachments.
if ((Texture != texture) || (CubeSurfaces != cubeSurfaces))
{
needSizeUpdate = true;
CubeSurfaces = cubeSurfaces; // TODO: we can probably avoid some memory allocating/de-allocating if _only_ CubeSurfaces change.
if (texture.size() > Driver->ActiveRenderTarget.size())
{
core::stringc message = "This GPU supports up to ";
message += Driver->ActiveRenderTarget.size();
message += " textures per render target.";
os::Printer::log(message.c_str(), ELL_WARNING);
}
const u32 size = core::min_(texture.size(), static_cast<u32>(Driver->ActiveRenderTarget.size()));
for (u32 i = 0; i < Surface.size(); ++i)
{
if (Surface[i])
Surface[i]->Release();
}
Surface.set_used(size);
core::array<ITexture*> prevTextures(Texture);
Texture.set_used(size);
for (u32 i = 0; i < size; ++i)
{
CD3D9Texture* currentTexture = (texture[i] && texture[i]->getDriverType() == DriverType) ? static_cast<CD3D9Texture*>(texture[i]) : 0;
IDirect3DTexture9* textureID = 0;
IDirect3DCubeTexture9* cubeTextureId = 0;
UINT level = 0; // no support for rendering to to other mip-levels so far
if (currentTexture)
{
if (currentTexture->getType() == ETT_2D)
textureID = currentTexture->getDX9Texture();
else if ( currentTexture->getType() == ETT_CUBEMAP )
cubeTextureId = currentTexture->getDX9CubeTexture();
}
if (textureID)
{
Texture[i] = texture[i];
Texture[i]->grab();
IDirect3DSurface9* currentSurface = 0;
textureID->GetSurfaceLevel(level, &currentSurface);
Surface[i] = currentSurface;
}
else if ( cubeTextureId )
{
Texture[i] = texture[i];
Texture[i]->grab();
IDirect3DSurface9* currentSurface = 0;
D3DCUBEMAP_FACES face = (D3DCUBEMAP_FACES)CubeSurfaces[i]; // we use same numbering
cubeTextureId->GetCubeMapSurface(face, level, &currentSurface);
Surface[i] = currentSurface;
}
else
{
Surface[i] = 0;
Texture[i] = 0;
}
}
for (u32 i = 0; i < prevTextures.size(); ++i)
{
if (prevTextures[i])
prevTextures[i]->drop();
}
}
// Set depth and stencil attachments.
if (DepthStencil != depthStencil)
{
if (DepthStencilSurface)
{
DepthStencilSurface->Release();
DepthStencilSurface = 0;
}
if (DepthStencil)
{
DepthStencil->drop();
DepthStencil = 0;
DepthStencilSurface = 0;
}
needSizeUpdate = true;
CD3D9Texture* currentTexture = (depthStencil && depthStencil->getDriverType() == DriverType) ? static_cast<CD3D9Texture*>(depthStencil) : 0;
if (currentTexture)
{
if (currentTexture->getType() == ETT_2D)
{
IDirect3DTexture9* textureID = currentTexture->getDX9Texture();
if (textureID)
{
const ECOLOR_FORMAT textureFormat = depthStencil->getColorFormat();
if (IImage::isDepthFormat(textureFormat))
{
DepthStencil = depthStencil;
DepthStencil->grab();
IDirect3DSurface9* currentSurface = 0;
textureID->GetSurfaceLevel(0, &currentSurface);
DepthStencilSurface = currentSurface;
}
else
{
os::Printer::log("Ignoring depth/stencil texture without depth color format.", ELL_WARNING);
}
}
}
else
os::Printer::log("This driver doesn't support depth/stencil to cubemaps.", ELL_WARNING);
}
}
if (needSizeUpdate)
{
// Set size required for a viewport.
bool sizeDetected = false;
for (u32 i = 0; i < Texture.size(); ++i)
{
if (Texture[i])
{
Size = Texture[i]->getSize();
sizeDetected = true;
break;
}
}
if (!sizeDetected)
{
if (DepthStencil)
Size = DepthStencil->getSize();
else
Size = Driver->getScreenSize();
}
}
}
const core::dimension2d<u32>& CD3D9RenderTarget::getSize() const
{
return Size;
}
IDirect3DSurface9* CD3D9RenderTarget::getSurface(u32 id) const
{
return (id < Surface.size()) ? Surface[id] : 0;
}
u32 CD3D9RenderTarget::getSurfaceCount() const
{
return Surface.size();
}
IDirect3DSurface9* CD3D9RenderTarget::getDepthStencilSurface() const
{
return DepthStencilSurface;
}
void CD3D9RenderTarget::releaseSurfaces()
{
for (u32 i = 0; i < Surface.size(); ++i)
{
if (Surface[i])
{
Surface[i]->Release();
Surface[i] = 0;
}
}
if (DepthStencilSurface)
{
DepthStencilSurface->Release();
DepthStencilSurface = 0;
}
}
void CD3D9RenderTarget::generateSurfaces()
{
for (u32 i = 0; i < Surface.size(); ++i)
{
if (!Surface[i] && Texture[i])
{
IDirect3DTexture9* currentTexture = static_cast<CD3D9Texture*>(Texture[i])->getDX9Texture();
if ( currentTexture )
{
IDirect3DSurface9* currentSurface = 0;
currentTexture->GetSurfaceLevel(0, &currentSurface);
Surface[i] = currentSurface;
}
}
}
if (!DepthStencilSurface && DepthStencil)
{
IDirect3DTexture9* currentTexture = static_cast<CD3D9Texture*>(DepthStencil)->getDX9Texture();
if ( currentTexture )
{
IDirect3DSurface9* currentSurface = 0;
currentTexture->GetSurfaceLevel(0, &currentSurface);
DepthStencilSurface = currentSurface;
}
}
}
}
}
#endif

View File

@ -1,60 +0,0 @@
// Copyright (C) 2015 Patryk Nadrowski
// This file is part of the "Irrlicht Engine".
// For conditions of distribution and use, see copyright notice in irrlicht.h
#ifndef __C_OPEN_GL_RENDER_TARGET_H_INCLUDED__
#define __C_OPEN_GL_RENDER_TARGET_H_INCLUDED__
#include "IrrCompileConfig.h"
#ifdef _IRR_COMPILE_WITH_DIRECT3D_9_
#include "IRenderTarget.h"
#include "dimension2d.h"
#include "os.h"
#include <d3d9.h>
namespace irr
{
namespace video
{
class CD3D9Driver;
class CD3D9RenderTarget : public IRenderTarget
{
public:
CD3D9RenderTarget(CD3D9Driver* driver);
virtual ~CD3D9RenderTarget();
virtual void setTexture(const core::array<ITexture*>& texture, ITexture* depthStencil, const core::array<E_CUBE_SURFACE>& cubeSurfaces) _IRR_OVERRIDE_;
const core::dimension2d<u32>& getSize() const;
IDirect3DSurface9* getSurface(u32 id) const;
u32 getSurfaceCount() const;
IDirect3DSurface9* getDepthStencilSurface() const;
void releaseSurfaces();
void generateSurfaces();
protected:
core::dimension2d<u32> Size;
core::array<IDirect3DSurface9*> Surface;
IDirect3DSurface9* DepthStencilSurface;
CD3D9Driver* Driver;
};
}
}
#endif
#endif

View File

@ -1,539 +0,0 @@
// Copyright (C) 2002-2012 Nikolaus Gebhardt
// This file is part of the "Irrlicht Engine".
// For conditions of distribution and use, see copyright notice in irrlicht.h
#include "IrrCompileConfig.h"
#ifdef _IRR_COMPILE_WITH_DIRECT3D_9_
#include "CD3D9ShaderMaterialRenderer.h"
#include "IShaderConstantSetCallBack.h"
#include "IMaterialRendererServices.h"
#include "IVideoDriver.h"
#include "os.h"
#include "irrString.h"
#ifndef _IRR_D3D_NO_SHADER_DEBUGGING
#include <stdio.h>
#endif
namespace irr
{
namespace video
{
//! Public constructor
CD3D9ShaderMaterialRenderer::CD3D9ShaderMaterialRenderer(IDirect3DDevice9* d3ddev, video::IVideoDriver* driver,
s32& outMaterialTypeNr, const c8* vertexShaderProgram, const c8* pixelShaderProgram,
IShaderConstantSetCallBack* callback, IMaterialRenderer* baseMaterial, s32 userData)
: pID3DDevice(d3ddev), Driver(driver), CallBack(callback), BaseMaterial(baseMaterial),
VertexShader(0), OldVertexShader(0), PixelShader(0), UserData(userData)
{
#ifdef _DEBUG
setDebugName("CD3D9ShaderMaterialRenderer");
#endif
if (BaseMaterial)
BaseMaterial->grab();
if (CallBack)
CallBack->grab();
init(outMaterialTypeNr, vertexShaderProgram, pixelShaderProgram);
}
//! constructor only for use by derived classes who want to
//! create a fall back material for example.
CD3D9ShaderMaterialRenderer::CD3D9ShaderMaterialRenderer(IDirect3DDevice9* d3ddev,
video::IVideoDriver* driver,
IShaderConstantSetCallBack* callback,
IMaterialRenderer* baseMaterial, s32 userData)
: pID3DDevice(d3ddev), Driver(driver), CallBack(callback), BaseMaterial(baseMaterial),
VertexShader(0), OldVertexShader(0), PixelShader(0), UserData(userData)
{
#ifdef _DEBUG
setDebugName("CD3D9ShaderMaterialRenderer");
#endif
if (BaseMaterial)
BaseMaterial->grab();
if (CallBack)
CallBack->grab();
}
void CD3D9ShaderMaterialRenderer::init(s32& outMaterialTypeNr,
const c8* vertexShaderProgram, const c8* pixelShaderProgram)
{
outMaterialTypeNr = -1;
// create vertex shader
if (!createVertexShader(vertexShaderProgram))
return;
// create pixel shader
if (!createPixelShader(pixelShaderProgram))
return;
// register myself as new material
outMaterialTypeNr = Driver->addMaterialRenderer(this);
}
//! Destructor
CD3D9ShaderMaterialRenderer::~CD3D9ShaderMaterialRenderer()
{
if (CallBack)
CallBack->drop();
if (VertexShader)
VertexShader->Release();
if (PixelShader)
PixelShader->Release();
if (BaseMaterial)
BaseMaterial->drop();
}
bool CD3D9ShaderMaterialRenderer::OnRender(IMaterialRendererServices* service, E_VERTEX_TYPE vtxtype)
{
// call callback to set shader constants
if (CallBack && (VertexShader || PixelShader))
CallBack->OnSetConstants(service, UserData);
return true;
}
void CD3D9ShaderMaterialRenderer::OnSetMaterial(const video::SMaterial& material, const video::SMaterial& lastMaterial,
bool resetAllRenderstates, video::IMaterialRendererServices* services)
{
if (material.MaterialType != lastMaterial.MaterialType || resetAllRenderstates)
{
if (VertexShader)
{
// save old vertex shader
pID3DDevice->GetVertexShader(&OldVertexShader);
// set new vertex shader
if (FAILED(pID3DDevice->SetVertexShader(VertexShader)))
os::Printer::log("Could not set vertex shader.", ELL_WARNING);
}
// set new pixel shader
if (PixelShader)
{
if (FAILED(pID3DDevice->SetPixelShader(PixelShader)))
os::Printer::log("Could not set pixel shader.", ELL_WARNING);
}
}
services->setBasicRenderStates(material, lastMaterial, resetAllRenderstates);
if (BaseMaterial)
BaseMaterial->OnSetMaterial(material, lastMaterial, resetAllRenderstates, services);
if (CallBack)
CallBack->OnSetMaterial(material);
}
void CD3D9ShaderMaterialRenderer::OnUnsetMaterial()
{
if (VertexShader)
pID3DDevice->SetVertexShader(OldVertexShader);
if (PixelShader)
pID3DDevice->SetPixelShader(0);
if (BaseMaterial)
BaseMaterial->OnUnsetMaterial();
}
//! Returns if the material is transparent. The scene management needs to know this
//! for being able to sort the materials by opaque and transparent.
bool CD3D9ShaderMaterialRenderer::isTransparent() const
{
return BaseMaterial ? BaseMaterial->isTransparent() : false;
}
bool CD3D9ShaderMaterialRenderer::createPixelShader(const c8* pxsh)
{
if (!pxsh)
return true;
// compile shader
LPD3DXBUFFER code = 0;
LPD3DXBUFFER errors = 0;
#ifdef _IRR_D3D_NO_SHADER_DEBUGGING
// compile shader without debug info
stubD3DXAssembleShader(pxsh, (UINT)strlen(pxsh), 0, 0, 0, &code, &errors);
#else
// compile shader and emit some debug information to
// make it possible to debug the shader in visual studio
static int irr_dbg_file_nr = 0;
++irr_dbg_file_nr;
char tmp[32];
sprintf(tmp, "irr_d3d9_dbg_shader_%d.psh", irr_dbg_file_nr);
FILE* f = fopen(tmp, "wb");
fwrite(pxsh, strlen(pxsh), 1, f);
fflush(f);
fclose(f);
stubD3DXAssembleShaderFromFile(tmp, 0, 0, D3DXSHADER_DEBUG, &code, &errors);
#endif
if (errors)
{
// print out compilation errors.
os::Printer::log("Pixel shader compilation failed:", ELL_ERROR);
os::Printer::log((c8*)errors->GetBufferPointer(), ELL_ERROR);
if (code)
code->Release();
errors->Release();
return false;
}
if (FAILED(pID3DDevice->CreatePixelShader((DWORD*)code->GetBufferPointer(), &PixelShader)))
{
os::Printer::log("Could not create pixel shader.", ELL_ERROR);
code->Release();
return false;
}
code->Release();
return true;
}
bool CD3D9ShaderMaterialRenderer::createVertexShader(const char* vtxsh)
{
if (!vtxsh)
return true;
// compile shader
LPD3DXBUFFER code = 0;
LPD3DXBUFFER errors = 0;
#ifdef _IRR_D3D_NO_SHADER_DEBUGGING
// compile shader without debug info
stubD3DXAssembleShader(vtxsh, (UINT)strlen(vtxsh), 0, 0, 0, &code, &errors);
#else
// compile shader and emit some debug information to
// make it possible to debug the shader in visual studio
static int irr_dbg_file_nr = 0;
++irr_dbg_file_nr;
char tmp[32];
sprintf(tmp, "irr_d3d9_dbg_shader_%d.vsh", irr_dbg_file_nr);
FILE* f = fopen(tmp, "wb");
fwrite(vtxsh, strlen(vtxsh), 1, f);
fflush(f);
fclose(f);
stubD3DXAssembleShaderFromFile(tmp, 0, 0, D3DXSHADER_DEBUG, &code, &errors);
#endif
if (errors)
{
// print out compilation errors.
os::Printer::log("Vertex shader compilation failed:", ELL_ERROR);
os::Printer::log((c8*)errors->GetBufferPointer(), ELL_ERROR);
if (code)
code->Release();
errors->Release();
return false;
}
if (!code || FAILED(pID3DDevice->CreateVertexShader((DWORD*)code->GetBufferPointer(), &VertexShader)))
{
os::Printer::log("Could not create vertex shader.", ELL_ERROR);
if (code)
code->Release();
return false;
}
code->Release();
return true;
}
HRESULT CD3D9ShaderMaterialRenderer::stubD3DXAssembleShader(LPCSTR pSrcData,
UINT SrcDataLen, CONST D3DXMACRO* pDefines,
LPD3DXINCLUDE pInclude, DWORD Flags, LPD3DXBUFFER* ppShader,
LPD3DXBUFFER* ppErrorMsgs)
{
// Because Irrlicht needs to be able to start up even without installed d3d dlls, it
// needs to load external d3d dlls manually. examples for the dlls are:
// SDK dll name D3DX_SDK_VERSION
// Summer 2004: no dll 22
// February 2005: d3dx9_24.dll 24
// April 2005: d3dx9_25.dll 25
// June 2005: d3dx9_26.dll 26
// August 2005: d3dx9_27.dll 27
// October 2005,
// December 2005: d3dx9_28.dll 28
#if ( D3DX_SDK_VERSION < 24 )
// directly link functions, old d3d sdks didn't try to load external dlls
// when linking to the d3dx9.lib
#ifdef _MSC_VER
#pragma comment (lib, "d3dx9.lib")
#endif
// invoke static linked function
return D3DXAssembleShader(pSrcData, SrcDataLen, pDefines, pInclude,
Flags, ppShader, ppErrorMsgs);
#else
{
// try to load shader functions from the dll and print error if failed.
// D3DXAssembleShader signature
typedef HRESULT (WINAPI *AssembleShaderFunction)(LPCSTR pSrcData, UINT SrcDataLen,
CONST D3DXMACRO* pDefines, LPD3DXINCLUDE pInclude,
DWORD Flags, LPD3DXBUFFER* ppShader,
LPD3DXBUFFER* ppErrorMsgs);
static bool LoadFailed = false;
static AssembleShaderFunction pFn = 0;
if (!pFn && !LoadFailed)
{
// try to load dll
io::path strDllName = "d3dx9_";
strDllName += (int)D3DX_SDK_VERSION;
strDllName += ".dll";
HMODULE hMod = LoadLibrary(strDllName.c_str());
if (hMod)
pFn = (AssembleShaderFunction)GetProcAddress(hMod, "D3DXAssembleShader");
if (!pFn)
{
LoadFailed = true;
os::Printer::log("Could not load shader function D3DXAssembleShader from dll, shaders disabled",
strDllName.c_str(), ELL_ERROR);
}
}
if (pFn)
{
// call already loaded function
return (*pFn)(pSrcData, SrcDataLen, pDefines, pInclude, Flags, ppShader, ppErrorMsgs);
}
}
#endif // D3DX_SDK_VERSION < 24
return 0;
}
HRESULT CD3D9ShaderMaterialRenderer::stubD3DXAssembleShaderFromFile(LPCSTR pSrcFile,
CONST D3DXMACRO* pDefines, LPD3DXINCLUDE pInclude, DWORD Flags,
LPD3DXBUFFER* ppShader, LPD3DXBUFFER* ppErrorMsgs)
{
// wondering what I'm doing here?
// see comment in CD3D9ShaderMaterialRenderer::stubD3DXAssembleShader()
#if ( D3DX_SDK_VERSION < 24 )
// directly link functions, old d3d sdks didn't try to load external dlls
// when linking to the d3dx9.lib
#ifdef _MSC_VER
#pragma comment (lib, "d3dx9.lib")
#endif
// invoke static linked function
return D3DXAssembleShaderFromFileA(pSrcFile, pDefines, pInclude, Flags,
ppShader, ppErrorMsgs);
#else
{
// try to load shader functions from the dll and print error if failed.
// D3DXAssembleShaderFromFileA signature
typedef HRESULT (WINAPI *AssembleShaderFromFileFunction)(LPCSTR pSrcFile,
CONST D3DXMACRO* pDefines, LPD3DXINCLUDE pInclude, DWORD Flags,
LPD3DXBUFFER* ppShader, LPD3DXBUFFER* ppErrorMsgs);
static bool LoadFailed = false;
static AssembleShaderFromFileFunction pFn = 0;
if (!pFn && !LoadFailed)
{
// try to load dll
io::path strDllName = "d3dx9_";
strDllName += (int)D3DX_SDK_VERSION;
strDllName += ".dll";
HMODULE hMod = LoadLibrary(strDllName.c_str());
if (hMod)
pFn = (AssembleShaderFromFileFunction)GetProcAddress(hMod, "D3DXAssembleShaderFromFileA");
if (!pFn)
{
LoadFailed = true;
os::Printer::log("Could not load shader function D3DXAssembleShaderFromFileA from dll, shaders disabled",
strDllName.c_str(), ELL_ERROR);
}
}
if (pFn)
{
// call already loaded function
return (*pFn)(pSrcFile, pDefines, pInclude, Flags, ppShader, ppErrorMsgs);
}
}
#endif // D3DX_SDK_VERSION < 24
return 0;
}
HRESULT CD3D9ShaderMaterialRenderer::stubD3DXCompileShader(LPCSTR pSrcData, UINT SrcDataLen, CONST D3DXMACRO* pDefines,
LPD3DXINCLUDE pInclude, LPCSTR pFunctionName,
LPCSTR pProfile, DWORD Flags, LPD3DXBUFFER* ppShader,
LPD3DXBUFFER* ppErrorMsgs, LPD3DXCONSTANTTABLE* ppConstantTable)
{
// wondering what I'm doing here?
// see comment in CD3D9ShaderMaterialRenderer::stubD3DXAssembleShader()
#if ( D3DX_SDK_VERSION < 24 )
// directly link functions, old d3d sdks didn't try to load external dlls
// when linking to the d3dx9.lib
#ifdef _MSC_VER
#pragma comment (lib, "d3dx9.lib")
#endif
// invoke static linked function
return D3DXCompileShader(pSrcData, SrcDataLen, pDefines, pInclude, pFunctionName, pProfile, Flags, ppShader, ppErrorMsgs, ppConstantTable);
#else
{
// try to load shader functions from the dll and print error if failed.
// D3DXCompileShader
typedef HRESULT (WINAPI *D3DXCompileShaderFunction)(LPCSTR pSrcData, UINT SrcDataLen, CONST D3DXMACRO* pDefines,
LPD3DXINCLUDE pInclude, LPCSTR pFunctionName,
LPCSTR pProfile, DWORD Flags, LPD3DXBUFFER* ppShader,
LPD3DXBUFFER* ppErrorMsgs, LPD3DXCONSTANTTABLE* ppConstantTable);
static bool LoadFailed = false;
static D3DXCompileShaderFunction pFn = 0;
if (!pFn && !LoadFailed)
{
// try to load dll
io::path strDllName = "d3dx9_";
strDllName += (int)D3DX_SDK_VERSION;
strDllName += ".dll";
HMODULE hMod = LoadLibrary(strDllName.c_str());
if (hMod)
pFn = (D3DXCompileShaderFunction)GetProcAddress(hMod, "D3DXCompileShader");
if (!pFn)
{
LoadFailed = true;
os::Printer::log("Could not load shader function D3DXCompileShader from dll, shaders disabled",
strDllName.c_str(), ELL_ERROR);
}
}
if (pFn)
{
// call already loaded function
return (*pFn)(pSrcData, SrcDataLen, pDefines, pInclude, pFunctionName, pProfile, Flags, ppShader, ppErrorMsgs, ppConstantTable);
}
}
#endif // D3DX_SDK_VERSION < 24
return 0;
}
HRESULT CD3D9ShaderMaterialRenderer::stubD3DXCompileShaderFromFile(LPCSTR pSrcFile, CONST D3DXMACRO* pDefines,
LPD3DXINCLUDE pInclude, LPCSTR pFunctionName,
LPCSTR pProfile, DWORD Flags, LPD3DXBUFFER* ppShader, LPD3DXBUFFER* ppErrorMsgs,
LPD3DXCONSTANTTABLE* ppConstantTable)
{
// wondering what I'm doing here?
// see comment in CD3D9ShaderMaterialRenderer::stubD3DXAssembleShader()
#if ( D3DX_SDK_VERSION < 24 )
// directly link functions, old d3d sdks didn't try to load external dlls
// when linking to the d3dx9.lib
#ifdef _MSC_VER
#pragma comment (lib, "d3dx9.lib")
#endif
// invoke static linked function
return D3DXCompileShaderFromFileA(pSrcFile, pDefines, pInclude, pFunctionName, pProfile, Flags, ppShader, ppErrorMsgs, ppConstantTable);
#else
{
// try to load shader functions from the dll and print error if failed.
// D3DXCompileShaderFromFileA
typedef HRESULT (WINAPI *D3DXCompileShaderFromFileFunction)(LPCSTR pSrcFile,
CONST D3DXMACRO* pDefines, LPD3DXINCLUDE pInclude, LPCSTR pFunctionName,
LPCSTR pProfile, DWORD Flags, LPD3DXBUFFER* ppShader, LPD3DXBUFFER* ppErrorMsgs,
LPD3DXCONSTANTTABLE* ppConstantTable);
static bool LoadFailed = false;
static D3DXCompileShaderFromFileFunction pFn = 0;
if (!pFn && !LoadFailed)
{
// try to load dll
io::path strDllName = "d3dx9_";
strDllName += (int)D3DX_SDK_VERSION;
strDllName += ".dll";
HMODULE hMod = LoadLibrary(strDllName.c_str());
if (hMod)
pFn = (D3DXCompileShaderFromFileFunction)GetProcAddress(hMod, "D3DXCompileShaderFromFileA");
if (!pFn)
{
LoadFailed = true;
os::Printer::log("Could not load shader function D3DXCompileShaderFromFileA from dll, shaders disabled",
strDllName.c_str(), ELL_ERROR);
}
}
if (pFn)
{
// call already loaded function
return (*pFn)(pSrcFile, pDefines, pInclude, pFunctionName, pProfile, Flags, ppShader, ppErrorMsgs, ppConstantTable);
}
}
#endif // D3DX_SDK_VERSION < 24
return 0;
}
} // end namespace video
} // end namespace irr
#endif // _IRR_COMPILE_WITH_DIRECT3D_9_

View File

@ -1,108 +0,0 @@
// Copyright (C) 2002-2012 Nikolaus Gebhardt
// This file is part of the "Irrlicht Engine".
// For conditions of distribution and use, see copyright notice in irrlicht.h
#ifndef __C_D3D9_SHADER_MATERIAL_RENDERER_H_INCLUDED__
#define __C_D3D9_SHADER_MATERIAL_RENDERER_H_INCLUDED__
#include "IrrCompileConfig.h"
#ifdef _IRR_WINDOWS_
#ifdef _IRR_COMPILE_WITH_DIRECT3D_9_
#if defined(__BORLANDC__) || defined (__BCPLUSPLUS__)
#include "irrMath.h" // needed by borland for sqrtf define
#endif
#include <d3dx9shader.h>
#include "IMaterialRenderer.h"
namespace irr
{
namespace video
{
class IVideoDriver;
class IShaderConstantSetCallBack;
class IMaterialRenderer;
//! Class for using vertex and pixel shaders with D3D9
class CD3D9ShaderMaterialRenderer : public IMaterialRenderer
{
public:
//! Public constructor
CD3D9ShaderMaterialRenderer(IDirect3DDevice9* d3ddev, video::IVideoDriver* driver,
s32& outMaterialTypeNr, const c8* vertexShaderProgram, const c8* pixelShaderProgram,
IShaderConstantSetCallBack* callback, IMaterialRenderer* baseMaterial, s32 userData);
//! Destructor
~CD3D9ShaderMaterialRenderer();
virtual void OnSetMaterial(const video::SMaterial& material, const video::SMaterial& lastMaterial,
bool resetAllRenderstates, video::IMaterialRendererServices* services) _IRR_OVERRIDE_;
virtual void OnUnsetMaterial() _IRR_OVERRIDE_;
virtual bool OnRender(IMaterialRendererServices* service, E_VERTEX_TYPE vtxtype) _IRR_OVERRIDE_;
//! Returns if the material is transparent.
virtual bool isTransparent() const _IRR_OVERRIDE_;
//! Access the callback provided by the users when creating shader materials
virtual IShaderConstantSetCallBack* getShaderConstantSetCallBack() const _IRR_OVERRIDE_
{
return CallBack;
}
protected:
//! constructor only for use by derived classes who want to
//! create a fall back material for example.
CD3D9ShaderMaterialRenderer(IDirect3DDevice9* d3ddev,
video::IVideoDriver* driver,
IShaderConstantSetCallBack* callback,
IMaterialRenderer* baseMaterial,
s32 userData=0);
void init(s32& outMaterialTypeNr, const c8* vertexShaderProgram, const c8* pixelShaderProgram);
bool createPixelShader(const c8* pxsh);
bool createVertexShader(const char* vtxsh);
HRESULT stubD3DXAssembleShader(LPCSTR pSrcData, UINT SrcDataLen,
CONST D3DXMACRO* pDefines, LPD3DXINCLUDE pInclude,
DWORD Flags, LPD3DXBUFFER* ppShader,
LPD3DXBUFFER* ppErrorMsgs);
HRESULT stubD3DXAssembleShaderFromFile(LPCSTR pSrcFile,
CONST D3DXMACRO* pDefines, LPD3DXINCLUDE pInclude, DWORD Flags,
LPD3DXBUFFER* ppShader, LPD3DXBUFFER* ppErrorMsgs);
HRESULT stubD3DXCompileShader(LPCSTR pSrcData, UINT SrcDataLen, CONST D3DXMACRO* pDefines,
LPD3DXINCLUDE pInclude, LPCSTR pFunctionName,
LPCSTR pProfile, DWORD Flags, LPD3DXBUFFER* ppShader,
LPD3DXBUFFER* ppErrorMsgs, LPD3DXCONSTANTTABLE* ppConstantTable);
HRESULT stubD3DXCompileShaderFromFile(LPCSTR pSrcFile, CONST D3DXMACRO* pDefines,
LPD3DXINCLUDE pInclude, LPCSTR pFunctionName,
LPCSTR pProfile, DWORD Flags, LPD3DXBUFFER* ppShader, LPD3DXBUFFER* ppErrorMsgs,
LPD3DXCONSTANTTABLE* ppConstantTable);
IDirect3DDevice9* pID3DDevice;
video::IVideoDriver* Driver;
IShaderConstantSetCallBack* CallBack;
IMaterialRenderer* BaseMaterial;
IDirect3DVertexShader9* VertexShader;
IDirect3DVertexShader9* OldVertexShader;
IDirect3DPixelShader9* PixelShader;
s32 UserData;
};
} // end namespace video
} // end namespace irr
#endif
#endif
#endif

View File

@ -1,758 +0,0 @@
// Copyright (C) 2002-2012 Nikolaus Gebhardt
// This file is part of the "Irrlicht Engine".
// For conditions of distribution and use, see copyright notice in irrlicht.h
#include "IrrCompileConfig.h"
#ifdef _IRR_COMPILE_WITH_DIRECT3D_9_
#include "CD3D9Texture.h"
#include "CD3D9Driver.h"
#include "os.h"
namespace irr
{
namespace video
{
CD3D9Texture::CD3D9Texture(const io::path& name, const core::array<IImage*>& image, E_TEXTURE_TYPE type, CD3D9Driver* driver)
: ITexture(name, type), Driver(driver), InternalFormat(D3DFMT_UNKNOWN), LockReadOnly(false), LockData(0), LockLayer(0),
MipLevelLocked(0), HardwareMipMaps(false), Device(0), Texture(0), CubeTexture(0), RTTSurface(0)
{
#ifdef _DEBUG
setDebugName("CD3D9Texture");
#endif
_IRR_DEBUG_BREAK_IF(image.size() == 0)
Device=driver->getExposedVideoData().D3D9.D3DDev9;
if (Device)
Device->AddRef();
DriverType = Driver->getDriverType();
HasMipMaps = Driver->getTextureCreationFlag(ETCF_CREATE_MIP_MAPS);
HardwareMipMaps = Driver->getTextureCreationFlag(ETCF_AUTO_GENERATE_MIP_MAPS) && Driver->queryFeature(EVDF_MIP_MAP_AUTO_UPDATE);
getImageValues(image[0]);
DWORD flags = 0;
if (HasMipMaps && HardwareMipMaps)
{
LPDIRECT3D9 intf = Driver->getExposedVideoData().D3D9.D3D9;
D3DDISPLAYMODE d3ddm;
intf->GetAdapterDisplayMode(Driver->Params.DisplayAdapter, &d3ddm);
if (D3D_OK == intf->CheckDeviceFormat(Driver->Params.DisplayAdapter, D3DDEVTYPE_HAL, d3ddm.Format, D3DUSAGE_AUTOGENMIPMAP, D3DRTYPE_TEXTURE, InternalFormat))
flags = D3DUSAGE_AUTOGENMIPMAP;
else
HardwareMipMaps = false;
}
HRESULT hr = 0;
switch (Type)
{
case ETT_2D:
hr = Device->CreateTexture(Size.Width, Size.Height, HasMipMaps ? 0 : 1, flags, InternalFormat, D3DPOOL_MANAGED, &Texture, NULL);
break;
case ETT_CUBEMAP:
hr = Device->CreateCubeTexture(Size.Width, HasMipMaps ? 0 : 1, flags, InternalFormat, D3DPOOL_MANAGED, &CubeTexture, NULL);
break;
default:
_IRR_DEBUG_BREAK_IF(true)
break;
}
if (FAILED(hr))
{
// Try again with 16-bit format
if (InternalFormat == D3DFMT_A8R8G8B8)
{
InternalFormat = D3DFMT_A1R5G5B5;
ColorFormat = ECF_A1R5G5B5;
}
else if (InternalFormat == D3DFMT_R8G8B8) // (24 bit is usually failing in d3d9, not sure if it's ever supported)
{
InternalFormat = D3DFMT_R5G6B5;
ColorFormat = ECF_R5G6B5;
}
switch (Type)
{
case ETT_2D:
hr = Device->CreateTexture(Size.Width, Size.Height, HasMipMaps ? 0 : 1, flags, InternalFormat, D3DPOOL_MANAGED, &Texture, NULL);
break;
case ETT_CUBEMAP:
hr = Device->CreateCubeTexture(Size.Width, HasMipMaps ? 0 : 1, flags, InternalFormat, D3DPOOL_MANAGED, &CubeTexture, NULL);
break;
}
}
core::array<IImage*> tmpImage = image;
bool releaseImageData = false;
if (SUCCEEDED(hr))
{
if (OriginalSize != Size || OriginalColorFormat != ColorFormat)
{
releaseImageData = true;
for (u32 i = 0; i < image.size(); ++i)
{
tmpImage[i] = Driver->createImage(ColorFormat, Size);
if (image[i]->getDimension() == Size)
image[i]->copyTo(tmpImage[i]);
else
image[i]->copyToScaling(tmpImage[i]);
}
}
for (u32 i = 0; i < tmpImage.size(); ++i)
uploadTexture(tmpImage[i]->getData(), 0, i);
bool autoGenerateRequired = true;
for (u32 i = 0; i < tmpImage.size(); ++i)
{
void* mipmapsData = tmpImage[i]->getMipMapsData();
if (autoGenerateRequired || mipmapsData)
regenerateMipMapLevels(mipmapsData, i);
if (!mipmapsData)
autoGenerateRequired = false;
}
}
else
{
switch (hr )
{
case D3DERR_INVALIDCALL:
os::Printer::log("Could not create DIRECT3D9 Texture. D3DERR_INVALIDCALL", ELL_WARNING);
break;
case D3DERR_OUTOFVIDEOMEMORY:
os::Printer::log("Could not create DIRECT3D9 Texture. D3DERR_OUTOFVIDEOMEMORY", ELL_WARNING);
break;
case E_OUTOFMEMORY:
os::Printer::log("Could not create DIRECT3D9 Texture. E_OUTOFMEMORY", ELL_WARNING);
break;
default:
os::Printer::log("Could not create DIRECT3D9 Texture.", ELL_WARNING);
}
}
if (releaseImageData)
{
for (u32 i = 0; i < tmpImage.size(); ++i)
tmpImage[i]->drop();
}
}
CD3D9Texture::CD3D9Texture(CD3D9Driver* driver, const core::dimension2d<u32>& size, const io::path& name, E_TEXTURE_TYPE type, const ECOLOR_FORMAT format)
: ITexture(name, type), Driver(driver), InternalFormat(D3DFMT_UNKNOWN), LockReadOnly(false), LockData(0), LockLayer(0),
MipLevelLocked(0), HardwareMipMaps(false), Device(0), Texture(0), CubeTexture(0), RTTSurface(0)
{
#ifdef _DEBUG
setDebugName("CD3D9Texture");
#endif
Device = driver->getExposedVideoData().D3D9.D3DDev9;
if (Device)
Device->AddRef();
DriverType = Driver->getDriverType();
HasMipMaps = false;
IsRenderTarget = true;
OriginalColorFormat = format;
if (ECF_UNKNOWN == OriginalColorFormat)
ColorFormat = getBestColorFormat(Driver->getColorFormat());
else
ColorFormat = OriginalColorFormat;
OriginalSize = size;
Size = OriginalSize;
if (!Driver->queryFeature(EVDF_TEXTURE_NPOT))
{
Size = Size.getOptimalSize(true, !Driver->queryFeature(EVDF_TEXTURE_NSQUARE), true, Driver->Caps.MaxTextureWidth);
if (Size != OriginalSize)
os::Printer::log("RenderTarget size has to be a power of two", ELL_INFORMATION);
}
Pitch = Size.Width * IImage::getBitsPerPixelFromFormat(ColorFormat) / 8;
InternalFormat = Driver->getD3DFormatFromColorFormat(ColorFormat);
generateRenderTarget();
}
CD3D9Texture::~CD3D9Texture()
{
releaseTexture();
if (Device)
Device->Release();
}
void* CD3D9Texture::lock(E_TEXTURE_LOCK_MODE mode, u32 mipmapLevel, u32 layer, E_TEXTURE_LOCK_FLAGS lockFlags)
{
if (LockData)
return LockData;
if (IImage::isCompressedFormat(ColorFormat))
return 0;
MipLevelLocked = mipmapLevel;
LockReadOnly = (mode == ETLM_READ_ONLY);
LockLayer = layer;
HRESULT hr;
D3DLOCKED_RECT rect;
if (!IsRenderTarget)
{
if (Texture)
{
hr = Texture->LockRect(MipLevelLocked, &rect, 0, LockReadOnly ? D3DLOCK_READONLY : 0);
}
else if (CubeTexture)
{
_IRR_DEBUG_BREAK_IF(layer > 5)
hr = CubeTexture->LockRect(static_cast<_D3DCUBEMAP_FACES>(layer), MipLevelLocked, &rect, 0, LockReadOnly ? D3DLOCK_READONLY : 0);
}
else
{
os::Printer::log("Could not lock DIRECT3D9 Texture. Missing internal D3D texture.", ELL_ERROR);
return 0;
}
if (FAILED(hr))
{
os::Printer::log("Could not lock DIRECT3D9 Texture.", ELL_ERROR);
return 0;
}
}
else
{
if (!RTTSurface)
{
// Make RTT surface large enough for all miplevels (including 0)
D3DSURFACE_DESC desc;
if (Texture)
Texture->GetLevelDesc(0, &desc);
else if (CubeTexture)
CubeTexture->GetLevelDesc(0, &desc);
hr = Device->CreateOffscreenPlainSurface(desc.Width, desc.Height, desc.Format, D3DPOOL_SYSTEMMEM, &RTTSurface, 0);
if (FAILED(hr))
{
os::Printer::log("Could not lock DIRECT3D9 Texture", "Offscreen surface creation failed.", ELL_ERROR);
return 0;
}
}
IDirect3DSurface9 *surface = 0;
if (Texture)
hr = Texture->GetSurfaceLevel(MipLevelLocked, &surface);
else if (CubeTexture)
hr = CubeTexture->GetCubeMapSurface(static_cast<_D3DCUBEMAP_FACES>(layer), MipLevelLocked, &surface);
if (FAILED(hr))
{
os::Printer::log("Could not lock DIRECT3D9 Texture", "Could not get surface.", ELL_ERROR);
return 0;
}
hr = Device->GetRenderTargetData(surface, RTTSurface);
surface->Release();
if(FAILED(hr))
{
os::Printer::log("Could not lock DIRECT3D9 Texture", "Data copy failed.", ELL_ERROR);
return 0;
}
hr = RTTSurface->LockRect(&rect, 0, LockReadOnly ? D3DLOCK_READONLY : 0);
if(FAILED(hr))
{
os::Printer::log("Could not lock DIRECT3D9 Texture", "LockRect failed.", ELL_ERROR);
return 0;
}
}
LockData = rect.pBits;
return LockData;
}
void CD3D9Texture::unlock()
{
if (!LockData)
return;
if (!IsRenderTarget)
{
if (Texture)
{
Texture->UnlockRect(MipLevelLocked);
}
else if (CubeTexture)
{
CubeTexture->UnlockRect(static_cast<_D3DCUBEMAP_FACES>(LockLayer), MipLevelLocked);
}
}
else if (RTTSurface)
{
RTTSurface->UnlockRect();
}
LockReadOnly = false;
LockData = 0;
LockLayer = 0;
}
void CD3D9Texture::regenerateMipMapLevels(void* data, u32 layer)
{
if (!HasMipMaps || (Size.Width <= 1 && Size.Height <= 1))
return;
if ( HardwareMipMaps )
{
// Can't update with custom data with those unfortunately
// Also MSDN docs don't mention it, but GenerateMipSubLevels only works when AUTOGENMIPMAP is set.
// So we can't call this to get hardware mipmaps when not setting AUTOGENMIPMAP.
if (Texture)
Texture->GenerateMipSubLevels();
else if (CubeTexture)
CubeTexture->GenerateMipSubLevels();
}
else if (data)
{
u32 width = Size.Width;
u32 height = Size.Height;
u8* tmpData = static_cast<u8*>(data);
u32 dataSize = 0;
u32 level = 0;
do
{
if (width > 1)
width >>= 1;
if (height > 1)
height >>= 1;
dataSize = IImage::getDataSizeFromFormat(ColorFormat, width, height);
++level;
uploadTexture(tmpData, level, layer);
tmpData += dataSize;
} while (width != 1 || height != 1);
}
else
{
createManualMipMaps(1);
}
}
void CD3D9Texture::copy16BitMipMap(char* src, char* tgt,
s32 width, s32 height,
s32 pitchsrc, s32 pitchtgt) const
{
for (s32 y=0; y<height; ++y)
{
for (s32 x=0; x<width; ++x)
{
u32 a=0, r=0, g=0, b=0;
for (s32 dy=0; dy<2; ++dy)
{
const s32 tgy = (y*2)+dy;
for (s32 dx=0; dx<2; ++dx)
{
const s32 tgx = (x*2)+dx;
SColor c;
if (ColorFormat == ECF_A1R5G5B5)
c = A1R5G5B5toA8R8G8B8(*(u16*)(&src[(tgx*2)+(tgy*pitchsrc)]));
else
c = R5G6B5toA8R8G8B8(*(u16*)(&src[(tgx*2)+(tgy*pitchsrc)]));
a += c.getAlpha();
r += c.getRed();
g += c.getGreen();
b += c.getBlue();
}
}
a /= 4;
r /= 4;
g /= 4;
b /= 4;
u16 c;
if (ColorFormat == ECF_A1R5G5B5)
c = RGBA16(r,g,b,a);
else
c = A8R8G8B8toR5G6B5(SColor(a,r,g,b).color);
*(u16*)(&tgt[(x*2)+(y*pitchtgt)]) = c;
}
}
}
void CD3D9Texture::copy32BitMipMap(char* src, char* tgt,
s32 width, s32 height,
s32 pitchsrc, s32 pitchtgt) const
{
for (s32 y=0; y<height; ++y)
{
for (s32 x=0; x<width; ++x)
{
u32 a=0, r=0, g=0, b=0;
SColor c;
for (s32 dy=0; dy<2; ++dy)
{
const s32 tgy = (y*2)+dy;
for (s32 dx=0; dx<2; ++dx)
{
const s32 tgx = (x*2)+dx;
c = *(u32*)(&src[(tgx*4)+(tgy*pitchsrc)]);
a += c.getAlpha();
r += c.getRed();
g += c.getGreen();
b += c.getBlue();
}
}
a /= 4;
r /= 4;
g /= 4;
b /= 4;
c.set(a, r, g, b);
*(u32*)(&tgt[(x*4)+(y*pitchtgt)]) = c.color;
}
}
}
bool CD3D9Texture::createManualMipMaps(u32 level)
{
if (level==0)
return true;
if (!Texture) //Manual mips for CubeTexture not supported yet
{
return true;
}
// manual mipmap generation
IDirect3DSurface9* upperSurface = 0;
IDirect3DSurface9* lowerSurface = 0;
// get upper level
HRESULT hr = Texture->GetSurfaceLevel(level-1, &upperSurface);
if (FAILED(hr) || !upperSurface)
{
os::Printer::log("Could not get upper surface level for mip map generation", ELL_WARNING);
return false;
}
// get lower level
hr = Texture->GetSurfaceLevel(level, &lowerSurface);
if (FAILED(hr) || !lowerSurface)
{
os::Printer::log("Could not get lower surface level for mip map generation", ELL_WARNING);
upperSurface->Release();
return false;
}
D3DSURFACE_DESC upperDesc, lowerDesc;
upperSurface->GetDesc(&upperDesc);
lowerSurface->GetDesc(&lowerDesc);
D3DLOCKED_RECT upperlr;
D3DLOCKED_RECT lowerlr;
// lock upper surface
if (FAILED(upperSurface->LockRect(&upperlr, NULL, 0)))
{
upperSurface->Release();
lowerSurface->Release();
os::Printer::log("Could not lock upper texture for mip map generation", ELL_WARNING);
return false;
}
// lock lower surface
if (FAILED(lowerSurface->LockRect(&lowerlr, NULL, 0)))
{
upperSurface->UnlockRect();
upperSurface->Release();
lowerSurface->Release();
os::Printer::log("Could not lock lower texture for mip map generation", ELL_WARNING);
return false;
}
if (upperDesc.Format != lowerDesc.Format)
{
os::Printer::log("Cannot copy mip maps with different formats.", ELL_WARNING);
}
else
{
if ((upperDesc.Format == D3DFMT_A1R5G5B5) || (upperDesc.Format == D3DFMT_R5G6B5))
copy16BitMipMap((char*)upperlr.pBits, (char*)lowerlr.pBits,
lowerDesc.Width, lowerDesc.Height,
upperlr.Pitch, lowerlr.Pitch);
else
if (upperDesc.Format == D3DFMT_A8R8G8B8)
copy32BitMipMap((char*)upperlr.pBits, (char*)lowerlr.pBits,
lowerDesc.Width, lowerDesc.Height,
upperlr.Pitch, lowerlr.Pitch);
else
os::Printer::log("Unsupported mipmap format, cannot copy.", ELL_WARNING);
}
bool result=true;
// unlock
if (FAILED(upperSurface->UnlockRect()))
result=false;
if (FAILED(lowerSurface->UnlockRect()))
result=false;
// release
upperSurface->Release();
lowerSurface->Release();
if (!result || (upperDesc.Width <= 3 && upperDesc.Height <= 3))
return result; // stop generating levels
// generate next level
return createManualMipMaps(level+1);
}
IDirect3DBaseTexture9* CD3D9Texture::getDX9BaseTexture() const
{
return (Texture) ? static_cast<IDirect3DBaseTexture9*>(Texture) : static_cast<IDirect3DBaseTexture9*>(CubeTexture);
}
IDirect3DTexture9* CD3D9Texture::getDX9Texture() const
{
return Texture;
}
IDirect3DCubeTexture9* CD3D9Texture::getDX9CubeTexture() const
{
return CubeTexture;
}
void CD3D9Texture::releaseTexture()
{
if (RTTSurface)
{
if (RTTSurface->Release() == 0)
RTTSurface = 0;
}
if (Texture)
{
if (Texture->Release() == 0)
Texture = 0;
}
if (CubeTexture)
{
if (CubeTexture->Release() == 0)
CubeTexture = 0;
}
}
void CD3D9Texture::generateRenderTarget()
{
DWORD flags = (IImage::isDepthFormat(ColorFormat)) ? D3DUSAGE_DEPTHSTENCIL : D3DUSAGE_RENDERTARGET;
HRESULT hr = 0;
switch (Type)
{
case ETT_2D:
if (!Texture )
hr = Device->CreateTexture(Size.Width, Size.Height, 1, flags, InternalFormat, D3DPOOL_DEFAULT, &Texture, NULL);
break;
case ETT_CUBEMAP:
if (!CubeTexture)
hr = Device->CreateCubeTexture(Size.Width, 1, flags, InternalFormat, D3DPOOL_DEFAULT, &CubeTexture, NULL);
break;
default:
_IRR_DEBUG_BREAK_IF(true)
break;
}
if (FAILED(hr))
{
if (D3DERR_INVALIDCALL == hr)
os::Printer::log("Could not create render target texture", "Invalid Call", irr::ELL_ERROR);
else if (D3DERR_OUTOFVIDEOMEMORY == hr)
os::Printer::log("Could not create render target texture", "Out of Video Memory", irr::ELL_ERROR);
else if (E_OUTOFMEMORY == hr)
os::Printer::log("Could not create render target texture", "Out of Memory", irr::ELL_ERROR);
else
os::Printer::log("Could not create render target texture", irr::ELL_ERROR);
core::stringc params("Width:");
params += (unsigned int)Size.Width;
params += " Height: ";
params += (unsigned int)Size.Height;
params += " flag: ";
params += (unsigned int)flags;
params += " format";
params += (unsigned int)InternalFormat;
params += " Type: ";
params += (unsigned int)Type;
os::Printer::log(params.c_str(), irr::ELL_ERROR);
}
}
ECOLOR_FORMAT CD3D9Texture::getBestColorFormat(ECOLOR_FORMAT format)
{
// We only try for to adapt "simple" formats
ECOLOR_FORMAT destFormat = (format <= ECF_A8R8G8B8) ? ECF_A8R8G8B8 : format;
switch (format)
{
case ECF_A1R5G5B5:
if (!Driver->getTextureCreationFlag(ETCF_ALWAYS_32_BIT))
destFormat = ECF_A1R5G5B5;
break;
case ECF_R5G6B5:
if (!Driver->getTextureCreationFlag(ETCF_ALWAYS_32_BIT))
destFormat = ECF_R5G6B5;
break;
case ECF_A8R8G8B8:
if (Driver->getTextureCreationFlag(ETCF_ALWAYS_16_BIT) ||
Driver->getTextureCreationFlag(ETCF_OPTIMIZED_FOR_SPEED))
destFormat = ECF_A1R5G5B5;
break;
case ECF_R8G8B8:
// Note: Using ECF_A8R8G8B8 even when ETCF_ALWAYS_32_BIT is not set as 24 bit textures fail with too many cards
if (Driver->getTextureCreationFlag(ETCF_ALWAYS_16_BIT) || Driver->getTextureCreationFlag(ETCF_OPTIMIZED_FOR_SPEED))
destFormat = ECF_A1R5G5B5;
default:
break;
}
if (Driver->getTextureCreationFlag(ETCF_NO_ALPHA_CHANNEL))
{
switch (destFormat)
{
case ECF_A1R5G5B5:
destFormat = ECF_R5G6B5;
break;
case ECF_A8R8G8B8:
destFormat = ECF_R8G8B8;
break;
default:
break;
}
}
return destFormat;
}
void CD3D9Texture::getImageValues(const IImage* image)
{
OriginalColorFormat = image->getColorFormat();
ColorFormat = getBestColorFormat(OriginalColorFormat);
InternalFormat = Driver->getD3DFormatFromColorFormat(ColorFormat);
if (IImage::isCompressedFormat(image->getColorFormat()))
{
HardwareMipMaps = false;
}
OriginalSize = image->getDimension();
Size = OriginalSize;
if (Size.Width == 0 || Size.Height == 0)
{
os::Printer::log("Invalid size of image for texture.", ELL_ERROR);
return;
}
const f32 ratio = (f32)Size.Width / (f32)Size.Height;
if ((Size.Width > Driver->Caps.MaxTextureWidth) && (ratio >= 1.f))
{
Size.Width = Driver->Caps.MaxTextureWidth;
Size.Height = (u32)(Driver->Caps.MaxTextureWidth / ratio);
}
else if (Size.Height > Driver->Caps.MaxTextureHeight)
{
Size.Height = Driver->Caps.MaxTextureHeight;
Size.Width = (u32)(Driver->Caps.MaxTextureHeight * ratio);
}
bool needSquare = (!Driver->queryFeature(EVDF_TEXTURE_NSQUARE) || Type == ETT_CUBEMAP);
Size = Size.getOptimalSize(!Driver->queryFeature(EVDF_TEXTURE_NPOT), needSquare, true, Driver->Caps.MaxTextureWidth);
Pitch = Size.Width * IImage::getBitsPerPixelFromFormat(ColorFormat) / 8;
}
void CD3D9Texture::uploadTexture(void* data, u32 mipmapLevel, u32 layer)
{
if (!data)
return;
u32 width = Size.Width >> mipmapLevel;
u32 height = Size.Height >> mipmapLevel;
u32 dataSize = IImage::getDataSizeFromFormat(ColorFormat, width, height);
HRESULT hr = 0;
D3DLOCKED_RECT lockRectangle;
if (Texture)
{
hr = Texture->LockRect(mipmapLevel, &lockRectangle, 0, 0);
}
else if (CubeTexture)
{
_IRR_DEBUG_BREAK_IF(layer > 5)
hr = CubeTexture->LockRect(static_cast<_D3DCUBEMAP_FACES>(layer), mipmapLevel, &lockRectangle, 0, 0);
}
if (FAILED(hr))
{
os::Printer::log("Texture data not copied", "Could not LockRect D3D9 Texture.", ELL_ERROR);
return;
}
memcpy(lockRectangle.pBits, data, dataSize);
if (Texture)
{
hr = Texture->UnlockRect(mipmapLevel);
}
else if (CubeTexture)
{
hr = CubeTexture->UnlockRect(static_cast<_D3DCUBEMAP_FACES>(layer), mipmapLevel);
}
if (FAILED(hr))
{
os::Printer::log("Texture data not copied", "Could not UnlockRect D3D9 Texture.", ELL_ERROR);
}
}
}
}
#endif

View File

@ -1,91 +0,0 @@
// Copyright (C) 2002-2012 Nikolaus Gebhardt
// This file is part of the "Irrlicht Engine".
// For conditions of distribution and use, see copyright notice in irrlicht.h
#ifndef __C_DIRECTX9_TEXTURE_H_INCLUDED__
#define __C_DIRECTX9_TEXTURE_H_INCLUDED__
#include "IrrCompileConfig.h"
#ifdef _IRR_COMPILE_WITH_DIRECT3D_9_
#include "irrArray.h"
#include "ITexture.h"
#include "IImage.h"
#if defined(__BORLANDC__) || defined (__BCPLUSPLUS__)
#include "irrMath.h" // needed by borland for sqrtf define
#endif
#include <d3d9.h>
namespace irr
{
namespace video
{
class CD3D9Driver;
class CD3D9Texture : public ITexture
{
public:
CD3D9Texture(const io::path& name, const core::array<IImage*>& image, E_TEXTURE_TYPE type, CD3D9Driver* driver);
CD3D9Texture(CD3D9Driver* driver, const core::dimension2d<u32>& size, const io::path& name, E_TEXTURE_TYPE type, const ECOLOR_FORMAT format = ECF_UNKNOWN);
virtual ~CD3D9Texture();
virtual void* lock(E_TEXTURE_LOCK_MODE mode = ETLM_READ_WRITE, u32 mipmapLevel=0, u32 layer = 0, E_TEXTURE_LOCK_FLAGS lockFlags = ETLF_FLIP_Y_UP_RTT) _IRR_OVERRIDE_;
virtual void unlock() _IRR_OVERRIDE_;
virtual void regenerateMipMapLevels(void* data = 0, u32 layer = 0) _IRR_OVERRIDE_;
IDirect3DBaseTexture9* getDX9BaseTexture() const;
IDirect3DTexture9* getDX9Texture() const;
IDirect3DCubeTexture9* getDX9CubeTexture() const;
private:
friend class CD3D9Driver;
void releaseTexture();
void generateRenderTarget();
ECOLOR_FORMAT getBestColorFormat(ECOLOR_FORMAT format);
void getImageValues(const IImage* image);
void uploadTexture(void* data, u32 mipmapLevel, u32 layer);
//! Helper function for mipmap generation.
bool createManualMipMaps(u32 level);
//! Helper function for mipmap generation.
void copy16BitMipMap(char* src, char* tgt,
s32 width, s32 height, s32 pitchsrc, s32 pitchtgt) const;
//! Helper function for mipmap generation.
void copy32BitMipMap(char* src, char* tgt,
s32 width, s32 height, s32 pitchsrc, s32 pitchtgt) const;
CD3D9Driver* Driver;
D3DFORMAT InternalFormat;
bool LockReadOnly;
void* LockData;
u32 LockLayer;
u32 MipLevelLocked;
bool HardwareMipMaps;
IDirect3DDevice9* Device;
IDirect3DTexture9* Texture;
IDirect3DCubeTexture9* CubeTexture;
IDirect3DSurface9* RTTSurface;
};
}
}
#endif
#endif

View File

@ -1,431 +0,0 @@
// Copyright (C) 2002-2012 Nikolaus Gebhardt
// This file is part of the "Irrlicht Engine".
// For conditions of distribution and use, see copyright notice in irrlicht.h
//
// This file was originally written by Salvatore Russo.
// I (Nikolaus Gebhardt) did some minor modifications and changes to it and
// integrated it into Irrlicht.
// Thanks a lot to Salvatore for his work on this and that he gave me
// his permission to add it into Irrlicht using the zlib license.
/*
CDMFLoader by Salvatore Russo (September 2005)
See the header file for additional information including use and distribution rights.
*/
#include "IrrCompileConfig.h"
#ifdef _IRR_COMPILE_WITH_DMF_LOADER_
#ifdef _DEBUG
#define _IRR_DMF_DEBUG_
#include "os.h"
#endif
#include "CDMFLoader.h"
#include "CMeshTextureLoader.h"
#include "ISceneManager.h"
#include "IAttributes.h"
#include "SAnimatedMesh.h"
#include "SSkinMeshBuffer.h"
#include "irrString.h"
#include "irrMath.h"
#include "dmfsupport.h"
namespace irr
{
namespace scene
{
/** Constructor*/
CDMFLoader::CDMFLoader(ISceneManager* smgr, io::IFileSystem* filesys)
: SceneMgr(smgr), FileSystem(filesys)
{
#ifdef _DEBUG
IReferenceCounted::setDebugName("CDMFLoader");
#endif
TextureLoader = new CMeshTextureLoader( FileSystem, SceneMgr->getVideoDriver() );
}
void CDMFLoader::addMaterialPath(core::stringc& filename, const core::stringc& matPath)
{
c8 last = matPath.lastChar();
if ( last == '/' || last == '\\' )
filename = matPath+filename;
else
{
core::stringc matPathSlash(matPath);
matPathSlash.append('/');
filename = matPathSlash+filename;
}
}
/**Creates/loads an animated mesh from the file.
\return Pointer to the created mesh. Returns 0 if loading failed.
If you no longer need the mesh, you should call IAnimatedMesh::drop().
See IReferenceCounted::drop() for more information.*/
IAnimatedMesh* CDMFLoader::createMesh(io::IReadFile* file)
{
if (!file)
return 0;
if ( getMeshTextureLoader() )
{
getMeshTextureLoader()->setMeshFile(file);
if ( SceneMgr->getParameters()->existsAttribute(DMF_TEXTURE_PATH) )
getMeshTextureLoader()->setTexturePath( SceneMgr->getParameters()->getAttributeAsString(DMF_TEXTURE_PATH) );
}
video::IVideoDriver* driver = SceneMgr->getVideoDriver();
//Load stringlist
StringList dmfRawFile;
LoadFromFile(file, dmfRawFile);
if (dmfRawFile.size()==0)
return 0;
SMesh * mesh = new SMesh();
u32 i;
dmfHeader header;
//load header
core::array<dmfMaterial> materiali;
if (GetDMFHeader(dmfRawFile, header))
{
//let's set ambient light
SceneMgr->setAmbientLight(header.dmfAmbient);
//let's create the correct number of materials, vertices and faces
dmfVert *verts=new dmfVert[header.numVertices];
dmfFace *faces=new dmfFace[header.numFaces];
//let's get the materials
#ifdef _IRR_DMF_DEBUG_
os::Printer::log("Loading materials", core::stringc(header.numMaterials).c_str());
#endif
GetDMFMaterials(dmfRawFile, materiali, header.numMaterials);
//let's get vertices and faces
#ifdef _IRR_DMF_DEBUG_
os::Printer::log("Loading geometry");
#endif
GetDMFVerticesFaces(dmfRawFile, verts, faces);
//create a meshbuffer for each material, then we'll remove empty ones
#ifdef _IRR_DMF_DEBUG_
os::Printer::log("Creating meshbuffers.");
#endif
for (i=0; i<header.numMaterials; i++)
{
//create a new SMeshBufferLightMap for each material
SSkinMeshBuffer* buffer = new SSkinMeshBuffer();
buffer->Material.MaterialType = video::EMT_LIGHTMAP_LIGHTING;
buffer->Material.Wireframe = false;
buffer->Material.Lighting = true;
mesh->addMeshBuffer(buffer);
buffer->drop();
}
// Build the mesh buffers
#ifdef _IRR_DMF_DEBUG_
os::Printer::log("Adding geometry to mesh.");
#endif
for (i = 0; i < header.numFaces; i++)
{
#ifdef _IRR_DMF_DEBUG_
os::Printer::log("Polygon with #vertices", core::stringc(faces[i].numVerts).c_str());
#endif
if (faces[i].numVerts < 3)
continue;
const core::vector3df normal =
core::triangle3df(verts[faces[i].firstVert].pos,
verts[faces[i].firstVert+1].pos,
verts[faces[i].firstVert+2].pos).getNormal().normalize();
SSkinMeshBuffer* meshBuffer = (SSkinMeshBuffer*)mesh->getMeshBuffer(
faces[i].materialID);
const bool use2TCoords = meshBuffer->Vertices_2TCoords.size() ||
materiali[faces[i].materialID].lightmapName.size();
if (use2TCoords && meshBuffer->Vertices_Standard.size())
meshBuffer->convertTo2TCoords();
const u32 base = meshBuffer->Vertices_2TCoords.size()?meshBuffer->Vertices_2TCoords.size():meshBuffer->Vertices_Standard.size();
// Add this face's verts
if (use2TCoords)
{
// make sure we have the proper type set
meshBuffer->VertexType=video::EVT_2TCOORDS;
for (u32 v = 0; v < faces[i].numVerts; v++)
{
const dmfVert& vv = verts[faces[i].firstVert + v];
video::S3DVertex2TCoords vert(vv.pos,
normal, video::SColor(255,255,255,255), vv.tc, vv.lc);
if (materiali[faces[i].materialID].textureBlend==4 &&
SceneMgr->getParameters()->getAttributeAsBool(DMF_FLIP_ALPHA_TEXTURES))
{
vert.TCoords.set(vv.tc.X,-vv.tc.Y);
}
meshBuffer->Vertices_2TCoords.push_back(vert);
}
}
else
{
for (u32 v = 0; v < faces[i].numVerts; v++)
{
const dmfVert& vv = verts[faces[i].firstVert + v];
video::S3DVertex vert(vv.pos,
normal, video::SColor(255,255,255,255), vv.tc);
if (materiali[faces[i].materialID].textureBlend==4 &&
SceneMgr->getParameters()->getAttributeAsBool(DMF_FLIP_ALPHA_TEXTURES))
{
vert.TCoords.set(vv.tc.X,-vv.tc.Y);
}
meshBuffer->Vertices_Standard.push_back(vert);
}
}
// Now add the indices
// This weird loop turns convex polygons into triangle strips.
// I do it this way instead of a simple fan because it usually
// looks a lot better in wireframe, for example.
u32 h = faces[i].numVerts - 1, l = 0, c; // High, Low, Center
for (u32 v = 0; v < faces[i].numVerts - 2; v++)
{
if (v & 1) // odd
c = h - 1;
else // even
c = l + 1;
meshBuffer->Indices.push_back(base + h);
meshBuffer->Indices.push_back(base + l);
meshBuffer->Indices.push_back(base + c);
if (v & 1) // odd
h--;
else // even
l++;
}
}
delete [] verts;
delete [] faces;
}
// delete all buffers without geometry in it.
#ifdef _IRR_DMF_DEBUG_
os::Printer::log("Cleaning meshbuffers.");
#endif
i = 0;
while(i < mesh->MeshBuffers.size())
{
if (mesh->MeshBuffers[i]->getVertexCount() == 0 ||
mesh->MeshBuffers[i]->getIndexCount() == 0)
{
// Meshbuffer is empty -- drop it
mesh->MeshBuffers[i]->drop();
mesh->MeshBuffers.erase(i);
materiali.erase(i);
}
else
{
i++;
}
}
{
//load textures and lightmaps in materials.
//don't worry if you receive a could not load texture, cause if you don't need
//a particular material in your scene it will be loaded and then destroyed.
#ifdef _IRR_DMF_DEBUG_
os::Printer::log("Loading textures.");
#endif
const bool use_mat_dirs=!SceneMgr->getParameters()->getAttributeAsBool(DMF_IGNORE_MATERIALS_DIRS);
for (i=0; i<mesh->getMeshBufferCount(); i++)
{
//texture and lightmap
video::ITexture *tex = 0;
video::ITexture *lig = 0;
//current buffer to apply material
video::SMaterial& mat = mesh->getMeshBuffer(i)->getMaterial();
//Primary texture is normal
if (materiali[i].textureFlag==0)
{
if (materiali[i].textureBlend==4)
driver->setTextureCreationFlag(video::ETCF_ALWAYS_32_BIT,true);
if ( use_mat_dirs )
addMaterialPath(materiali[i].textureName, materiali[i].pathName);
tex = getMeshTextureLoader() ? getMeshTextureLoader()->getTexture( materiali[i].textureName ) : NULL;
}
//Primary texture is just a color
else if(materiali[i].textureFlag==1)
{
video::SColor color(axtoi(materiali[i].textureName.c_str()));
//just for compatibility with older Irrlicht versions
//to support transparent materials
if (color.getAlpha()!=255 && materiali[i].textureBlend==4)
driver->setTextureCreationFlag(video::ETCF_ALWAYS_32_BIT,true);
video::IImage *immagine= driver->createImage(video::ECF_A8R8G8B8,
core::dimension2d<u32>(8,8));
immagine->fill(color);
tex = driver->addTexture("", immagine);
immagine->drop();
//to support transparent materials
if (color.getAlpha()!=255 && materiali[i].textureBlend==4)
{
mat.MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL;
mat.MaterialTypeParam =(((f32) (color.getAlpha()-1))/255.0f);
}
}
//Lightmap is present
if (materiali[i].lightmapFlag == 0)
{
if ( use_mat_dirs )
addMaterialPath(materiali[i].lightmapName, materiali[i].pathName);
lig = getMeshTextureLoader() ? getMeshTextureLoader()->getTexture(materiali[i].lightmapName) : NULL;
}
else //no lightmap
{
mat.MaterialType = video::EMT_SOLID;
const f32 mult = 100.0f - header.dmfShadow;
mat.AmbientColor=header.dmfAmbient.getInterpolated(video::SColor(255,0,0,0),mult/100.f);
}
if (materiali[i].textureBlend==4)
{
mat.MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL;
mat.MaterialTypeParam =
SceneMgr->getParameters()->getAttributeAsFloat(DMF_ALPHA_CHANNEL_REF);
}
//if texture is present mirror vertically owing to DeleD representation
if (tex && header.dmfVersion<1.1)
{
const core::dimension2d<u32> texsize = tex->getSize();
void* pp = tex->lock();
if (pp)
{
const video::ECOLOR_FORMAT format = tex->getColorFormat();
if (format == video::ECF_A1R5G5B5)
{
s16* p = (s16*)pp;
s16 tmp=0;
for (u32 x=0; x<texsize.Width; x++)
for (u32 y=0; y<texsize.Height/2; y++)
{
tmp=p[y*texsize.Width + x];
p[y*texsize.Width + x] = p[(texsize.Height-y-1)*texsize.Width + x];
p[(texsize.Height-y-1)*texsize.Width + x]=tmp;
}
}
else
if (format == video::ECF_A8R8G8B8)
{
s32* p = (s32*)pp;
s32 tmp=0;
for (u32 x=0; x<texsize.Width; x++)
for (u32 y=0; y<texsize.Height/2; y++)
{
tmp=p[y*texsize.Width + x];
p[y*texsize.Width + x] = p[(texsize.Height-y-1)*texsize.Width + x];
p[(texsize.Height-y-1)*texsize.Width + x]=tmp;
}
}
}
tex->unlock();
tex->regenerateMipMapLevels();
}
//if lightmap is present mirror vertically owing to DeleD rapresentation
if (lig && header.dmfVersion<1.1)
{
const core::dimension2d<u32> ligsize=lig->getSize();
void* pp = lig->lock();
if (pp)
{
video::ECOLOR_FORMAT format = lig->getColorFormat();
if (format == video::ECF_A1R5G5B5)
{
s16* p = (s16*)pp;
s16 tmp=0;
for (u32 x=0; x<ligsize.Width; x++)
{
for (u32 y=0; y<ligsize.Height/2; y++)
{
tmp=p[y*ligsize.Width + x];
p[y*ligsize.Width + x] = p[(ligsize.Height-y-1)*ligsize.Width + x];
p[(ligsize.Height-y-1)*ligsize.Width + x]=tmp;
}
}
}
else if (format == video::ECF_A8R8G8B8)
{
s32* p = (s32*)pp;
s32 tmp=0;
for (u32 x=0; x<ligsize.Width; x++)
{
for (u32 y=0; y<ligsize.Height/2; y++)
{
tmp=p[y*ligsize.Width + x];
p[y*ligsize.Width + x] = p[(ligsize.Height-y-1)*ligsize.Width + x];
p[(ligsize.Height-y-1)*ligsize.Width + x]=tmp;
}
}
}
}
lig->unlock();
lig->regenerateMipMapLevels();
}
mat.setTexture(0, tex);
mat.setTexture(1, lig);
}
}
// create bounding box
for (i = 0; i < mesh->MeshBuffers.size(); ++i)
{
mesh->MeshBuffers[i]->recalculateBoundingBox();
}
mesh->recalculateBoundingBox();
// Set up an animated mesh to hold the mesh
SAnimatedMesh* AMesh = new SAnimatedMesh();
AMesh->Type = EAMT_UNKNOWN;
AMesh->addMesh(mesh);
AMesh->recalculateBoundingBox();
mesh->drop();
return AMesh;
}
/** \brief Tell us if this file is able to be loaded by this class
based on the file extension (e.g. ".bsp")
\return true if file is loadable.*/
bool CDMFLoader::isALoadableFileExtension(const io::path& filename) const
{
return core::hasFileExtension ( filename, "dmf" );
}
} // end namespace scene
} // end namespace irr
#endif // _IRR_COMPILE_WITH_DMF_LOADER_

View File

@ -1,91 +0,0 @@
// Copyright (C) 2002-2012 Nikolaus Gebhardt
// This file is part of the "Irrlicht Engine".
// For conditions of distribution and use, see copyright notice in irrlicht.h
//
// This file was originally written by Salvatore Russo.
// I (Nikolaus Gebhardt) did some minor modifications changes to it and integrated
// it into Irrlicht:
// - removed STL dependency
// - removed log file and replaced it with irrlicht logging
// - adapted code formatting a bit to Irrlicht style
// - removed memory leaks
// Thanks a lot to Salvatore for his work on this and that he gave me
// his permission to add it into Irrlicht.
/*
CDMFLoader by Salvatore Russo
Version 1.3
This loader is used to load DMF files in Irrlicht.
Look at the documentation for a sample application.
Parts of this code are from Murphy McCauley COCTLoader just like
GetFaceNormal() or indexes creation routines and a routine to add faces. So
please refer to COCTLoader.h to know more about rights granted.
You can use this software as you wish but you must not remove these notes about license nor
credits to others for parts of this code.
*/
#ifndef __C_DMF_LOADER_H_INCLUDED__
#define __C_DMF_LOADER_H_INCLUDED__
#include "IMeshLoader.h"
#include "IReadFile.h"
#include "IFileSystem.h"
#include "SMesh.h"
#include "IVideoDriver.h"
#include "ISceneManager.h"
#include "SAnimatedMesh.h"
namespace irr
{
namespace scene
{
/** A class to load DeleD mesh files.*/
class CDMFLoader : public IMeshLoader
{
public:
/** constructor*/
CDMFLoader(ISceneManager* smgr, io::IFileSystem* filesys);
//! returns true if the file maybe is able to be loaded by this class
//! based on the file extension (e.g. ".cob")
virtual bool isALoadableFileExtension(const io::path& filename) const _IRR_OVERRIDE_;
/** creates/loads an animated mesh from the file.
\return Pointer to the created mesh. Returns 0 if loading failed.
If you no longer need the mesh, you should call IAnimatedMesh::drop().
See IReferenceCounted::drop() for more information.*/
virtual IAnimatedMesh* createMesh(io::IReadFile* file) _IRR_OVERRIDE_;
/** loads dynamic lights present in this scene.
Note that loaded lights from DeleD must have the suffix \b dynamic_ and must be \b pointlight.
Irrlicht correctly loads specular color, diffuse color , position and distance of object affected by light.
\return number of lights loaded or 0 if loading failed.*/
int loadLights(const c8 * filename, ISceneManager* smgr,
ISceneNode* parent = 0, s32 base_id = 1000);
/** loads water plains present in this scene.
Note that loaded water plains from DeleD must have the suffix \b water_ and must be \b rectangle (with just 1 rectangular face).
Irrlicht correctly loads position and rotation of water plain as well as texture layers.
\return number of water plains loaded or 0 if loading failed.*/
int loadWaterPlains(const c8 *filename,
ISceneManager* smgr,
ISceneNode * parent = 0,
s32 base_id = 2000,
bool mode = true);
private:
void addMaterialPath(core::stringc& filename, const core::stringc& matPath);
ISceneManager* SceneMgr;
io::IFileSystem* FileSystem;
};
} // end namespace scene
} // end namespace irr
#endif

View File

@ -1,162 +0,0 @@
// Copyright (C) 2002-2012 Nikolaus Gebhardt
// This file is part of the "Irrlicht Engine".
// For conditions of distribution and use, see copyright notice in irrlicht.h
#include "CDefaultSceneNodeAnimatorFactory.h"
#include "CSceneNodeAnimatorCameraFPS.h"
#include "CSceneNodeAnimatorCameraMaya.h"
#include "ICursorControl.h"
#include "ISceneNodeAnimatorCollisionResponse.h"
#include "ISceneManager.h"
namespace irr
{
namespace scene
{
//! Names for scene node types
const c8* const SceneNodeAnimatorTypeNames[] =
{
"flyCircle",
"flyStraight",
"followSpline",
"rotation",
"texture",
"deletion",
"collisionResponse",
"cameraFPS",
"cameraMaya",
0
};
CDefaultSceneNodeAnimatorFactory::CDefaultSceneNodeAnimatorFactory(ISceneManager* mgr, gui::ICursorControl* crs)
: Manager(mgr), CursorControl(crs)
{
#ifdef _DEBUG
setDebugName("CDefaultSceneNodeAnimatorFactory");
#endif
// don't grab the scene manager here to prevent cyclic references
if (CursorControl)
CursorControl->grab();
}
CDefaultSceneNodeAnimatorFactory::~CDefaultSceneNodeAnimatorFactory()
{
if (CursorControl)
CursorControl->drop();
}
//! creates a scene node animator based on its type id
ISceneNodeAnimator* CDefaultSceneNodeAnimatorFactory::createSceneNodeAnimator(ESCENE_NODE_ANIMATOR_TYPE type, ISceneNode* target)
{
scene::ISceneNodeAnimator* anim = 0;
switch(type)
{
case ESNAT_FLY_CIRCLE:
anim = Manager->createFlyCircleAnimator(core::vector3df(0,0,0), 10);
break;
case ESNAT_FLY_STRAIGHT:
anim = Manager->createFlyStraightAnimator(core::vector3df(0,0,0), core::vector3df(100,100,100), 10000, true );
break;
case ESNAT_FOLLOW_SPLINE:
{
core::array<core::vector3df> points;
points.push_back(core::vector3df(0,0,0));
points.push_back(core::vector3df(10,5,10));
anim = Manager->createFollowSplineAnimator(0, points);
}
break;
case ESNAT_ROTATION:
anim = Manager->createRotationAnimator(core::vector3df(0.3f,0,0));
break;
case ESNAT_TEXTURE:
{
core::array<video::ITexture*> textures;
anim = Manager->createTextureAnimator(textures, 250);
}
break;
case ESNAT_DELETION:
anim = Manager->createDeleteAnimator(5000);
break;
case ESNAT_COLLISION_RESPONSE:
anim = Manager->createCollisionResponseAnimator(0, target);
break;
case ESNAT_CAMERA_FPS:
anim = new CSceneNodeAnimatorCameraFPS(CursorControl);
break;
case ESNAT_CAMERA_MAYA:
anim = new CSceneNodeAnimatorCameraMaya(CursorControl);
break;
default:
break;
}
if (anim && target)
target->addAnimator(anim);
return anim;
}
//! creates a scene node animator based on its type name
ISceneNodeAnimator* CDefaultSceneNodeAnimatorFactory::createSceneNodeAnimator(const c8* typeName, ISceneNode* target)
{
return createSceneNodeAnimator( getTypeFromName(typeName), target );
}
//! returns amount of scene node animator types this factory is able to create
u32 CDefaultSceneNodeAnimatorFactory::getCreatableSceneNodeAnimatorTypeCount() const
{
return ESNAT_COUNT;
}
//! returns type of a creatable scene node animator type
ESCENE_NODE_ANIMATOR_TYPE CDefaultSceneNodeAnimatorFactory::getCreateableSceneNodeAnimatorType(u32 idx) const
{
if (idx<ESNAT_COUNT)
return (ESCENE_NODE_ANIMATOR_TYPE)idx;
else
return ESNAT_UNKNOWN;
}
//! returns type name of a creatable scene node animator type
const c8* CDefaultSceneNodeAnimatorFactory::getCreateableSceneNodeAnimatorTypeName(u32 idx) const
{
if (idx<ESNAT_COUNT)
return SceneNodeAnimatorTypeNames[idx];
else
return 0;
}
//! returns type name of a creatable scene node animator type
const c8* CDefaultSceneNodeAnimatorFactory::getCreateableSceneNodeAnimatorTypeName(ESCENE_NODE_ANIMATOR_TYPE type) const
{
// for this factory: index == type
if (type<ESNAT_COUNT)
return SceneNodeAnimatorTypeNames[type];
else
return 0;
}
ESCENE_NODE_ANIMATOR_TYPE CDefaultSceneNodeAnimatorFactory::getTypeFromName(const c8* name) const
{
for ( u32 i=0; SceneNodeAnimatorTypeNames[i]; ++i)
if (!strcmp(name, SceneNodeAnimatorTypeNames[i]) )
return (ESCENE_NODE_ANIMATOR_TYPE)i;
return ESNAT_UNKNOWN;
}
} // end namespace scene
} // end namespace irr

View File

@ -1,75 +0,0 @@
// Copyright (C) 2002-2012 Nikolaus Gebhardt
// This file is part of the "Irrlicht Engine".
// For conditions of distribution and use, see copyright notice in irrlicht.h
#ifndef __C_DEFAULT_SCENE_NODE_ANIMATOR_FACTORY_H_INCLUDED__
#define __C_DEFAULT_SCENE_NODE_ANIMATOR_FACTORY_H_INCLUDED__
#include "ISceneNodeAnimatorFactory.h"
namespace irr
{
namespace gui
{
class ICursorControl;
}
namespace scene
{
class ISceneNodeAnimator;
class ISceneManager;
//! Interface making it possible to dynamicly create scene nodes animators
class CDefaultSceneNodeAnimatorFactory : public ISceneNodeAnimatorFactory
{
public:
CDefaultSceneNodeAnimatorFactory(ISceneManager* mgr, gui::ICursorControl* crs);
virtual ~CDefaultSceneNodeAnimatorFactory();
//! creates a scene node animator based on its type id
/** \param type: Type of the scene node animator to add.
\param target: Target scene node of the new animator.
\return Returns pointer to the new scene node animator or null if not successful. You need to
drop this pointer after calling this, see IReferenceCounted::drop() for details. */
virtual ISceneNodeAnimator* createSceneNodeAnimator(ESCENE_NODE_ANIMATOR_TYPE type, ISceneNode* target) _IRR_OVERRIDE_;
//! creates a scene node animator based on its type name
/** \param typeName: Type of the scene node animator to add.
\param target: Target scene node of the new animator.
\return Returns pointer to the new scene node animator or null if not successful. You need to
drop this pointer after calling this, see IReferenceCounted::drop() for details. */
virtual ISceneNodeAnimator* createSceneNodeAnimator(const char* typeName, ISceneNode* target) _IRR_OVERRIDE_;
//! returns amount of scene node animator types this factory is able to create
virtual u32 getCreatableSceneNodeAnimatorTypeCount() const _IRR_OVERRIDE_;
//! returns type of a creatable scene node animator type
/** \param idx: Index of scene node animator type in this factory. Must be a value between 0 and
getCreatableSceneNodeTypeCount() */
virtual ESCENE_NODE_ANIMATOR_TYPE getCreateableSceneNodeAnimatorType(u32 idx) const _IRR_OVERRIDE_;
//! returns type name of a creatable scene node animator type
/** \param idx: Index of scene node animator type in this factory. Must be a value between 0 and
getCreatableSceneNodeAnimatorTypeCount() */
virtual const c8* getCreateableSceneNodeAnimatorTypeName(u32 idx) const _IRR_OVERRIDE_;
//! returns type name of a creatable scene node animator type
/** \param type: Type of scene node animator.
\return: Returns name of scene node animator type if this factory can create the type, otherwise 0. */
virtual const c8* getCreateableSceneNodeAnimatorTypeName(ESCENE_NODE_ANIMATOR_TYPE type) const _IRR_OVERRIDE_;
private:
ESCENE_NODE_ANIMATOR_TYPE getTypeFromName(const c8* name) const;
ISceneManager* Manager;
gui::ICursorControl* CursorControl;
};
} // end namespace scene
} // end namespace irr
#endif

View File

@ -4,17 +4,11 @@
#include "CDefaultSceneNodeFactory.h"
#include "ISceneManager.h"
#include "ITextSceneNode.h"
#include "IBillboardTextSceneNode.h"
#include "ITerrainSceneNode.h"
#include "IDummyTransformationSceneNode.h"
#include "ICameraSceneNode.h"
#include "IBillboardSceneNode.h"
#include "IAnimatedMeshSceneNode.h"
#include "IParticleSystemSceneNode.h"
#include "ILightSceneNode.h"
#include "IMeshSceneNode.h"
#include "IOctreeSceneNode.h"
namespace irr
{
@ -32,33 +26,12 @@ CDefaultSceneNodeFactory::CDefaultSceneNodeFactory(ISceneManager* mgr)
// don't grab the scene manager here to prevent cyclic references
SupportedSceneNodeTypes.push_back(SSceneNodeTypePair(ESNT_CUBE, "cube"));
SupportedSceneNodeTypes.push_back(SSceneNodeTypePair(ESNT_SPHERE, "sphere"));
SupportedSceneNodeTypes.push_back(SSceneNodeTypePair(ESNT_TEXT, "text"));
SupportedSceneNodeTypes.push_back(SSceneNodeTypePair(ESNT_BILLBOARD_TEXT, "billboardText"));
SupportedSceneNodeTypes.push_back(SSceneNodeTypePair(ESNT_WATER_SURFACE, "waterSurface"));
SupportedSceneNodeTypes.push_back(SSceneNodeTypePair(ESNT_TERRAIN, "terrain"));
SupportedSceneNodeTypes.push_back(SSceneNodeTypePair(ESNT_SKY_BOX, "skyBox"));
SupportedSceneNodeTypes.push_back(SSceneNodeTypePair(ESNT_SKY_DOME, "skyDome"));
SupportedSceneNodeTypes.push_back(SSceneNodeTypePair(ESNT_SHADOW_VOLUME, "shadowVolume"));
SupportedSceneNodeTypes.push_back(SSceneNodeTypePair(ESNT_OCTREE, "octree"));
// Legacy support
SupportedSceneNodeTypes.push_back(SSceneNodeTypePair(ESNT_OCTREE, "octTree"));
SupportedSceneNodeTypes.push_back(SSceneNodeTypePair(ESNT_MESH, "mesh"));
SupportedSceneNodeTypes.push_back(SSceneNodeTypePair(ESNT_LIGHT, "light"));
SupportedSceneNodeTypes.push_back(SSceneNodeTypePair(ESNT_EMPTY, "empty"));
SupportedSceneNodeTypes.push_back(SSceneNodeTypePair(ESNT_DUMMY_TRANSFORMATION, "dummyTransformation"));
SupportedSceneNodeTypes.push_back(SSceneNodeTypePair(ESNT_CAMERA, "camera"));
SupportedSceneNodeTypes.push_back(SSceneNodeTypePair(ESNT_BILLBOARD, "billBoard"));
SupportedSceneNodeTypes.push_back(SSceneNodeTypePair(ESNT_ANIMATED_MESH, "animatedMesh"));
SupportedSceneNodeTypes.push_back(SSceneNodeTypePair(ESNT_PARTICLE_SYSTEM, "particleSystem"));
SupportedSceneNodeTypes.push_back(SSceneNodeTypePair(ESNT_VOLUME_LIGHT, "volumeLight"));
// SupportedSceneNodeTypes.push_back(SSceneNodeTypePair(ESNT_MD3_SCENE_NODE, "md3"));
// legacy, for version <= 1.4.x irr files
SupportedSceneNodeTypes.push_back(SSceneNodeTypePair(ESNT_CAMERA_MAYA, "cameraMaya"));
SupportedSceneNodeTypes.push_back(SSceneNodeTypePair(ESNT_CAMERA_FPS, "cameraFPS"));
SupportedSceneNodeTypes.push_back(SSceneNodeTypePair(ESNT_Q3SHADER_SCENE_NODE, "quake3Shader"));
}
@ -67,55 +40,20 @@ ISceneNode* CDefaultSceneNodeFactory::addSceneNode(ESCENE_NODE_TYPE type, IScene
{
switch(type)
{
case ESNT_CUBE:
return Manager->addCubeSceneNode(10, parent);
case ESNT_SPHERE:
return Manager->addSphereSceneNode(5, 16, parent);
case ESNT_TEXT:
return Manager->addTextSceneNode(0, L"example");
case ESNT_BILLBOARD_TEXT:
return Manager->addBillboardTextSceneNode(0, L"example");
case ESNT_WATER_SURFACE:
return Manager->addWaterSurfaceSceneNode(0, 2.0f, 300.0f, 10.0f, parent);
case ESNT_TERRAIN:
return Manager->addTerrainSceneNode("", parent, -1,
core::vector3df(0.0f,0.0f,0.0f),
core::vector3df(0.0f,0.0f,0.0f),
core::vector3df(1.0f,1.0f,1.0f),
video::SColor(255,255,255,255),
4, ETPS_17, 0, true);
case ESNT_SKY_BOX:
return Manager->addSkyBoxSceneNode(0,0,0,0,0,0, parent);
case ESNT_SKY_DOME:
return Manager->addSkyDomeSceneNode(0, 16, 8, 0.9f, 2.0f, 1000.0f, parent);
case ESNT_SHADOW_VOLUME:
return 0;
case ESNT_OCTREE:
return Manager->addOctreeSceneNode((IMesh*)0, parent, -1, 128, true);
case ESNT_MESH:
return Manager->addMeshSceneNode(0, parent, -1, core::vector3df(),
core::vector3df(), core::vector3df(1,1,1), true);
case ESNT_LIGHT:
return Manager->addLightSceneNode(parent);
case ESNT_EMPTY:
return Manager->addEmptySceneNode(parent);
case ESNT_DUMMY_TRANSFORMATION:
return Manager->addDummyTransformationSceneNode(parent);
case ESNT_CAMERA:
return Manager->addCameraSceneNode(parent);
case ESNT_CAMERA_MAYA:
return Manager->addCameraSceneNodeMaya(parent);
case ESNT_CAMERA_FPS:
return Manager->addCameraSceneNodeFPS(parent);
case ESNT_BILLBOARD:
return Manager->addBillboardSceneNode(parent);
case ESNT_ANIMATED_MESH:
return Manager->addAnimatedMeshSceneNode(0, parent, -1, core::vector3df(),
core::vector3df(), core::vector3df(1,1,1), true);
case ESNT_PARTICLE_SYSTEM:
return Manager->addParticleSystemSceneNode(true, parent);
case ESNT_VOLUME_LIGHT:
return (ISceneNode*)Manager->addVolumeLightSceneNode(parent);
default:
break;
}

View File

@ -1,186 +0,0 @@
// Copyright (C) 2002-2012 Nikolaus Gebhardt / Thomas Alten
// This file is part of the "Irrlicht Engine".
// For conditions of distribution and use, see copyright notice in irrlicht.h
#include "IrrCompileConfig.h"
#include "SoftwareDriver2_compile_config.h"
#include "CDepthBuffer.h"
#ifdef _IRR_COMPILE_WITH_BURNINGSVIDEO_
namespace irr
{
namespace video
{
//! constructor
CDepthBuffer::CDepthBuffer(const core::dimension2d<u32>& size)
: Buffer(0), Size(0,0)
{
#ifdef _DEBUG
setDebugName("CDepthBuffer");
#endif
setSize(size);
}
//! destructor
CDepthBuffer::~CDepthBuffer()
{
if (Buffer)
{
delete[] Buffer;
Buffer = 0;
}
}
//! clears the zbuffer
void CDepthBuffer::clear(f32 value, interlaced_control interlaced)
{
ieee754 zMaxValue;
#ifdef SOFTWARE_DRIVER_2_USE_WBUFFER
zMaxValue.f = 1.f-value;
#else
zMaxValue.f = value;
#endif
memset32_interlaced(Buffer, zMaxValue.u, Pitch, Size.Height, interlaced);
}
//! sets the new size of the buffer
void CDepthBuffer::setSize(const core::dimension2d<u32>& size)
{
if (size == Size)
return;
Size = size;
delete [] Buffer;
Pitch = size.Width * sizeof ( fp24 );
size_t TotalSize = Pitch * size.Height;
Buffer = new u8[align_next(TotalSize,16)];
clear( 1.f, interlace_disabled());
}
//! returns the size of the buffer
const core::dimension2d<u32>& CDepthBuffer::getSize() const
{
return Size;
}
// -----------------------------------------------------------------
//! constructor
CStencilBuffer::CStencilBuffer(const core::dimension2d<u32>& size, unsigned bit)
: Buffer(0), Size(0,0),Bit(bit)
{
#ifdef _DEBUG
setDebugName("CStencilBuffer");
#endif
setSize(size);
}
//! destructor
CStencilBuffer::~CStencilBuffer()
{
if (Buffer)
{
delete[] Buffer;
Buffer = 0;
}
}
//! clears the buffer
void CStencilBuffer::clear(u32 value, const interlaced_control interlaced)
{
u32 set = value;
if (Bit == 8)
{
set |= set << 8;
set |= set << 16;
}
memset32_interlaced ( Buffer, set, Pitch,Size.Height,interlaced );
}
//! sets the new size of the buffer
void CStencilBuffer::setSize(const core::dimension2d<u32>& size)
{
if (size == Size)
return;
Size = size;
delete [] Buffer;
Pitch = size.Width * sizeof (tStencilSample);
size_t TotalSize = Pitch * size.Height;
Buffer = new u8[align_next(TotalSize,16)];
clear(0, interlace_disabled());
}
//! returns the size of the buffer
const core::dimension2d<u32>& CStencilBuffer::getSize() const
{
return Size;
}
} // end namespace video
} // end namespace irr
#endif // _IRR_COMPILE_WITH_BURNINGSVIDEO_
namespace irr
{
namespace video
{
//! creates a ZBuffer
IDepthBuffer* createDepthBuffer(const core::dimension2d<u32>& size)
{
#ifdef _IRR_COMPILE_WITH_BURNINGSVIDEO_
return new CDepthBuffer(size);
#else
return 0;
#endif // _IRR_COMPILE_WITH_BURNINGSVIDEO_
}
//! creates a Stencil Buffer
IStencilBuffer* createStencilBuffer(const core::dimension2d<u32>& size, u32 bit)
{
#ifdef _IRR_COMPILE_WITH_BURNINGSVIDEO_
return new CStencilBuffer(size,bit);
#else
return 0;
#endif // _IRR_COMPILE_WITH_BURNINGSVIDEO_
}
} // end namespace video
} // end namespace irr

View File

@ -1,92 +0,0 @@
// Copyright (C) 2002-2012 Nikolaus Gebhardt / Thomas Alten
// This file is part of the "Irrlicht Engine".
// For conditions of distribution and use, see copyright notice in irrlicht.h
#ifndef __C_Z_BUFFER_H_INCLUDED__
#define __C_Z_BUFFER_H_INCLUDED__
#include "IDepthBuffer.h"
namespace irr
{
namespace video
{
class CDepthBuffer : public IDepthBuffer
{
public:
//! constructor
CDepthBuffer(const core::dimension2d<u32>& size);
//! destructor
virtual ~CDepthBuffer();
//! clears the zbuffer
virtual void clear(f32 value, const interlaced_control interlaced) _IRR_OVERRIDE_;
//! sets the new size of the zbuffer
virtual void setSize(const core::dimension2d<u32>& size) _IRR_OVERRIDE_;
//! returns the size of the zbuffer
virtual const core::dimension2d<u32>& getSize() const _IRR_OVERRIDE_;
//! locks the zbuffer
virtual void* lock() _IRR_OVERRIDE_ { return (void*) Buffer; }
//! unlocks the zbuffer
virtual void unlock() _IRR_OVERRIDE_ {}
//! returns pitch of depthbuffer (in bytes)
virtual u32 getPitch() const _IRR_OVERRIDE_ { return Pitch; }
private:
u8* Buffer;
core::dimension2d<u32> Size;
u32 Pitch;
};
class CStencilBuffer : public IStencilBuffer
{
public:
//! constructor
CStencilBuffer(const core::dimension2d<u32>& size, unsigned bit);
//! destructor
virtual ~CStencilBuffer();
//! clears the zbuffer
virtual void clear(u32 value, const interlaced_control interlaced) _IRR_OVERRIDE_;
//! sets the new size of the zbuffer
virtual void setSize(const core::dimension2d<u32>& size) _IRR_OVERRIDE_;
//! returns the size of the zbuffer
virtual const core::dimension2d<u32>& getSize() const _IRR_OVERRIDE_;
//! locks the zbuffer
virtual void* lock() _IRR_OVERRIDE_ { return (void*) Buffer; }
//! unlocks the zbuffer
virtual void unlock() _IRR_OVERRIDE_ {}
//! returns pitch of depthbuffer (in bytes)
virtual u32 getPitch() const _IRR_OVERRIDE_ { return Pitch; }
private:
u8* Buffer;
core::dimension2d<u32> Size;
u32 Pitch;
u32 Bit;
};
} // end namespace video
} // end namespace irr
#endif

View File

@ -9,10 +9,6 @@
#include "IWriteFile.h"
#include "CZipReader.h"
#include "CMountPointReader.h"
#include "CPakReader.h"
#include "CNPKReader.h"
#include "CTarReader.h"
#include "CWADReader.h"
#include "CFileList.h"
#include "stdio.h"
#include "os.h"

File diff suppressed because it is too large Load Diff

View File

@ -1,67 +0,0 @@
// Copyright (C) 2002-2012 Nikolaus Gebhardt
// This file is part of the "Irrlicht Engine".
// For conditions of distribution and use, see copyright notice in irrlicht.h
#ifndef __C_GEOMETRY_CREATOR_H_INCLUDED__
#define __C_GEOMETRY_CREATOR_H_INCLUDED__
#include "IGeometryCreator.h"
#include "SMeshBuffer.h"
namespace irr
{
namespace scene
{
//! class for creating geometry on the fly
class CGeometryCreator : public IGeometryCreator
{
void addToBuffer(const video::S3DVertex& v, SMeshBuffer* Buffer) const;
public:
virtual IMesh* createCubeMesh(const core::vector3df& size, ECUBE_MESH_TYPE type) const _IRR_OVERRIDE_;
virtual IMesh* createHillPlaneMesh(
const core::dimension2d<f32>& tileSize, const core::dimension2d<u32>& tileCount,
video::SMaterial* material, f32 hillHeight, const core::dimension2d<f32>& countHills,
const core::dimension2d<f32>& textureRepeatCount) const _IRR_OVERRIDE_;
virtual IMesh* createGeoplaneMesh(f32 radius, u32 rows, u32 columns) const _IRR_OVERRIDE_;
virtual IMesh* createTerrainMesh(video::IImage* texture,
video::IImage* heightmap, const core::dimension2d<f32>& stretchSize,
f32 maxHeight, video::IVideoDriver* driver,
const core::dimension2d<u32>& defaultVertexBlockSize,
bool debugBorders=false) const _IRR_OVERRIDE_;
virtual IMesh* createArrowMesh(const u32 tesselationCylinder,
const u32 tesselationCone, const f32 height,
const f32 cylinderHeight, const f32 width0,
const f32 width1, const video::SColor vtxColor0,
const video::SColor vtxColor1) const _IRR_OVERRIDE_;
virtual IMesh* createSphereMesh(f32 radius, u32 polyCountX, u32 polyCountY) const _IRR_OVERRIDE_;
virtual IMesh* createCylinderMesh(f32 radius, f32 length, u32 tesselation,
const video::SColor& color=0xffffffff,
bool closeTop=true, f32 oblique=0.f, u32 normalType=0) const _IRR_OVERRIDE_;
virtual IMesh* createConeMesh(f32 radius, f32 length, u32 tesselation,
const video::SColor& colorTop=0xffffffff,
const video::SColor& colorBottom=0xffffffff,
f32 oblique=0.f) const _IRR_OVERRIDE_;
virtual IMesh* createVolumeLightMesh(
const u32 subdivideU=32, const u32 subdivideV=32,
const video::SColor footColor=0xffffffff,
const video::SColor tailColor=0xffffffff,
const f32 lpDistance = 8.f,
const core::vector3df& lightDim = core::vector3df(1.f,1.2f,1.f)) const _IRR_OVERRIDE_;
};
} // end namespace scene
} // end namespace irr
#endif

View File

@ -1,887 +0,0 @@
// Copyright (C) 2013 Patryk Nadrowski
// Heavily based on the DDS loader implemented by Thomas Alten
// and DDS loader from IrrSpintz implemented by Thomas Ince
// This file is part of the "Irrlicht Engine".
// For conditions of distribution and use, see copyright notice in irrlicht.h
/*
Based on Code from Copyright (c) 2003 Randy Reddig
Based on code from Nvidia's DDS example:
http://www.nvidia.com/object/dxtc_decompression_code.html
mainly c to cpp
*/
#include "CImageLoaderDDS.h"
#if defined(_IRR_COMPILE_WITH_DDS_LOADER_) || defined(_IRR_COMPILE_WITH_DDS_DECODER_LOADER_)
#include "IReadFile.h"
#include "os.h"
#include "CColorConverter.h"
#include "CImage.h"
#include "irrString.h"
// Header flag values
#define DDSD_CAPS 0x00000001
#define DDSD_HEIGHT 0x00000002
#define DDSD_WIDTH 0x00000004
#define DDSD_PITCH 0x00000008
#define DDSD_PIXELFORMAT 0x00001000
#define DDSD_MIPMAPCOUNT 0x00020000
#define DDSD_LINEARSIZE 0x00080000
#define DDSD_DEPTH 0x00800000
// Pixel format flag values
#define DDPF_ALPHAPIXELS 0x00000001
#define DDPF_ALPHA 0x00000002
#define DDPF_FOURCC 0x00000004
#define DDPF_RGB 0x00000040
#define DDPF_COMPRESSED 0x00000080
#define DDPF_LUMINANCE 0x00020000
// Caps1 values
#define DDSCAPS1_COMPLEX 0x00000008
#define DDSCAPS1_TEXTURE 0x00001000
#define DDSCAPS1_MIPMAP 0x00400000
// Caps2 values
#define DDSCAPS2_CUBEMAP 0x00000200
#define DDSCAPS2_CUBEMAP_POSITIVEX 0x00000400
#define DDSCAPS2_CUBEMAP_NEGATIVEX 0x00000800
#define DDSCAPS2_CUBEMAP_POSITIVEY 0x00001000
#define DDSCAPS2_CUBEMAP_NEGATIVEY 0x00002000
#define DDSCAPS2_CUBEMAP_POSITIVEZ 0x00004000
#define DDSCAPS2_CUBEMAP_NEGATIVEZ 0x00008000
#define DDSCAPS2_VOLUME 0x00200000
namespace irr
{
namespace video
{
/*
DDSGetInfo()
extracts relevant info from a dds texture, returns 0 on success
*/
s32 DDSGetInfo(ddsHeader* dds, s32* width, s32* height, eDDSPixelFormat* pf)
{
/* dummy test */
if( dds == NULL )
return -1;
/* test dds header */
if( *((s32*) dds->Magic) != *((s32*) "DDS ") )
return -1;
if( DDSLittleLong( dds->Size ) != 124 )
return -1;
if( !(DDSLittleLong( dds->Flags ) & DDSD_PIXELFORMAT) )
return -1;
if( !(DDSLittleLong( dds->Flags ) & DDSD_CAPS) )
return -1;
/* extract width and height */
if( width != NULL )
*width = DDSLittleLong( dds->Width );
if( height != NULL )
*height = DDSLittleLong( dds->Height );
/* get pixel format */
/* extract fourCC */
const u32 fourCC = dds->PixelFormat.FourCC;
/* test it */
if( fourCC == 0 )
*pf = DDS_PF_ARGB8888;
else if( fourCC == *((u32*) "DXT1") )
*pf = DDS_PF_DXT1;
else if( fourCC == *((u32*) "DXT2") )
*pf = DDS_PF_DXT2;
else if( fourCC == *((u32*) "DXT3") )
*pf = DDS_PF_DXT3;
else if( fourCC == *((u32*) "DXT4") )
*pf = DDS_PF_DXT4;
else if( fourCC == *((u32*) "DXT5") )
*pf = DDS_PF_DXT5;
else
*pf = DDS_PF_UNKNOWN;
/* return ok */
return 0;
}
#ifdef _IRR_COMPILE_WITH_DDS_DECODER_LOADER_
/*
DDSDecompressARGB8888()
decompresses an argb 8888 format texture
*/
s32 DDSDecompressARGB8888(ddsHeader* dds, u8* data, s32 width, s32 height, u8* pixels)
{
/* setup */
u8* in = data;
u8* out = pixels;
/* walk y */
for(s32 y = 0; y < height; y++)
{
/* walk x */
for(s32 x = 0; x < width; x++)
{
*out++ = *in++;
*out++ = *in++;
*out++ = *in++;
*out++ = *in++;
}
}
/* return ok */
return 0;
}
/*!
DDSGetColorBlockColors()
extracts colors from a dds color block
*/
void DDSGetColorBlockColors(ddsColorBlock* block, ddsColor colors[4])
{
u16 word;
/* color 0 */
word = DDSLittleShort( block->colors[ 0 ] );
colors[ 0 ].a = 0xff;
/* extract rgb bits */
colors[ 0 ].b = (u8) word;
colors[ 0 ].b <<= 3;
colors[ 0 ].b |= (colors[ 0 ].b >> 5);
word >>= 5;
colors[ 0 ].g = (u8) word;
colors[ 0 ].g <<= 2;
colors[ 0 ].g |= (colors[ 0 ].g >> 5);
word >>= 6;
colors[ 0 ].r = (u8) word;
colors[ 0 ].r <<= 3;
colors[ 0 ].r |= (colors[ 0 ].r >> 5);
/* same for color 1 */
word = DDSLittleShort( block->colors[ 1 ] );
colors[ 1 ].a = 0xff;
/* extract rgb bits */
colors[ 1 ].b = (u8) word;
colors[ 1 ].b <<= 3;
colors[ 1 ].b |= (colors[ 1 ].b >> 5);
word >>= 5;
colors[ 1 ].g = (u8) word;
colors[ 1 ].g <<= 2;
colors[ 1 ].g |= (colors[ 1 ].g >> 5);
word >>= 6;
colors[ 1 ].r = (u8) word;
colors[ 1 ].r <<= 3;
colors[ 1 ].r |= (colors[ 1 ].r >> 5);
/* use this for all but the super-freak math method */
if( block->colors[ 0 ] > block->colors[ 1 ] )
{
/* four-color block: derive the other two colors.
00 = color 0, 01 = color 1, 10 = color 2, 11 = color 3
these two bit codes correspond to the 2-bit fields
stored in the 64-bit block. */
word = ((u16) colors[ 0 ].r * 2 + (u16) colors[ 1 ].r ) / 3;
/* no +1 for rounding */
/* as bits have been shifted to 888 */
colors[ 2 ].r = (u8) word;
word = ((u16) colors[ 0 ].g * 2 + (u16) colors[ 1 ].g) / 3;
colors[ 2 ].g = (u8) word;
word = ((u16) colors[ 0 ].b * 2 + (u16) colors[ 1 ].b) / 3;
colors[ 2 ].b = (u8) word;
colors[ 2 ].a = 0xff;
word = ((u16) colors[ 0 ].r + (u16) colors[ 1 ].r * 2) / 3;
colors[ 3 ].r = (u8) word;
word = ((u16) colors[ 0 ].g + (u16) colors[ 1 ].g * 2) / 3;
colors[ 3 ].g = (u8) word;
word = ((u16) colors[ 0 ].b + (u16) colors[ 1 ].b * 2) / 3;
colors[ 3 ].b = (u8) word;
colors[ 3 ].a = 0xff;
}
else
{
/* three-color block: derive the other color.
00 = color 0, 01 = color 1, 10 = color 2,
11 = transparent.
These two bit codes correspond to the 2-bit fields
stored in the 64-bit block */
word = ((u16) colors[ 0 ].r + (u16) colors[ 1 ].r) / 2;
colors[ 2 ].r = (u8) word;
word = ((u16) colors[ 0 ].g + (u16) colors[ 1 ].g) / 2;
colors[ 2 ].g = (u8) word;
word = ((u16) colors[ 0 ].b + (u16) colors[ 1 ].b) / 2;
colors[ 2 ].b = (u8) word;
colors[ 2 ].a = 0xff;
/* random color to indicate alpha */
colors[ 3 ].r = 0x00;
colors[ 3 ].g = 0xff;
colors[ 3 ].b = 0xff;
colors[ 3 ].a = 0x00;
}
}
/*
DDSDecodeColorBlock()
decodes a dds color block
fixme: make endian-safe
*/
void DDSDecodeColorBlock(u32* pixel, ddsColorBlock* block, s32 width, u32 colors[4])
{
s32 r, n;
u32 bits;
u32 masks[] = { 3, 12, 3 << 4, 3 << 6 }; /* bit masks = 00000011, 00001100, 00110000, 11000000 */
s32 shift[] = { 0, 2, 4, 6 };
/* r steps through lines in y */
for( r = 0; r < 4; r++, pixel += (width - 4) ) /* no width * 4 as u32 ptr inc will * 4 */
{
/* width * 4 bytes per pixel per line, each j dxtc row is 4 lines of pixels */
/* n steps through pixels */
for( n = 0; n < 4; n++ )
{
bits = block->row[ r ] & masks[ n ];
bits >>= shift[ n ];
switch( bits )
{
case 0:
*pixel = colors[ 0 ];
pixel++;
break;
case 1:
*pixel = colors[ 1 ];
pixel++;
break;
case 2:
*pixel = colors[ 2 ];
pixel++;
break;
case 3:
*pixel = colors[ 3 ];
pixel++;
break;
default:
/* invalid */
pixel++;
break;
}
}
}
}
/*
DDSDecodeAlphaExplicit()
decodes a dds explicit alpha block
*/
void DDSDecodeAlphaExplicit(u32* pixel, ddsAlphaBlockExplicit* alphaBlock, s32 width, u32 alphaZero)
{
s32 row, pix;
u16 word;
ddsColor color;
/* clear color */
color.r = 0;
color.g = 0;
color.b = 0;
/* walk rows */
for( row = 0; row < 4; row++, pixel += (width - 4) )
{
word = DDSLittleShort( alphaBlock->row[ row ] );
/* walk pixels */
for( pix = 0; pix < 4; pix++ )
{
/* zero the alpha bits of image pixel */
*pixel &= alphaZero;
color.a = word & 0x000F;
color.a = color.a | (color.a << 4);
*pixel |= *((u32*) &color);
word >>= 4; /* move next bits to lowest 4 */
pixel++; /* move to next pixel in the row */
}
}
}
/*
DDSDecodeAlpha3BitLinear()
decodes interpolated alpha block
*/
void DDSDecodeAlpha3BitLinear(u32* pixel, ddsAlphaBlock3BitLinear* alphaBlock, s32 width, u32 alphaZero)
{
s32 row, pix;
u32 stuff;
u8 bits[ 4 ][ 4 ];
u16 alphas[ 8 ];
ddsColor aColors[ 4 ][ 4 ];
/* get initial alphas */
alphas[ 0 ] = alphaBlock->alpha0;
alphas[ 1 ] = alphaBlock->alpha1;
/* 8-alpha block */
if( alphas[ 0 ] > alphas[ 1 ] )
{
/* 000 = alpha_0, 001 = alpha_1, others are interpolated */
alphas[ 2 ] = ( 6 * alphas[ 0 ] + alphas[ 1 ]) / 7; /* bit code 010 */
alphas[ 3 ] = ( 5 * alphas[ 0 ] + 2 * alphas[ 1 ]) / 7; /* bit code 011 */
alphas[ 4 ] = ( 4 * alphas[ 0 ] + 3 * alphas[ 1 ]) / 7; /* bit code 100 */
alphas[ 5 ] = ( 3 * alphas[ 0 ] + 4 * alphas[ 1 ]) / 7; /* bit code 101 */
alphas[ 6 ] = ( 2 * alphas[ 0 ] + 5 * alphas[ 1 ]) / 7; /* bit code 110 */
alphas[ 7 ] = ( alphas[ 0 ] + 6 * alphas[ 1 ]) / 7; /* bit code 111 */
}
/* 6-alpha block */
else
{
/* 000 = alpha_0, 001 = alpha_1, others are interpolated */
alphas[ 2 ] = (4 * alphas[ 0 ] + alphas[ 1 ]) / 5; /* bit code 010 */
alphas[ 3 ] = (3 * alphas[ 0 ] + 2 * alphas[ 1 ]) / 5; /* bit code 011 */
alphas[ 4 ] = (2 * alphas[ 0 ] + 3 * alphas[ 1 ]) / 5; /* bit code 100 */
alphas[ 5 ] = ( alphas[ 0 ] + 4 * alphas[ 1 ]) / 5; /* bit code 101 */
alphas[ 6 ] = 0; /* bit code 110 */
alphas[ 7 ] = 255; /* bit code 111 */
}
/* decode 3-bit fields into array of 16 bytes with same value */
/* first two rows of 4 pixels each */
stuff = *((u32*) &(alphaBlock->stuff[ 0 ]));
bits[ 0 ][ 0 ] = (u8) (stuff & 0x00000007);
stuff >>= 3;
bits[ 0 ][ 1 ] = (u8) (stuff & 0x00000007);
stuff >>= 3;
bits[ 0 ][ 2 ] = (u8) (stuff & 0x00000007);
stuff >>= 3;
bits[ 0 ][ 3 ] = (u8) (stuff & 0x00000007);
stuff >>= 3;
bits[ 1 ][ 0 ] = (u8) (stuff & 0x00000007);
stuff >>= 3;
bits[ 1 ][ 1 ] = (u8) (stuff & 0x00000007);
stuff >>= 3;
bits[ 1 ][ 2 ] = (u8) (stuff & 0x00000007);
stuff >>= 3;
bits[ 1 ][ 3 ] = (u8) (stuff & 0x00000007);
/* last two rows */
stuff = *((u32*) &(alphaBlock->stuff[ 3 ])); /* last 3 bytes */
bits[ 2 ][ 0 ] = (u8) (stuff & 0x00000007);
stuff >>= 3;
bits[ 2 ][ 1 ] = (u8) (stuff & 0x00000007);
stuff >>= 3;
bits[ 2 ][ 2 ] = (u8) (stuff & 0x00000007);
stuff >>= 3;
bits[ 2 ][ 3 ] = (u8) (stuff & 0x00000007);
stuff >>= 3;
bits[ 3 ][ 0 ] = (u8) (stuff & 0x00000007);
stuff >>= 3;
bits[ 3 ][ 1 ] = (u8) (stuff & 0x00000007);
stuff >>= 3;
bits[ 3 ][ 2 ] = (u8) (stuff & 0x00000007);
stuff >>= 3;
bits[ 3 ][ 3 ] = (u8) (stuff & 0x00000007);
/* decode the codes into alpha values */
for( row = 0; row < 4; row++ )
{
for( pix=0; pix < 4; pix++ )
{
aColors[ row ][ pix ].r = 0;
aColors[ row ][ pix ].g = 0;
aColors[ row ][ pix ].b = 0;
aColors[ row ][ pix ].a = (u8) alphas[ bits[ row ][ pix ] ];
}
}
/* write out alpha values to the image bits */
for( row = 0; row < 4; row++, pixel += width-4 )
{
for( pix = 0; pix < 4; pix++ )
{
/* zero the alpha bits of image pixel */
*pixel &= alphaZero;
/* or the bits into the prev. nulled alpha */
*pixel |= *((u32*) &(aColors[ row ][ pix ]));
pixel++;
}
}
}
/*
DDSDecompressDXT1()
decompresses a dxt1 format texture
*/
s32 DDSDecompressDXT1(ddsHeader* dds, u8* data, s32 width, s32 height, u8* pixels)
{
s32 x, y, xBlocks, yBlocks;
u32 *pixel;
ddsColorBlock *block;
ddsColor colors[ 4 ];
/* setup */
xBlocks = width / 4;
yBlocks = height / 4;
/* walk y */
for( y = 0; y < yBlocks; y++ )
{
/* 8 bytes per block */
block = (ddsColorBlock*) (data + y * xBlocks * 8);
/* walk x */
for( x = 0; x < xBlocks; x++, block++ )
{
DDSGetColorBlockColors( block, colors );
pixel = (u32*) (pixels + x * 16 + (y * 4) * width * 4);
DDSDecodeColorBlock( pixel, block, width, (u32*) colors );
}
}
/* return ok */
return 0;
}
/*
DDSDecompressDXT3()
decompresses a dxt3 format texture
*/
s32 DDSDecompressDXT3(ddsHeader* dds, u8* data, s32 width, s32 height, u8* pixels)
{
s32 x, y, xBlocks, yBlocks;
u32 *pixel, alphaZero;
ddsColorBlock *block;
ddsAlphaBlockExplicit *alphaBlock;
ddsColor colors[ 4 ];
/* setup */
xBlocks = width / 4;
yBlocks = height / 4;
/* create zero alpha */
colors[ 0 ].a = 0;
colors[ 0 ].r = 0xFF;
colors[ 0 ].g = 0xFF;
colors[ 0 ].b = 0xFF;
alphaZero = *((u32*) &colors[ 0 ]);
/* walk y */
for( y = 0; y < yBlocks; y++ )
{
/* 8 bytes per block, 1 block for alpha, 1 block for color */
block = (ddsColorBlock*) (data + y * xBlocks * 16);
/* walk x */
for( x = 0; x < xBlocks; x++, block++ )
{
/* get alpha block */
alphaBlock = (ddsAlphaBlockExplicit*) block;
/* get color block */
block++;
DDSGetColorBlockColors( block, colors );
/* decode color block */
pixel = (u32*) (pixels + x * 16 + (y * 4) * width * 4);
DDSDecodeColorBlock( pixel, block, width, (u32*) colors );
/* overwrite alpha bits with alpha block */
DDSDecodeAlphaExplicit( pixel, alphaBlock, width, alphaZero );
}
}
/* return ok */
return 0;
}
/*
DDSDecompressDXT5()
decompresses a dxt5 format texture
*/
s32 DDSDecompressDXT5(ddsHeader* dds, u8* data, s32 width, s32 height, u8* pixels)
{
s32 x, y, xBlocks, yBlocks;
u32 *pixel, alphaZero;
ddsColorBlock *block;
ddsAlphaBlock3BitLinear *alphaBlock;
ddsColor colors[ 4 ];
/* setup */
xBlocks = width / 4;
yBlocks = height / 4;
/* create zero alpha */
colors[ 0 ].a = 0;
colors[ 0 ].r = 0xFF;
colors[ 0 ].g = 0xFF;
colors[ 0 ].b = 0xFF;
alphaZero = *((u32*) &colors[ 0 ]);
/* walk y */
for( y = 0; y < yBlocks; y++ )
{
/* 8 bytes per block, 1 block for alpha, 1 block for color */
block = (ddsColorBlock*) (data + y * xBlocks * 16);
/* walk x */
for( x = 0; x < xBlocks; x++, block++ )
{
/* get alpha block */
alphaBlock = (ddsAlphaBlock3BitLinear*) block;
/* get color block */
block++;
DDSGetColorBlockColors( block, colors );
/* decode color block */
pixel = (u32*) (pixels + x * 16 + (y * 4) * width * 4);
DDSDecodeColorBlock( pixel, block, width, (u32*) colors );
/* overwrite alpha bits with alpha block */
DDSDecodeAlpha3BitLinear( pixel, alphaBlock, width, alphaZero );
}
}
/* return ok */
return 0;
}
/*
DDSDecompressDXT2()
decompresses a dxt2 format texture (fixme: un-premultiply alpha)
*/
s32 DDSDecompressDXT2(ddsHeader* dds, u8* data, s32 width, s32 height, u8* pixels)
{
/* decompress dxt3 first */
const s32 r = DDSDecompressDXT3( dds, data, width, height, pixels );
/* return to sender */
return r;
}
/*
DDSDecompressDXT4()
decompresses a dxt4 format texture (fixme: un-premultiply alpha)
*/
s32 DDSDecompressDXT4(ddsHeader* dds, u8* data, s32 width, s32 height, u8* pixels)
{
/* decompress dxt5 first */
const s32 r = DDSDecompressDXT5( dds, data, width, height, pixels );
/* return to sender */
return r;
}
/*
DDSDecompress()
decompresses a dds texture into an rgba image buffer, returns 0 on success
*/
s32 DDSDecompress(ddsHeader* dds, u8* data, u8* pixels)
{
s32 width, height;
eDDSPixelFormat pf;
/* get dds info */
s32 r = DDSGetInfo( dds, &width, &height, &pf );
if ( r )
return r;
/* decompress */
switch( pf )
{
case DDS_PF_ARGB8888:
/* fixme: support other [a]rgb formats */
r = DDSDecompressARGB8888( dds, data, width, height, pixels );
break;
case DDS_PF_DXT1:
r = DDSDecompressDXT1( dds, data, width, height, pixels );
break;
case DDS_PF_DXT2:
r = DDSDecompressDXT2( dds, data, width, height, pixels );
break;
case DDS_PF_DXT3:
r = DDSDecompressDXT3( dds, data, width, height, pixels );
break;
case DDS_PF_DXT4:
r = DDSDecompressDXT4( dds, data, width, height, pixels );
break;
case DDS_PF_DXT5:
r = DDSDecompressDXT5( dds, data, width, height, pixels );
break;
default: // DDS_PF_UNKNOWN
r = -1;
break;
}
/* return to sender */
return r;
}
#endif
//! returns true if the file maybe is able to be loaded by this class
//! based on the file extension (e.g. ".tga")
bool CImageLoaderDDS::isALoadableFileExtension(const io::path& filename) const
{
return core::hasFileExtension(filename, "dds");
}
//! returns true if the file maybe is able to be loaded by this class
bool CImageLoaderDDS::isALoadableFileFormat(io::IReadFile* file) const
{
if (!file)
return false;
c8 MagicWord[4];
file->read(&MagicWord, 4);
return (MagicWord[0] == 'D' && MagicWord[1] == 'D' && MagicWord[2] == 'S');
}
//! creates a surface from the file
IImage* CImageLoaderDDS::loadImage(io::IReadFile* file) const
{
ddsHeader header;
IImage* image = 0;
s32 width, height;
eDDSPixelFormat pixelFormat;
ECOLOR_FORMAT format = ECF_UNKNOWN;
u32 dataSize = 0;
u32 mipMapsDataSize = 0;
bool is3D = false;
bool useAlpha = false;
u32 mipMapCount = 0;
file->seek(0);
file->read(&header, sizeof(ddsHeader));
if (0 == DDSGetInfo(&header, &width, &height, &pixelFormat))
{
is3D = header.Depth > 0 && (header.Flags & DDSD_DEPTH);
if (!is3D)
header.Depth = 1;
useAlpha = header.PixelFormat.Flags & DDPF_ALPHAPIXELS;
if (header.MipMapCount > 0 && (header.Flags & DDSD_MIPMAPCOUNT))
mipMapCount = header.MipMapCount;
#ifdef _IRR_COMPILE_WITH_DDS_DECODER_LOADER_
u32 newSize = file->getSize() - sizeof(ddsHeader);
u8* memFile = new u8[newSize];
file->read(memFile, newSize);
image = new CImage(ECF_A8R8G8B8, core::dimension2d<u32>(width, height));
if (DDSDecompress(&header, memFile, (u8*)image->lock()) == -1)
{
image->unlock();
image->drop();
image = 0;
}
delete[] memFile;
#else
if (header.PixelFormat.Flags & DDPF_RGB) // Uncompressed formats
{
// u32 byteCount = header.PixelFormat.RGBBitCount / 8;
if( header.Flags & DDSD_PITCH )
dataSize = header.PitchOrLinearSize * header.Height * header.Depth * (header.PixelFormat.RGBBitCount / 8);
else
dataSize = header.Width * header.Height * header.Depth * (header.PixelFormat.RGBBitCount / 8);
u8* data = new u8[dataSize];
file->read(data, dataSize);
switch (header.PixelFormat.RGBBitCount) // Bytes per pixel
{
case 16:
{
if (useAlpha)
{
if (header.PixelFormat.ABitMask == 0x8000)
format = ECF_A1R5G5B5;
}
else
{
if (header.PixelFormat.RBitMask == 0xf800)
format = ECF_R5G6B5;
}
break;
}
case 24:
{
if (!useAlpha)
{
if (header.PixelFormat.RBitMask == 0xff0000)
format = ECF_R8G8B8;
}
break;
}
case 32:
{
if (useAlpha)
{
if (header.PixelFormat.RBitMask & 0xff0000)
format = ECF_A8R8G8B8;
else if (header.PixelFormat.RBitMask & 0xff)
{
// convert from A8B8G8R8 to A8R8G8B8
u8 tmp = 0;
for (u32 i = 0; i < dataSize; i += 4)
{
tmp = data[i];
data[i] = data[i+2];
data[i+2] = tmp;
}
}
}
break;
}
}
if (format != ECF_UNKNOWN)
{
if (!is3D) // Currently 3D textures are unsupported.
{
image = new CImage(format, core::dimension2d<u32>(header.Width, header.Height), data, true, true);
}
}
else
{
delete[] data;
}
}
else if (header.PixelFormat.Flags & DDPF_FOURCC) // Compressed formats
{
switch(pixelFormat)
{
case DDS_PF_DXT1:
{
format = ECF_DXT1;
break;
}
case DDS_PF_DXT2:
case DDS_PF_DXT3:
{
format = ECF_DXT3;
break;
}
case DDS_PF_DXT4:
case DDS_PF_DXT5:
{
format = ECF_DXT5;
break;
}
default: // either not compressed or unknown
break;
}
if( format != ECF_UNKNOWN )
{
if (!is3D) // Currently 3D textures are unsupported.
{
dataSize = IImage::getDataSizeFromFormat(format, header.Width, header.Height);
u8* data = new u8[dataSize];
file->read(data, dataSize);
image = new CImage(format, core::dimension2d<u32>(header.Width, header.Height), data, true, true);
if (mipMapCount > 0)
{
u32 tmpWidth = header.Width;
u32 tmpHeight = header.Height;
do
{
if (tmpWidth > 1)
tmpWidth >>= 1;
if (tmpHeight > 1)
tmpHeight >>= 1;
mipMapsDataSize += IImage::getDataSizeFromFormat(format, tmpWidth, tmpHeight);
}
while (tmpWidth != 1 || tmpHeight != 1);
u8* mipMapsData = new u8[mipMapsDataSize];
file->read(mipMapsData, mipMapsDataSize);
image->setMipMapsData(mipMapsData, true, true);
}
}
}
}
#endif
}
return image;
}
//! creates a loader which is able to load dds images
IImageLoader* createImageLoaderDDS()
{
return new CImageLoaderDDS();
}
} // end namespace video
} // end namespace irr
#endif

View File

@ -1,215 +0,0 @@
// Copyright (C) 2002-2012 Thomas Alten
// This file is part of the "Irrlicht Engine".
// For conditions of distribution and use, see copyright notice in irrlicht.h
#ifndef __C_IMAGE_LOADER_DDS_H_INCLUDED__
#define __C_IMAGE_LOADER_DDS_H_INCLUDED__
#include "IrrCompileConfig.h"
#if defined(_IRR_COMPILE_WITH_DDS_LOADER_) || defined(_IRR_COMPILE_WITH_DDS_DECODER_LOADER_)
#include "IImageLoader.h"
namespace irr
{
namespace video
{
/* dds pixel format types */
enum eDDSPixelFormat
{
DDS_PF_ARGB8888,
DDS_PF_DXT1,
DDS_PF_DXT2,
DDS_PF_DXT3,
DDS_PF_DXT4,
DDS_PF_DXT5,
DDS_PF_UNKNOWN
};
// byte-align structures
#include "irrpack.h"
/* structures */
struct ddsPixelFormat
{
u32 Size;
u32 Flags;
u32 FourCC;
u32 RGBBitCount;
u32 RBitMask;
u32 GBitMask;
u32 BBitMask;
u32 ABitMask;
} PACK_STRUCT;
struct ddsCaps
{
u32 caps1;
u32 caps2;
u32 caps3;
u32 caps4;
} PACK_STRUCT;
struct ddsHeader
{
c8 Magic[4];
u32 Size;
u32 Flags;
u32 Height;
u32 Width;
u32 PitchOrLinearSize;
u32 Depth;
u32 MipMapCount;
u32 Reserved1[11];
ddsPixelFormat PixelFormat;
ddsCaps Caps;
u32 Reserved2;
} PACK_STRUCT;
#ifdef _IRR_COMPILE_WITH_DDS_DECODER_LOADER_
struct ddsColorBlock
{
u16 colors[ 2 ];
u8 row[ 4 ];
} PACK_STRUCT;
struct ddsAlphaBlockExplicit
{
u16 row[ 4 ];
} PACK_STRUCT;
struct ddsAlphaBlock3BitLinear
{
u8 alpha0;
u8 alpha1;
u8 stuff[ 6 ];
} PACK_STRUCT;
struct ddsColor
{
u8 r, g, b, a;
} PACK_STRUCT;
#endif
// Default alignment
#include "irrunpack.h"
/* endian tomfoolery */
typedef union
{
f32 f;
c8 c[ 4 ];
}
floatSwapUnion;
#ifndef __BIG_ENDIAN__
#ifdef _SGI_SOURCE
#define __BIG_ENDIAN__
#endif
#endif
#ifdef __BIG_ENDIAN__
s32 DDSBigLong( s32 src ) { return src; }
s16 DDSBigShort( s16 src ) { return src; }
f32 DDSBigFloat( f32 src ) { return src; }
s32 DDSLittleLong( s32 src )
{
return ((src & 0xFF000000) >> 24) |
((src & 0x00FF0000) >> 8) |
((src & 0x0000FF00) << 8) |
((src & 0x000000FF) << 24);
}
s16 DDSLittleShort( s16 src )
{
return ((src & 0xFF00) >> 8) |
((src & 0x00FF) << 8);
}
f32 DDSLittleFloat( f32 src )
{
floatSwapUnion in,out;
in.f = src;
out.c[ 0 ] = in.c[ 3 ];
out.c[ 1 ] = in.c[ 2 ];
out.c[ 2 ] = in.c[ 1 ];
out.c[ 3 ] = in.c[ 0 ];
return out.f;
}
#else /*__BIG_ENDIAN__*/
s32 DDSLittleLong( s32 src ) { return src; }
s16 DDSLittleShort( s16 src ) { return src; }
f32 DDSLittleFloat( f32 src ) { return src; }
s32 DDSBigLong( s32 src )
{
return ((src & 0xFF000000) >> 24) |
((src & 0x00FF0000) >> 8) |
((src & 0x0000FF00) << 8) |
((src & 0x000000FF) << 24);
}
s16 DDSBigShort( s16 src )
{
return ((src & 0xFF00) >> 8) |
((src & 0x00FF) << 8);
}
f32 DDSBigFloat( f32 src )
{
floatSwapUnion in,out;
in.f = src;
out.c[ 0 ] = in.c[ 3 ];
out.c[ 1 ] = in.c[ 2 ];
out.c[ 2 ] = in.c[ 1 ];
out.c[ 3 ] = in.c[ 0 ];
return out.f;
}
#endif /*__BIG_ENDIAN__*/
/*!
Surface Loader for DDS images
*/
class CImageLoaderDDS : public IImageLoader
{
public:
//! returns true if the file maybe is able to be loaded by this class
//! based on the file extension (e.g. ".tga")
virtual bool isALoadableFileExtension(const io::path& filename) const _IRR_OVERRIDE_;
//! returns true if the file maybe is able to be loaded by this class
virtual bool isALoadableFileFormat(io::IReadFile* file) const _IRR_OVERRIDE_;
//! creates a surface from the file
virtual IImage* loadImage(io::IReadFile* file) const _IRR_OVERRIDE_;
};
} // end namespace video
} // end namespace irr
#endif // compiled with DDS loader
#endif

View File

@ -1,229 +0,0 @@
// Copyright (C) 2002-2012 Nikolaus Gebhardt
// This file is part of the "Irrlicht Engine".
// For conditions of distribution and use, see copyright notice in irrlicht.h
#include "CImageLoaderPCX.h"
#ifdef _IRR_COMPILE_WITH_PCX_LOADER_
#include "IReadFile.h"
#include "SColor.h"
#include "CColorConverter.h"
#include "CImage.h"
#include "os.h"
#include "irrString.h"
namespace irr
{
namespace video
{
//! constructor
CImageLoaderPCX::CImageLoaderPCX()
{
#ifdef _DEBUG
setDebugName("CImageLoaderPCX");
#endif
}
//! returns true if the file maybe is able to be loaded by this class
//! based on the file extension (e.g. ".tga")
bool CImageLoaderPCX::isALoadableFileExtension(const io::path& filename) const
{
return core::hasFileExtension ( filename, "pcx" );
}
//! returns true if the file maybe is able to be loaded by this class
bool CImageLoaderPCX::isALoadableFileFormat(io::IReadFile* file) const
{
u8 headerID;
file->read(&headerID, sizeof(headerID));
return headerID == 0x0a;
}
//! creates a image from the file
IImage* CImageLoaderPCX::loadImage(io::IReadFile* file) const
{
SPCXHeader header;
s32* paletteData = 0;
file->read(&header, sizeof(header));
#ifdef __BIG_ENDIAN__
header.XMin = os::Byteswap::byteswap(header.XMin);
header.YMin = os::Byteswap::byteswap(header.YMin);
header.XMax = os::Byteswap::byteswap(header.XMax);
header.YMax = os::Byteswap::byteswap(header.YMax);
header.HorizDPI = os::Byteswap::byteswap(header.HorizDPI);
header.VertDPI = os::Byteswap::byteswap(header.VertDPI);
header.BytesPerLine = os::Byteswap::byteswap(header.BytesPerLine);
header.PaletteType = os::Byteswap::byteswap(header.PaletteType);
header.HScrSize = os::Byteswap::byteswap(header.HScrSize);
header.VScrSize = os::Byteswap::byteswap(header.VScrSize);
#endif
//! return if the header is wrong
if (header.Manufacturer != 0x0a && header.Encoding != 0x01)
return 0;
// return if this isn't a supported type
if ((header.BitsPerPixel != 8) && (header.BitsPerPixel != 4) && (header.BitsPerPixel != 1))
{
os::Printer::log("Unsupported bits per pixel in PCX file.",
file->getFileName(), irr::ELL_WARNING);
return 0;
}
// read palette
if( (header.BitsPerPixel == 8) && (header.Planes == 1) )
{
// the palette indicator (usually a 0x0c is found infront of the actual palette data)
// is ignored because some exporters seem to forget to write it. This would result in
// no image loaded before, now only wrong colors will be set.
const long pos = file->getPos();
file->seek( file->getSize()-256*3, false );
u8 *tempPalette = new u8[768];
paletteData = new s32[256];
file->read( tempPalette, 768 );
for( s32 i=0; i<256; i++ )
{
paletteData[i] = (0xff000000 |
(tempPalette[i*3+0] << 16) |
(tempPalette[i*3+1] << 8) |
(tempPalette[i*3+2]));
}
delete [] tempPalette;
file->seek(pos);
}
else if( header.BitsPerPixel == 4 )
{
paletteData = new s32[16];
for( s32 i=0; i<16; i++ )
{
paletteData[i] = (0xff000000 |
(header.Palette[i*3+0] << 16) |
(header.Palette[i*3+1] << 8) |
(header.Palette[i*3+2]));
}
}
// read image data
const s32 width = header.XMax - header.XMin + 1;
const s32 height = header.YMax - header.YMin + 1;
const s32 imagebytes = header.BytesPerLine * header.Planes * header.BitsPerPixel * height / 8;
u8* PCXData = new u8[imagebytes];
u8 cnt, value;
s32 lineoffset=0, linestart=0, nextmode=1;
for(s32 offset = 0; offset < imagebytes; offset += cnt)
{
file->read(&cnt, 1);
if( !((cnt & 0xc0) == 0xc0) )
{
value = cnt;
cnt = 1;
}
else
{
cnt &= 0x3f;
file->read(&value, 1);
}
if (header.Planes==1)
memset(PCXData+offset, value, cnt);
else
{
for (u8 i=0; i<cnt; ++i)
{
PCXData[linestart+lineoffset]=value;
lineoffset += 3;
if (lineoffset>=3*header.BytesPerLine)
{
lineoffset=nextmode;
if (++nextmode==3)
nextmode=0;
if (lineoffset==0)
linestart += 3*header.BytesPerLine;
}
}
}
}
// create image
video::IImage* image = 0;
s32 pad = (header.BytesPerLine - width * header.BitsPerPixel / 8) * header.Planes;
if (pad < 0)
pad = -pad;
if (header.BitsPerPixel==8)
{
switch(header.Planes) // TODO: Other formats
{
case 1:
image = new CImage(ECF_A1R5G5B5, core::dimension2d<u32>(width, height));
if (image)
CColorConverter::convert8BitTo16Bit(PCXData, (s16*)image->getData(), width, height, paletteData, pad);
break;
case 3:
image = new CImage(ECF_R8G8B8, core::dimension2d<u32>(width, height));
if (image)
CColorConverter::convert24BitTo24Bit(PCXData, (u8*)image->getData(), width, height, pad);
break;
}
}
else if (header.BitsPerPixel==4)
{
if (header.Planes==1)
{
image = new CImage(ECF_A1R5G5B5, core::dimension2d<u32>(width, height));
if (image)
CColorConverter::convert4BitTo16Bit(PCXData, (s16*)image->getData(), width, height, paletteData, pad);
}
}
else if (header.BitsPerPixel==1)
{
if (header.Planes==4)
{
image = new CImage(ECF_A1R5G5B5, core::dimension2d<u32>(width, height));
if (image)
CColorConverter::convert4BitTo16Bit(PCXData, (s16*)image->getData(), width, height, paletteData, pad);
}
else if (header.Planes==1)
{
image = new CImage(ECF_A1R5G5B5, core::dimension2d<u32>(width, height));
if (image)
CColorConverter::convert1BitTo16Bit(PCXData, (s16*)image->getData(), width, height, pad);
}
}
// clean up
delete [] paletteData;
delete [] PCXData;
return image;
}
//! creates a loader which is able to load pcx images
IImageLoader* createImageLoaderPCX()
{
return new CImageLoaderPCX();
}
} // end namespace video
} // end namespace irr
#endif

View File

@ -1,82 +0,0 @@
// Copyright (C) 2002-2012 Nikolaus Gebhardt
// This file is part of the "Irrlicht Engine".
// For conditions of distribution and use, see copyright notice in irrlicht.h
#ifndef __C_IMAGE_LOADER_PCX_H_INCLUDED__
#define __C_IMAGE_LOADER_PCX_H_INCLUDED__
#include "IrrCompileConfig.h"
#include "IImageLoader.h"
namespace irr
{
namespace video
{
#if defined(_IRR_COMPILE_WITH_PCX_LOADER_) || defined(_IRR_COMPILE_WITH_PCX_WRITER_)
// byte-align structures
#include "irrpack.h"
struct SPCXHeader
{
u8 Manufacturer;
u8 Version;
u8 Encoding;
u8 BitsPerPixel;
u16 XMin;
u16 YMin;
u16 XMax;
u16 YMax;
u16 HorizDPI;
u16 VertDPI;
u8 Palette[48];
u8 Reserved;
u8 Planes;
u16 BytesPerLine;
u16 PaletteType;
u16 HScrSize;
u16 VScrSize;
u8 Filler[54];
} PACK_STRUCT;
// Default alignment
#include "irrunpack.h"
#endif // compile with loader or writer
#ifdef _IRR_COMPILE_WITH_PCX_LOADER_
/*!
Image Loader for Windows PCX bitmaps.
This loader was written and sent in by Dean P. Macri. I modified
only some small bits of it.
*/
class CImageLoaderPCX : public IImageLoader
{
public:
//! constructor
CImageLoaderPCX();
//! returns true if the file maybe is able to be loaded by this class
//! based on the file extension (e.g. ".tga")
virtual bool isALoadableFileExtension(const io::path& filename) const _IRR_OVERRIDE_;
//! returns true if the file maybe is able to be loaded by this class
virtual bool isALoadableFileFormat(io::IReadFile* file) const _IRR_OVERRIDE_;
//! creates a surface from the file
virtual IImage* loadImage(io::IReadFile* file) const _IRR_OVERRIDE_;
};
#endif // compile with loader
} // end namespace video
} // end namespace irr
#endif

View File

@ -1,274 +0,0 @@
// Copyright (C) 2007-2012 Christian Stehno
// This file is part of the "Irrlicht Engine".
// For conditions of distribution and use, see copyright notice in irrlicht.h
#include "CImageLoaderPPM.h"
#ifdef _IRR_COMPILE_WITH_PPM_LOADER_
#include "IReadFile.h"
#include "CColorConverter.h"
#include "CImage.h"
#include "os.h"
#include "fast_atof.h"
#include "coreutil.h"
namespace irr
{
namespace video
{
//! constructor
CImageLoaderPPM::CImageLoaderPPM()
{
#ifdef _DEBUG
setDebugName("CImageLoaderPPM");
#endif
}
//! returns true if the file maybe is able to be loaded by this class
//! based on the file extension (e.g. ".tga")
bool CImageLoaderPPM::isALoadableFileExtension(const io::path& filename) const
{
return core::hasFileExtension ( filename, "ppm", "pgm", "pbm" );
}
//! returns true if the file maybe is able to be loaded by this class
bool CImageLoaderPPM::isALoadableFileFormat(io::IReadFile* file) const
{
c8 id[2]={0};
file->read(&id, 2);
return (id[0]=='P' && id[1]>'0' && id[1]<'7');
}
//! creates a surface from the file
IImage* CImageLoaderPPM::loadImage(io::IReadFile* file) const
{
IImage* image;
if (file->getSize() < 12)
return 0;
c8 id[2];
file->read(&id, 2);
if (id[0]!='P' || id[1]<'1' || id[1]>'6')
return 0;
const u8 format = id[1] - '0';
const bool binary = format>3;
core::stringc token;
getNextToken(file, token);
const u32 width = core::strtoul10(token.c_str());
getNextToken(file, token);
const u32 height = core::strtoul10(token.c_str());
u8* data = 0;
const u32 size = width*height;
if (format==1 || format==4)
{
skipToNextToken(file); // go to start of data
const u32 bytesize = size/8+(size & 3)?1:0;
if (binary)
{
if (file->getSize()-file->getPos() < (long)bytesize)
return 0;
data = new u8[bytesize];
file->read(data, bytesize);
}
else
{
if (file->getSize()-file->getPos() < (long)(2*size)) // optimistic test
return 0;
data = new u8[bytesize];
memset(data, 0, bytesize);
u32 shift=0;
for (u32 i=0; i<size; ++i)
{
getNextToken(file, token);
if (token == "1")
data[i/8] |= (0x01 << shift);
if (++shift == 8)
shift=0;
}
}
image = new CImage(ECF_A1R5G5B5, core::dimension2d<u32>(width, height));
if (image)
CColorConverter::convert1BitTo16Bit(data, (s16*)image->getData(), width, height);
}
else
{
getNextToken(file, token);
const u32 maxDepth = core::strtoul10(token.c_str());
if (maxDepth > 255) // no double bytes yet
return 0;
skipToNextToken(file); // go to start of data
if (format==2 || format==5)
{
if (binary)
{
if (file->getSize()-file->getPos() < (long)size)
return 0;
data = new u8[size];
file->read(data, size);
image = new CImage(ECF_A8R8G8B8, core::dimension2d<u32>(width, height));
if (image)
{
u8* ptr = (u8*)image->getData();
for (u32 i=0; i<size; ++i)
{
*ptr++ = data[i];
*ptr++ = data[i];
*ptr++ = data[i];
*ptr++ = 255;
}
}
}
else
{
if (file->getSize()-file->getPos() < (long)(2*size)) // optimistic test
return 0;
image = new CImage(ECF_A8R8G8B8, core::dimension2d<u32>(width, height));
if (image)
{
u8* ptr = (u8*)image->getData();
for (u32 i=0; i<size; ++i)
{
getNextToken(file, token);
const u8 num = (u8)core::strtoul10(token.c_str());
*ptr++ = num;
*ptr++ = num;
*ptr++ = num;
*ptr++ = 255;
}
}
}
}
else
{
const u32 bytesize = 3*size;
if (binary)
{
if (file->getSize()-file->getPos() < (long)bytesize)
return 0;
data = new u8[bytesize];
file->read(data, bytesize);
image = new CImage(ECF_A8R8G8B8, core::dimension2d<u32>(width, height));
if (image)
{
u8* ptr = (u8*)image->getData();
for (u32 i=0; i<size; ++i)
{
*ptr++ = data[3*i];
*ptr++ = data[3*i+1];
*ptr++ = data[3*i+2];
*ptr++ = 255;
}
}
}
else
{
if (file->getSize()-file->getPos() < (long)(2*bytesize)) // optimistic test
return 0;
image = new CImage(ECF_A8R8G8B8, core::dimension2d<u32>(width, height));
if (image)
{
u8* ptr = (u8*)image->getData();
for (u32 i=0; i<size; ++i)
{
getNextToken(file, token);
*ptr++ = (u8)core::strtoul10(token.c_str());
getNextToken(file, token);
*ptr++ = (u8)core::strtoul10(token.c_str());
getNextToken(file, token);
*ptr++ = (u8)core::strtoul10(token.c_str());
*ptr++ = 255;
}
}
}
}
}
delete [] data;
return image;
}
//! read the next token from file
void CImageLoaderPPM::getNextToken(io::IReadFile* file, core::stringc& token) const
{
token = "";
c8 c;
while(file->getPos()<file->getSize())
{
file->read(&c, 1);
if (c=='#')
{
while (c!='\n' && c!='\r' && (file->getPos()<file->getSize()))
file->read(&c, 1);
}
else if (!core::isspace(c))
{
token.append(c);
break;
}
}
while(file->getPos()<file->getSize())
{
file->read(&c, 1);
if (c=='#')
{
while (c!='\n' && c!='\r' && (file->getPos()<file->getSize()))
file->read(&c, 1);
}
else if (!core::isspace(c))
token.append(c);
else
break;
}
}
//! skip to next token (skip whitespace)
void CImageLoaderPPM::skipToNextToken(io::IReadFile* file) const
{
c8 c;
while(file->getPos()<file->getSize())
{
file->read(&c, 1);
if (c=='#')
{
while (c!='\n' && c!='\r' && (file->getPos()<file->getSize()))
file->read(&c, 1);
}
else if (!core::isspace(c))
{
file->seek(-1, true); // put back
break;
}
}
}
//! creates a loader which is able to load windows bitmaps
IImageLoader* createImageLoaderPPM()
{
return new CImageLoaderPPM;
}
} // end namespace video
} // end namespace irr
#endif

View File

@ -1,55 +0,0 @@
// Copyright (C) 2007-2012 Christian Stehno
// This file is part of the "Irrlicht Engine".
// For conditions of distribution and use, see copyright notice in irrlicht.h
#ifndef __C_IMAGE_LOADER_PPM_H_INCLUDED__
#define __C_IMAGE_LOADER_PPM_H_INCLUDED__
#include "IrrCompileConfig.h"
#ifdef _IRR_COMPILE_WITH_PPM_LOADER_
#include "IImageLoader.h"
#include "irrString.h"
namespace irr
{
namespace video
{
/*!
Surface Loader for SUN Pixmaps
*/
class CImageLoaderPPM : public IImageLoader
{
public:
//! constructor
CImageLoaderPPM();
//! returns true if the file maybe is able to be loaded by this class
//! based on the file extension (e.g. ".tga")
virtual bool isALoadableFileExtension(const io::path& filename) const _IRR_OVERRIDE_;
//! returns true if the file maybe is able to be loaded by this class
virtual bool isALoadableFileFormat(io::IReadFile* file) const _IRR_OVERRIDE_;
//! creates a surface from the file
virtual IImage* loadImage(io::IReadFile* file) const _IRR_OVERRIDE_;
private:
//! read the next token from file
void getNextToken(io::IReadFile* file, core::stringc& token) const;
//! skip to next token (skip whitespace)
void skipToNextToken(io::IReadFile* file) const;
};
} // end namespace video
} // end namespace irr
#endif
#endif

View File

@ -1,375 +0,0 @@
// Copyright (C) 2002-2012 Nikolaus Gebhardt
// This file is part of the "Irrlicht Engine".
// For conditions of distribution and use, see copyright notice in irrlicht.h
#include "CImageLoaderPSD.h"
#ifdef _IRR_COMPILE_WITH_PSD_LOADER_
#include "IReadFile.h"
#include "os.h"
#include "CImage.h"
#include "irrString.h"
namespace irr
{
namespace video
{
//! constructor
CImageLoaderPSD::CImageLoaderPSD()
{
#ifdef _DEBUG
setDebugName("CImageLoaderPSD");
#endif
}
//! returns true if the file maybe is able to be loaded by this class
//! based on the file extension (e.g. ".tga")
bool CImageLoaderPSD::isALoadableFileExtension(const io::path& filename) const
{
return core::hasFileExtension ( filename, "psd" );
}
//! returns true if the file maybe is able to be loaded by this class
bool CImageLoaderPSD::isALoadableFileFormat(io::IReadFile* file) const
{
if (!file)
return false;
u8 type[3];
file->read(&type, sizeof(u8)*3);
return (type[2]==2); // we currently only handle tgas of type 2.
}
//! creates a surface from the file
IImage* CImageLoaderPSD::loadImage(io::IReadFile* file) const
{
u32* imageData = 0;
PsdHeader header;
file->read(&header, sizeof(PsdHeader));
#ifndef __BIG_ENDIAN__
header.version = os::Byteswap::byteswap(header.version);
header.channels = os::Byteswap::byteswap(header.channels);
header.height = os::Byteswap::byteswap(header.height);
header.width = os::Byteswap::byteswap(header.width);
header.depth = os::Byteswap::byteswap(header.depth);
header.mode = os::Byteswap::byteswap(header.mode);
#endif
if (header.signature[0] != '8' ||
header.signature[1] != 'B' ||
header.signature[2] != 'P' ||
header.signature[3] != 'S')
return 0;
if (header.version != 1)
{
os::Printer::log("Unsupported PSD file version", file->getFileName(), ELL_ERROR);
return 0;
}
if (header.mode != 3 || header.depth != 8)
{
os::Printer::log("Unsupported PSD color mode or depth.\n", file->getFileName(), ELL_ERROR);
return 0;
}
// skip color mode data
u32 l;
file->read(&l, sizeof(u32));
#ifndef __BIG_ENDIAN__
l = os::Byteswap::byteswap(l);
#endif
if (!file->seek(l, true))
{
os::Printer::log("Error seeking file pos to image resources.\n", file->getFileName(), ELL_ERROR);
return 0;
}
// skip image resources
file->read(&l, sizeof(u32));
#ifndef __BIG_ENDIAN__
l = os::Byteswap::byteswap(l);
#endif
if (!file->seek(l, true))
{
os::Printer::log("Error seeking file pos to layer and mask.\n", file->getFileName(), ELL_ERROR);
return 0;
}
// skip layer & mask
file->read(&l, sizeof(u32));
#ifndef __BIG_ENDIAN__
l = os::Byteswap::byteswap(l);
#endif
if (!file->seek(l, true))
{
os::Printer::log("Error seeking file pos to image data section.\n", file->getFileName(), ELL_ERROR);
return 0;
}
// read image data
u16 compressionType;
file->read(&compressionType, sizeof(u16));
#ifndef __BIG_ENDIAN__
compressionType = os::Byteswap::byteswap(compressionType);
#endif
if (compressionType != 1 && compressionType != 0)
{
os::Printer::log("Unsupported psd compression mode.\n", file->getFileName(), ELL_ERROR);
return 0;
}
// create image data block
imageData = new u32[header.width * header.height];
bool res = false;
if (compressionType == 0)
res = readRawImageData(file, header, imageData); // RAW image data
else
res = readRLEImageData(file, header, imageData); // RLE compressed data
video::IImage* image = 0;
if (res)
{
// create surface
image = new CImage(ECF_A8R8G8B8,
core::dimension2d<u32>(header.width, header.height), imageData);
}
if (!image)
delete [] imageData;
imageData = 0;
return image;
}
bool CImageLoaderPSD::readRawImageData(io::IReadFile* file, const PsdHeader& header, u32* imageData) const
{
u8* tmpData = new u8[header.width * header.height];
for (s32 channel=0; channel<header.channels && channel < 3; ++channel)
{
if (!file->read(tmpData, sizeof(c8) * header.width * header.height))
{
os::Printer::log("Error reading color channel\n", file->getFileName(), ELL_ERROR);
break;
}
s16 shift = getShiftFromChannel((c8)channel, header);
if (shift != -1)
{
u32 mask = 0xff << shift;
for (u32 x=0; x<header.width; ++x)
{
for (u32 y=0; y<header.height; ++y)
{
s32 index = x + y*header.width;
imageData[index] = ~(~imageData[index] | mask);
imageData[index] |= tmpData[index] << shift;
}
}
}
}
delete [] tmpData;
return true;
}
bool CImageLoaderPSD::readRLEImageData(io::IReadFile* file, const PsdHeader& header, u32* imageData) const
{
/* If the compression code is 1, the image data
starts with the byte counts for all the scan lines in the channel
(LayerBottom LayerTop), with each count stored as a two
byte value. The RLE compressed data follows, with each scan line
compressed separately. The RLE compression is the same compres-sion
algorithm used by the Macintosh ROM routine PackBits, and
the TIFF standard.
If the Layer's Size, and therefore the data, is odd, a pad byte will
be inserted at the end of the row.
*/
/*
A pseudo code fragment to unpack might look like this:
Loop until you get the number of unpacked bytes you are expecting:
Read the next source byte into n.
If n is between 0 and 127 inclusive, copy the next n+1 bytes literally.
Else if n is between -127 and -1 inclusive, copy the next byte -n+1
times.
Else if n is -128, noop.
Endloop
In the inverse routine, it is best to encode a 2-byte repeat run as a replicate run
except when preceded and followed by a literal run. In that case, it is best to merge
the three runs into one literal run. Always encode 3-byte repeats as replicate runs.
That is the essence of the algorithm. Here are some additional rules:
- Pack each row separately. Do not compress across row boundaries.
- The number of uncompressed bytes per row is defined to be (ImageWidth + 7)
/ 8. If the uncompressed bitmap is required to have an even number of bytes per
row, decompress into word-aligned buffers.
- If a run is larger than 128 bytes, encode the remainder of the run as one or more
additional replicate runs.
When PackBits data is decompressed, the result should be interpreted as per com-pression
type 1 (no compression).
*/
u8* tmpData = new u8[header.width * header.height];
u16 *rleCount= new u16 [header.height * header.channels];
s32 size=0;
for (u32 y=0; y<header.height * header.channels; ++y)
{
if (!file->read(&rleCount[y], sizeof(u16)))
{
delete [] tmpData;
delete [] rleCount;
os::Printer::log("Error reading rle rows\n", file->getFileName(), ELL_ERROR);
return false;
}
#ifndef __BIG_ENDIAN__
rleCount[y] = os::Byteswap::byteswap(rleCount[y]);
#endif
size += rleCount[y];
}
s8 *buf = new s8[size];
if (!file->read(buf, size))
{
delete [] rleCount;
delete [] buf;
delete [] tmpData;
os::Printer::log("Error reading rle rows\n", file->getFileName(), ELL_ERROR);
return false;
}
u16 *rcount=rleCount;
s8 rh;
u16 bytesRead;
u8 *dest;
s8 *pBuf = buf;
// decompress packbit rle
for (s32 channel=0; channel<header.channels; channel++)
{
for (u32 y=0; y<header.height; ++y, ++rcount)
{
bytesRead=0;
dest = &tmpData[y*header.width];
while (bytesRead < *rcount)
{
rh = *pBuf++;
++bytesRead;
if (rh >= 0)
{
++rh;
while (rh--)
{
*dest = *pBuf++;
++bytesRead;
++dest;
}
}
else
if (rh > -128)
{
rh = -rh +1;
while (rh--)
{
*dest = *pBuf;
++dest;
}
++pBuf;
++bytesRead;
}
}
}
s16 shift = getShiftFromChannel((c8)channel, header);
if (shift != -1)
{
u32 mask = 0xff << shift;
for (u32 x=0; x<header.width; ++x)
for (u32 y=0; y<header.height; ++y)
{
s32 index = x + y*header.width;
imageData[index] = ~(~imageData[index] | mask);
imageData[index] |= tmpData[index] << shift;
}
}
}
delete [] rleCount;
delete [] buf;
delete [] tmpData;
return true;
}
s16 CImageLoaderPSD::getShiftFromChannel(c8 channelNr, const PsdHeader& header) const
{
switch(channelNr)
{
case 0:
return 16; // red
case 1:
return 8; // green
case 2:
return 0; // blue
case 3:
return header.channels == 4 ? 24 : -1; // ?
case 4:
return 24; // alpha
default:
return -1;
}
}
//! creates a loader which is able to load tgas
IImageLoader* createImageLoaderPSD()
{
return new CImageLoaderPSD();
}
} // end namespace video
} // end namespace irr
#endif

View File

@ -1,72 +0,0 @@
// Copyright (C) 2002-2012 Nikolaus Gebhardt
// This file is part of the "Irrlicht Engine".
// For conditions of distribution and use, see copyright notice in irrlicht.h
#ifndef __C_IMAGE_LOADER_PSD_H_INCLUDED__
#define __C_IMAGE_LOADER_PSD_H_INCLUDED__
#include "IrrCompileConfig.h"
#ifdef _IRR_COMPILE_WITH_PSD_LOADER_
#include "IImageLoader.h"
namespace irr
{
namespace video
{
// byte-align structures
#include "irrpack.h"
struct PsdHeader
{
c8 signature [4]; // Always equal to 8BPS.
u16 version; // Always equal to 1
c8 reserved [6]; // Must be zero
u16 channels; // Number of any channels inc. alphas
u32 height; // Rows Height of image in pixel
u32 width; // Colums Width of image in pixel
u16 depth; // Bits/channel
u16 mode; // Color mode of the file (Bitmap/Grayscale..)
} PACK_STRUCT;
// Default alignment
#include "irrunpack.h"
/*!
Surface Loader for psd images
*/
class CImageLoaderPSD : public IImageLoader
{
public:
//! constructor
CImageLoaderPSD();
//! returns true if the file maybe is able to be loaded by this class
//! based on the file extension (e.g. ".tga")
virtual bool isALoadableFileExtension(const io::path& filename) const _IRR_OVERRIDE_;
//! returns true if the file maybe is able to be loaded by this class
virtual bool isALoadableFileFormat(io::IReadFile* file) const _IRR_OVERRIDE_;
//! creates a surface from the file
virtual IImage* loadImage(io::IReadFile* file) const _IRR_OVERRIDE_;
private:
bool readRawImageData(io::IReadFile* file, const PsdHeader& header, u32* imageData) const;
bool readRLEImageData(io::IReadFile* file, const PsdHeader& header, u32* imageData) const;
s16 getShiftFromChannel(c8 channelNr, const PsdHeader& header) const;
};
} // end namespace video
} // end namespace irr
#endif
#endif

View File

@ -1,266 +0,0 @@
// Copyright (C) 2013-2016 Patryk Nadrowski
// This file is part of the "Irrlicht Engine".
// For conditions of distribution and use, see copyright notice in irrlicht.h
#include "CImageLoaderPVR.h"
#ifdef _IRR_COMPILE_WITH_PVR_LOADER_
#include "IReadFile.h"
#include "os.h"
#include "CImage.h"
#include "irrString.h"
namespace irr
{
namespace video
{
bool CImageLoaderPVR::isALoadableFileExtension(const io::path& filename) const
{
return core::hasFileExtension(filename, "pvr");
}
bool CImageLoaderPVR::isALoadableFileFormat(io::IReadFile* file) const
{
if (!file)
return false;
c8 fourCC[4];
file->seek(0);
file->read(&fourCC, 4);
/*if (header.Version == 0x03525650) // TO-DO - fix endiannes
{
fourCC[0] = os::Byteswap::byteswap(fourCC[0]);
fourCC[1] = os::Byteswap::byteswap(fourCC[1]);
fourCC[2] = os::Byteswap::byteswap(fourCC[2]);
fourCC[3] = os::Byteswap::byteswap(fourCC[3]);
}*/
return (fourCC[0] == 'P' && fourCC[1] == 'V' && fourCC[2] == 'R');
}
IImage* CImageLoaderPVR::loadImage(io::IReadFile* file) const
{
core::array<IImage*> imageArray = loadImages(file, 0);
const u32 imageCount = imageArray.size();
for (u32 i = 1; i < imageCount; ++i)
{
if (imageArray[i])
imageArray[i]->drop();
}
if (imageCount > 1)
imageArray.erase(1, imageCount - 1);
return (imageCount > 1) ? imageArray[0] : 0;
}
core::array<IImage*> CImageLoaderPVR::loadImages(io::IReadFile* file, E_TEXTURE_TYPE* type) const
{
// TO-DO -> use 'move' feature from C++11 standard.
SPVRHeader header;
core::array<IImage*> imageArray;
core::array<u8*> mipMapsDataArray;
ECOLOR_FORMAT format = ECF_UNKNOWN;
u32 dataSize = 0;
file->seek(0);
file->read(&header, sizeof(SPVRHeader));
/*if (header.Version == 0x03525650) // TO-DO - fix endiannes
{
header.Flags = os::Byteswap::byteswap(header.Flags);
header.PixelFormat = os::Byteswap::byteswap(header.PixelFormat);
header.ColourSpace = os::Byteswap::byteswap(header.ColourSpace);
header.ChannelType = os::Byteswap::byteswap(header.ChannelType);
header.Height = os::Byteswap::byteswap(header.Height);
header.Width = os::Byteswap::byteswap(header.Width);
header.Depth = os::Byteswap::byteswap(header.Depth);
header.NumSurfaces = os::Byteswap::byteswap(header.NumSurfaces);
header.NumFaces = os::Byteswap::byteswap(header.NumFaces);
header.MipMapCount = os::Byteswap::byteswap(header.MipMapCount);
header.MetDataSize = os::Byteswap::byteswap(header.MetDataSize);
}*/
c8 fourCC[4];
u32 key;
u32 helperDataSize;
if (header.MetDataSize > 0)
{
file->read(&fourCC, 4);
file->read(&key, sizeof(u32));
file->read(&helperDataSize, sizeof(u32));
file->seek(helperDataSize, true);
}
if (header.PixelFormat & 0xFFFFFFFF00000000)
{
switch (header.PixelFormat)
{
case 0x505050162677261:
format = ECF_A1R5G5B5;
break;
case 0x5060500626772:
format = ECF_R5G6B5;
break;
case 0x8080800626772:
format = ECF_R8G8B8;
break;
case 0x808080861726762:
format = ECF_A8R8G8B8;
break;
default:
break;
}
}
else // Compressed texture formats
{
switch (header.PixelFormat)
{
case 0: // PVRTC 2bpp RGB
format = ECF_PVRTC_RGB2;
break;
case 1: // PVRTC 2bpp RGBA
format = ECF_PVRTC_ARGB2;
break;
case 2: // PVRTC 4bpp RGB
format = ECF_PVRTC_RGB4;
break;
case 3: // PVRTC 4bpp RGBA
format = ECF_PVRTC_ARGB4;
break;
case 4: // PVRTC-II 2bpp
format = ECF_PVRTC2_ARGB2;
break;
case 5: // PVRTC-II 4bpp
format = ECF_PVRTC2_ARGB4;
break;
case 6: // ETC1
format = ECF_ETC1;
break;
case 7: // DXT1 / BC1
format = ECF_DXT1;
break;
case 8: // DXT2
case 9: // DXT3 / BC2
format = ECF_DXT3;
break;
case 10: // DXT4
case 11: // DXT5 / BC3
format = ECF_DXT5;
break;
case 22: // ETC2 RGB
format = ECF_ETC2_RGB;
break;
case 23: // ETC2 RGBA
format = ECF_ETC2_ARGB;
break;
default:
format = ECF_UNKNOWN;
break;
}
}
if (format != ECF_UNKNOWN)
{
imageArray.set_used(1);
E_TEXTURE_TYPE tmpType = ETT_2D;
// check for texture type
if (header.NumFaces == 6) // cube map
{
imageArray.set_used(6);
tmpType = ETT_CUBEMAP;
}
else if (header.Depth > 1) // 3d texture
{
// TO-DO
}
else if (header.NumSurfaces > 1) // texture array
{
// To-DO
}
if (type)
*type = tmpType;
// prepare mipmaps data
dataSize = 0;
for (u32 i = 1; i < header.MipMapCount; ++i)
{
u32 tmpWidth = header.Width >> i;
u32 tmpHeight = header.Height >> i;
dataSize += IImage::getDataSizeFromFormat(format, tmpWidth, tmpHeight);
}
if (header.MipMapCount > 1)
{
mipMapsDataArray.set_used(imageArray.size());
for (u32 j = 0; j < mipMapsDataArray.size(); ++j)
mipMapsDataArray[j] = new u8[dataSize];
}
// read texture
dataSize = 0;
long offset = 0;
for (u32 i = 0; i < header.MipMapCount; ++i)
{
if (i == 0)
{
for (u32 j = 0; j < imageArray.size(); ++j)
{
dataSize = IImage::getDataSizeFromFormat(format, header.Width, header.Height);
u8* data = new u8[dataSize];
file->read(data, dataSize);
imageArray[j] = new CImage(format, core::dimension2d<u32>(header.Width, header.Height), data, true, true);
}
}
else
{
u32 tmpWidth = header.Width >> i;
u32 tmpHeight = header.Height >> i;
dataSize = IImage::getDataSizeFromFormat(format, tmpWidth, tmpHeight);
for (u32 j = 0; j < imageArray.size(); ++j)
file->read(mipMapsDataArray[j] + offset, dataSize);
offset += dataSize;
}
}
// assign mipmaps data
for (u32 i = 0; i < mipMapsDataArray.size(); ++i)
imageArray[i]->setMipMapsData(mipMapsDataArray[i], true, true);
}
return imageArray;
}
IImageLoader* createImageLoaderPVR()
{
return new CImageLoaderPVR();
}
}
}
#endif

View File

@ -1,55 +0,0 @@
// Copyright (C) 2013-2016 Patryk Nadrowski
// This file is part of the "Irrlicht Engine".
// For conditions of distribution and use, see copyright notice in irrlicht.h
#ifndef __C_IMAGE_LOADER_PVR_H_INCLUDED__
#define __C_IMAGE_LOADER_PVR_H_INCLUDED__
#include "IrrCompileConfig.h"
#ifdef _IRR_COMPILE_WITH_PVR_LOADER_
#include "IImageLoader.h"
namespace irr
{
namespace video
{
#include "irrpack.h"
struct SPVRHeader
{
u32 Version;
u32 Flags;
u64 PixelFormat;
u32 ColourSpace;
u32 ChannelType;
u32 Height;
u32 Width;
u32 Depth;
u32 NumSurfaces;
u32 NumFaces;
u32 MipMapCount;
u32 MetDataSize;
} PACK_STRUCT;
#include "irrunpack.h"
class CImageLoaderPVR : public IImageLoader
{
public:
virtual bool isALoadableFileExtension(const io::path& filename) const _IRR_OVERRIDE_;
virtual bool isALoadableFileFormat(io::IReadFile* file) const _IRR_OVERRIDE_;
virtual IImage* loadImage(io::IReadFile* file) const _IRR_OVERRIDE_;
virtual core::array<IImage*> loadImages(io::IReadFile* file, E_TEXTURE_TYPE* type) const _IRR_OVERRIDE_;
};
}
}
#endif
#endif

View File

@ -1,651 +0,0 @@
//! Copyright (C) 2009-2012 Gary Conway
//! This file is part of the "Irrlicht Engine".
//! For conditions of distribution and use, see copyright notice in irrlicht.h
/*
Author: Gary Conway (Viper) - co-author of the ZIP file format, Feb 1989,
see the story at http://www.idcnet.us/ziphistory.html
Website: http://idcnet.us
Email: codeslinger@vipergc.com
Created: March 1, 2009
Version: 1.0
Updated:
This module will load SGI .rgb files (along with the other extensions). The module complies
with version 1.0 of the SGI Image File Format by Paul Haeberli of Silicon Graphics Computer Systems
The module handles BW, RGB and RGBA images.
RGB images are stored with either 8 bits per COLOR VALUE, one each for red,green,blue (24bpp)
or 16 bits per COLOR VALUE, again one each for red,green,blue (48 bpp), not including the alpha channel
OPTIONS NOT SUPPORTED
1. 16 bit COLOR VALUES (48bpp modes)
2. COLORMAP = DITHERED mode
For non- run length encoded files, this is the structure
The Header
The Image Data
If the image is run length encoded, this is the structure:
The Header
The Offset Tables
The Image Data
The Header consists of the following:
Size | Type | Name | Description
2 bytes | short | MAGIC | IRIS image file magic number
1 byte | char | STORAGE | Storage format
1 byte | char | BPC | Number of bytes per pixel channel
2 bytes | ushort | DIMENSION | Number of dimensions
2 bytes | ushort | XSIZE | X size in pixels
2 bytes | ushort | YSIZE | Y size in pixels
2 bytes | ushort | ZSIZE | Number of channels
4 bytes | long | PIXMIN | Minimum pixel value
4 bytes | long | PIXMAX | Maximum pixel value
4 bytes | char | DUMMY | Ignored
80 bytes | char | IMAGENAME | Image name
4 bytes | long | COLORMAP | Colormap ID
404 bytes | char | DUMMY | Ignored
Here is a description of each field in the image file Header:
MAGIC - This is the decimal value 474 saved as a short. This identifies the file as an SGI image file.
STORAGE - specifies whether the image is stored using run length encoding (RLE) or not (VERBATIM).
If RLE is used, the value of this byte will be 1. Otherwise the value of this byte will
be 0. The only allowed values for this field are 0 or 1.
BPC - describes the precision that is used to store each channel of an image. This is the number of
bytes per pixel component. The majority of SGI image files use 1 byte per pixel component,
giving 256 levels. Some SGI image files use 2 bytes per component. The only allowed values
for this field are 1 or 2.
DIMENSION - described the number of dimensions in the data stored in the image file.
The only allowed values are 1, 2, or 3. If this value is 1, the image file
consists of only 1 channel and only 1 scanline (row). The length of this
scanline is given by the value of XSIZE below. If this value is 2, the file
consists of a single channel with a number of scanlines. The width and height
of the image are given by the values of XSIZE and YSIZE below.
If this value is 3, the file consists of a number of channels.
The width and height of the image are given by the values of XSIZE and YSIZE below.
The number of channels is given by the value of ZSIZE below.
XSIZE - The width of the image in pixels
YSIZE - The height of the image in pixels
ZSIZE - The number of channels in the image. B/W (greyscale) images are stored as 2 dimensional
images with a ZSIZE of 1. RGB color images are stored as 3 dimensional images with a
ZSIZE of 3. An RGB image with an ALPHA channel is stored as a 3 dimensional image with
a ZSIZE of 4. There are no inherent limitations in the SGI image file format that would
preclude the creation of image files with more than 4 channels.
PINMIN - The minimum pixel value in the image. The value of 0 may be used if no pixel has a value
that is smaller than 0.
PINMAX - The maximum pixel value in the image. The value of 255 may be used if no pixel has a
value that is greater than 255. This is the value that is considered to be full
brightness in the image.
DUMMY - This 4 bytes of data should be set to 0.
IMAGENAME - An null terminated ascii string of up to 79 characters terminated by a null may be
included here. This is not commonly used.
COLORMAP - This controls how the pixel values in the file should be interpreted. It can have one
of these four values:
0: NORMAL - The data in the channels represent B/W values for images with 1 channel, RGB values
for images with 3 channels, and RGBA values for images with 4 channels. Almost all
the SGI image files are of this type.
1: DITHERED - The image will have only 1 channel of data. For each pixel, RGB data is packed
into one 8 bit value. 3 bits are used for red and green, while blue uses 2 bits.
Red data is found in bits[2..0], green data in bits[5..3], and blue data in
bits[7..6]. This format is obsolete.
2: SCREEN - The image will have only 1 channel of data. This format was used to store
color-indexed pixels. To convert the pixel values into RGB values a colormap
must be used. The appropriate color map varies from image to image. This format is obsolete.
3: COLORMAP - The image is used to store a color map from an SGI machine. In this case the
image is not displayable in the conventional sense.
DUMMY - This 404 bytes of data should be set to 0. This makes the Header exactly 512 bytes.
*/
#include "CImageLoaderRGB.h"
#ifdef _IRR_COMPILE_WITH_RGB_LOADER_
#include "IReadFile.h"
#include "SColor.h"
#include "CColorConverter.h"
#include "CImage.h"
#include "os.h"
#include "irrString.h"
namespace irr
{
namespace video
{
//! constructor
CImageLoaderRGB::CImageLoaderRGB()
{
#ifdef _DEBUG
setDebugName("CImageLoaderRGB");
#endif
}
//! returns true if the file maybe is able to be loaded by this class
//! based on the file extensions listed here
bool CImageLoaderRGB::isALoadableFileExtension(const io::path& filename) const
{
return core::hasFileExtension( filename, "rgb", "rgba", "sgi" ) ||
core::hasFileExtension( filename, "int", "inta", "bw" );
}
//! returns true if the file maybe is able to be loaded by this class
bool CImageLoaderRGB::isALoadableFileFormat(io::IReadFile* file) const
{
rgbStruct rgb;
return checkFormat(file, rgb);
}
/** The main entry point, read and format the image file.
\return Pointer to the image data on success
null pointer on fail */
IImage* CImageLoaderRGB::loadImage(io::IReadFile* file) const
{
IImage* image = 0;
s32* paletteData = 0;
rgbStruct rgb; // construct our structure for holding data
// read Header information
if (checkFormat(file, rgb))
{
// 16 bits per COLOR VALUE, not supported, this is 48bpp mode
if (rgb.Header.BPC != 1)
{
os::Printer::log("Only one byte per pixel RGB files are supported", file->getFileName(), ELL_ERROR);
}
else if (rgb.Header.Colormap != 0)
{
os::Printer::log("Dithered, Screen and Colormap RGB files are not supported", file->getFileName(), ELL_ERROR);
}
else if (rgb.Header.Storage == 1 && !readOffsetTables(file, rgb))
{
os::Printer::log("Failed to read RLE table in RGB file", file->getFileName(), ELL_ERROR);
}
else if (!rgb.allocateTemps())
{
os::Printer::log("Out of memory in RGB file loader", file->getFileName(), ELL_ERROR);
}
else
{
// read and process the file to rgbData
processFile(file, rgb);
/*
ZSIZE Description
1 BW (grayscale) image
3 RGB image
4 RGBa image with one alpha channel
When the Alpha channel is present, I am not sure with RGB files if
it's a precomputed RGB color or it needs to be completely calculated. My guess
would be that it's not precomputed for two reasons.
1. the loss of precision when calculating the fraction, then storing the result as an int
2. the loss of the original color data when the image might be composited with another. Yes
the original color data could be computed, however, not without another loss in precision
Also, I don't know where to find the background color
Pixmin and Pixmax are apparently the min and max alpha blend values (0-100%)
Complete Alpha blending computation
The actual resulting merged color is computed this way:
(image color ◊ alpha) + (background color ◊ (100% - alpha)).
Using precomputed blending
(image color) + (background color ◊ (100% - alpha)).
Alternatively, the RGB files could use another blending technique entirely
*/
switch (rgb.Header.Zsize)
{
case 1:
// BW (grayscale) image
paletteData = new s32[256];
for (int n=0; n<256; n++)
paletteData[n] = n;
image = new CImage(ECF_A1R5G5B5, core::dimension2d<u32>(rgb.Header.Xsize, rgb.Header.Ysize));
if (image)
CColorConverter::convert8BitTo16Bit(rgb.rgbData, (s16*)image->getData(), rgb.Header.Xsize, rgb.Header.Ysize, paletteData, 0, true);
break;
case 3:
// RGB image
// one byte per COLOR VALUE, eg, 24bpp
image = new CImage(ECF_R8G8B8, core::dimension2d<u32>(rgb.Header.Xsize, rgb.Header.Ysize));
if (image)
CColorConverter::convert24BitTo24Bit(rgb.rgbData, (u8*)image->getData(), rgb.Header.Xsize, rgb.Header.Ysize, 0, true, false);
break;
case 4:
// RGBa image with one alpha channel (32bpp)
// image is stored in rgbData as RGBA
converttoARGB(reinterpret_cast<u32*>(rgb.rgbData), rgb.Header.Ysize * rgb.Header.Xsize);
image = new CImage(ECF_A8R8G8B8, core::dimension2d<u32>(rgb.Header.Xsize, rgb.Header.Ysize));
if (image)
CColorConverter::convert32BitTo32Bit((s32*)rgb.rgbData, (s32*)image->getData(), rgb.Header.Xsize, rgb.Header.Ysize, 0, true);
break;
default:
// Format unknown
os::Printer::log("Unsupported pixel format in RGB file", file->getFileName(), ELL_ERROR);
}
}
}
// and tidy up allocated memory
delete [] paletteData;
return image;
}
// returns true on success
bool CImageLoaderRGB::readHeader(io::IReadFile* file, rgbStruct& rgb) const
{
if ( file->read(&rgb.Header, sizeof(rgb.Header)) < s32(sizeof(rgb.Header)) )
return false;
// test for INTEL or BIG ENDIAN processor
// if INTEL, then swap the byte order on 16 bit INT's to make them BIG ENDIAN
// because that is the native format for the .rgb file
#ifndef __BIG_ENDIAN__
rgb.Header.Magic = os::Byteswap::byteswap(rgb.Header.Magic);
rgb.Header.Storage = os::Byteswap::byteswap(rgb.Header.Storage);
rgb.Header.Dimension = os::Byteswap::byteswap(rgb.Header.Dimension);
rgb.Header.Xsize = os::Byteswap::byteswap(rgb.Header.Xsize);
rgb.Header.Ysize = os::Byteswap::byteswap(rgb.Header.Ysize);
rgb.Header.Zsize = os::Byteswap::byteswap(rgb.Header.Zsize);
rgb.Header.Pixmin = os::Byteswap::byteswap(rgb.Header.Pixmin);
rgb.Header.Pixmax = os::Byteswap::byteswap(rgb.Header.Pixmax);
rgb.Header.Colormap = os::Byteswap::byteswap(rgb.Header.Colormap);
#endif
// calculate the size of the buffer needed: XSIZE * YSIZE * ZSIZE * BPC
rgb.ImageSize = (rgb.Header.Xsize)*(rgb.Header.Ysize)*(rgb.Header.Zsize)*(rgb.Header.BPC);
return true;
}
bool CImageLoaderRGB::checkFormat(io::IReadFile* file, rgbStruct& rgb) const
{
if (!readHeader(file, rgb))
return false;
return (rgb.Header.Magic == 0x1DA);
}
/*
If the image is stored using run length encoding, offset tables follow the Header that
describe what the file offsets are to the RLE for each scanline. This information only
applies if the value for STORAGE above is 1.
Size | Type | Name | Description
tablen longs | long | STARTTAB | Start table
tablen longs | long | LENGTHTAB | Length table
One entry in each table is needed for each scanline of RLE data. The total number of scanlines in the image (tablen) is determined by the product of the YSIZE and ZSIZE. There are two tables of longs that are written. Each consists of tablen longs of data. The first table has the file offsets to the RLE data for each scanline in the image. In a file with more than 1 channel (ZSIZE > 1) this table first has all the offsets for the scanlines in the first channel, followed be offsets for the scanlines in the second channel, etc. The second table has the RLE data length for each scanline in the image. In a file with more than 1 channel (ZSIZE > 1) this table first has all the RLE data lengths for the scanlines in the first channel, followed be RLE data lengths for the scanlines in the second channel, etc.
To find the the file offset, and the number of bytes in the RLE data for a particular scanline, these
two arrays may be read in and indexed as follows:
To read in the tables:
unsigned long *starttab, *lengthtab;
tablen = YSIZE*ZSIZE*sizeof(long);
starttab = (unsigned long *)mymalloc(tablen);
lengthtab = (unsigned long *)mymalloc(tablen);
fseek(rgb->inf,512,SEEK_SET);
readlongtab(rgb->inf,starttab);
readlongtab(rgb->inf,lengthtab);
To find the file offset and RLE data length for a scanline:
rowno is an integer in the range 0 to YSIZE-1 channo is an integer in the range 0 to ZSIZE-1
rleoffset = starttab[rowno+channo*YSIZE]
rlelength = lengthtab[rowno+channo*YSIZE]
It is possible for two identical rows (scanlines) to share compressed data. A completely
white image could be written as a single compressed row and having all table entries point
to that row. Another little hack that should work is if you are writing out a RGB RLE file,
and a particular scanline is achromatic (greyscale), you could just make the r, g and b rows
point to the same data!!
RETURNS: on success true, else returns false
*/
bool CImageLoaderRGB::readOffsetTables(io::IReadFile* file, rgbStruct& rgb) const
{
rgb.TableLen = rgb.Header.Ysize * rgb.Header.Zsize ; // calc size of tables
// return error if unable to allocate tables
rgb.StartTable = new u32[rgb.TableLen];
if (!rgb.StartTable)
return false;
rgb.LengthTable = new u32[rgb.TableLen];
if (!rgb.LengthTable)
return false;
file->seek(512);
file->read(rgb.StartTable, rgb.TableLen* sizeof(u32));
file->read(rgb.LengthTable, rgb.TableLen* sizeof(u32));
// if we are on an INTEL platform, swap the bytes
#ifndef __BIG_ENDIAN__
const u32 length = rgb.TableLen;
for (u32 i=0; i<length; ++i)
{
rgb.StartTable[i] = os::Byteswap::byteswap(rgb.StartTable[i]);
rgb.LengthTable[i] = os::Byteswap::byteswap(rgb.LengthTable[i]);
}
#endif
return true;
}
/*
The Header has already been read into rgb structure
The Tables have been read if necessary
Now process the actual data
*/
void CImageLoaderRGB::processFile(io::IReadFile* file, rgbStruct& rgb) const
{
u16 *tempShort;
// calculate the size of the buffer needed: XSIZE * YSIZE * ZSIZE * BPC
rgb.rgbData = new u8 [(rgb.Header.Xsize)*(rgb.Header.Ysize)*(rgb.Header.Zsize)*(rgb.Header.BPC)];
u8 *ptr = rgb.rgbData;
// cycle through all scanlines
#ifdef _IRR_RGB_FILE_INVERTED_IMAGE_
// preserve the image as stored, eg, inverted
for (u16 i = 0; i < rgb.Header.Ysize; ++i)
#else
// invert the image to make it upright
for (s32 i = (s32)(rgb.Header.Ysize)-1; i>=0; --i)
#endif
{
// check the number of channels and read a row of data
if (rgb.Header.Zsize >= 1)
readRGBrow( rgb.tmpR, i, 0, file, rgb);
if (rgb.Header.Zsize >= 2)
readRGBrow( rgb.tmpG, i, 1, file, rgb);
if (rgb.Header.Zsize >= 3)
readRGBrow( rgb.tmpB, i, 2, file, rgb);
if (rgb.Header.Zsize >= 4)
readRGBrow( rgb.tmpA, i, 3, file, rgb);
// cycle thru all values for this row
for (u16 j = 0; j < rgb.Header.Xsize; ++j)
{
if(rgb.Header.BPC == 1)
{
// ONE byte per color
if (rgb.Header.Zsize >= 1)
*ptr++ = rgb.tmpR[j];
if (rgb.Header.Zsize >= 2)
*ptr++ = rgb.tmpG[j];
if (rgb.Header.Zsize >= 3)
*ptr++ = rgb.tmpB[j];
if (rgb.Header.Zsize >= 4)
*ptr++ = rgb.tmpA[j];
}
else
{
// TWO bytes per color
if( rgb.Header.Zsize >= 1 )
{
// two bytes of color data
tempShort = (u16 *) (ptr);
*tempShort = *( (u16 *) (rgb.tmpR) + j);
tempShort++;
ptr = ( u8 *)(tempShort);
}
if( rgb.Header.Zsize >= 2 )
{
tempShort = ( u16 *) (ptr);
*tempShort = *( ( u16 *) (rgb.tmpG) + j);
tempShort++;
ptr = ( u8 *) (tempShort);
}
if( rgb.Header.Zsize >= 3 )
{
tempShort = ( u16 *) (ptr);
*tempShort = *( ( u16 *) (rgb.tmpB) + j);
tempShort++;
ptr = ( u8 *)(tempShort);
}
if( rgb.Header.Zsize >= 4 )
{
tempShort = ( u16 *) (ptr);
*tempShort = *( ( u16 *) (rgb.tmpA) + j);
tempShort++;
ptr = ( u8 *)(tempShort);
}
} // end if(rgb.Header.BPC == 1)
} // end for
} // end for
}
/*
This information only applies if the value for STORAGE is 1. If the image is
stored using run length encoding, the image data follows the offset/length tables.
The RLE data is not in any particular order. The offset tables are used to
locate the rle data for any scanline.
The RLE data must be read in from the file and expanded into pixel data in the following manner:
If BPC is 1, then there is one byte per pixel. In this case the RLE data should be
read into an array of chars. To expand data, the low order seven bits of the first
byte: bits[6..0] are used to form a count. If the high order bit of the first byte
is 1: bit[7], then the count is used to specify how many bytes to copy from the RLE
data buffer to the destination. Otherwise, if the high order bit of the first byte
is 0: bit[7], then the count is used to specify how many times to repeat the value
of the following byte, in the destination. This process continues until a count
of 0 is found. This should decompress exactly XSIZE pixels.
One entry in each table is needed for each scanline of RLE data. The total number of
scanlines in the image (tablen) is determined by the product of the YSIZE and ZSIZE.
There are two tables of longs that are written. Each consists of tablen longs of data.
The first table has the file offsets to the RLE data for each scanline in the image. In
a file with more than 1 channel (ZSIZE > 1) this table first has all the offsets for the
scanlines in the first channel, followed be offsets for the scanlines in the second
channel, etc. The second table has the RLE data length for each scanline in the image.
In a file with more than 1 channel (ZSIZE > 1) this table first has all the RLE data
lengths for the scanlines in the first channel, followed be RLE data lengths for the
scanlines in the second channel, etc.
Return a row of data, expanding RLE compression if necessary
*/
void CImageLoaderRGB::readRGBrow(u8 *buf, int y, int z, io::IReadFile* file, rgbStruct& rgb) const
{
if (rgb.Header.Storage != 1)
{
// stored VERBATIM
file->seek(512+(y*rgb.Header.Xsize * rgb.Header.BPC)+(z* rgb.Header.Xsize * rgb.Header.Ysize * rgb.Header.BPC));
file->read(buf, rgb.Header.Xsize * rgb.Header.BPC);
#ifndef __BIG_ENDIAN__
if (rgb.Header.BPC != 1)
{
u16* tmpbuf = reinterpret_cast<u16*>(buf);
for (u16 i=0; i<rgb.Header.Xsize; ++i)
tmpbuf[i] = os::Byteswap::byteswap(tmpbuf[i]);
}
#endif
return;
}
// the file is stored as Run Length Encoding (RLE)
// each sequence is stored as 0x80 NumRepeats ByteToRepeat
// get the file offset from StartTable and SEEK
// then read the data
file->seek((long) rgb.StartTable[y+z * rgb.Header.Ysize]);
file->read(rgb.tmp, rgb.LengthTable[y+z * rgb.Header.Ysize]);
// rgb.tmp has the data
u16 pixel;
u16 *tempShort;
u8* iPtr = rgb.tmp;
u8* oPtr = buf;
while (true)
{
// if BPC = 1, then one byte per pixel
if (rgb.Header.BPC == 1)
{
pixel = *iPtr++;
}
else
{
// BPC = 2, so two bytes per pixel
tempShort = (u16 *) iPtr;
pixel = *tempShort;
tempShort++;
iPtr = (u8 *) tempShort;
}
#ifndef __BIG_ENDIAN__
if (rgb.Header.BPC != 1)
pixel = os::Byteswap::byteswap(pixel);
#endif
s32 count = (s32)(pixel & 0x7F);
// limit the count value to the remaining row size
if (oPtr + count*rgb.Header.BPC > buf + rgb.Header.Xsize * rgb.Header.BPC)
{
count = (s32)( (buf + rgb.Header.Xsize * rgb.Header.BPC) - oPtr ) / rgb.Header.BPC;
}
if (count<=0)
break;
else if (pixel & 0x80)
{
// repeat the byte pointed to by iPtr, count times
while (count--)
{
if(rgb.Header.BPC == 1)
{
*oPtr++ = *iPtr++;
}
else
{
// write pixel from iPtr to oPtr, move both two bytes ahead
tempShort = (u16 *) (iPtr);
pixel = *tempShort;
tempShort++;
iPtr = (u8 *) (tempShort);
#ifndef __BIG_ENDIAN__
pixel = os::Byteswap::byteswap(pixel);
#endif
tempShort = (u16 *) (oPtr);
*tempShort = pixel;
tempShort++;
oPtr = (u8 *) (tempShort);
}
}
}
else
{
if (rgb.Header.BPC == 1)
{
pixel = *iPtr++;
}
else
{
tempShort = (u16 *) (iPtr);
pixel = *tempShort;
tempShort++;
iPtr = (u8 *) (tempShort);
}
#ifndef __BIG_ENDIAN__
if (rgb.Header.BPC != 1)
pixel = os::Byteswap::byteswap(pixel);
#endif
while (count--)
{
if(rgb.Header.BPC == 1)
{
*oPtr++ = (u8) pixel;
}
else
{
tempShort = (u16 *) (oPtr);
*tempShort = pixel;
tempShort++;
oPtr = (u8 *) (tempShort);
}
}
} // else if (pixel & 0x80)
} // while (true)
}
// we have 1 byte per COLOR VALUE, eg 24bpp and 1 alpha channel
// color values are stored as RGBA, convert to ARGB
// todo: replace with CColorConverter method
void CImageLoaderRGB::converttoARGB(u32* in, const u32 size) const
{
for (u32 x=0; x < size; ++x)
{
*in=(*in>>8)|(*in<<24);
++in;
}
}
//! creates a loader which is able to load SGI RGB images
IImageLoader* createImageLoaderRGB()
{
return new CImageLoaderRGB;
}
} // end namespace video
} // end namespace irr
#endif

View File

@ -1,164 +0,0 @@
// Copyright (C) 2009-2012 Gary Conway
// This file is part of the "Irrlicht Engine".
// For conditions of distribution and use, see copyright notice in irrlicht.h
/*
Author: Gary Conway (Viper) - co-author of the ZIP file format, Feb 1989,
see the story at http://www.idcnet.us/ziphistory.html
Website: http://idcnet.us
Email: codeslinger@vipergc.com
Created: March 1, 2009
Version: 1.0
Updated:
*/
#ifndef __C_IMAGE_LOADER_RGB_H_INCLUDED__
#define __C_IMAGE_LOADER_RGB_H_INCLUDED__
// define _IRR_RGB_FILE_INVERTED_IMAGE_ to preserve the inverted format of the RGB file
// commenting this out will invert the inverted image,resulting in the image being upright
#define _IRR_RGB_FILE_INVERTED_IMAGE_
#include "IrrCompileConfig.h"
#ifdef _IRR_COMPILE_WITH_RGB_LOADER_
#include "IImageLoader.h"
namespace irr
{
namespace video
{
// byte-align structures
#include "irrpack.h"
// the RGB image file header structure
struct SRGBHeader
{
u16 Magic; // IRIS image file magic number
u8 Storage; // Storage format
u8 BPC; // Number of bytes per pixel channel
u16 Dimension; // Number of dimensions
u16 Xsize; // X size in pixels
u16 Ysize; // Y size in pixels
u16 Zsize; // Z size in pixels
u32 Pixmin; // Minimum pixel value
u32 Pixmax; // Maximum pixel value
u32 Dummy1; // ignored
char Imagename[80];// Image name
u32 Colormap; // Colormap ID
// char Dummy2[404];// Ignored
} PACK_STRUCT;
// Default alignment
#include "irrunpack.h"
// this structure holds context specific data about the file being loaded.
typedef struct _RGBdata
{
u8 *tmp;
u8 *tmpR;
u8 *tmpG;
u8 *tmpB;
u8 *tmpA;
u32 *StartTable; // compressed data table, holds file offsets
u32 *LengthTable; // length for the above data, hold lengths for above
u32 TableLen; // len of above tables
SRGBHeader Header; // define the .rgb file header
u32 ImageSize;
u8 *rgbData;
public:
_RGBdata() : tmp(0), tmpR(0), tmpG(0), tmpB(0), tmpA(0),
StartTable(0), LengthTable(0), TableLen(0), ImageSize(0), rgbData(0)
{
}
~_RGBdata()
{
delete [] tmp;
delete [] tmpR;
delete [] tmpG;
delete [] tmpB;
delete [] tmpA;
delete [] StartTable;
delete [] LengthTable;
delete [] rgbData;
}
bool allocateTemps()
{
tmp = tmpR = tmpG = tmpB = tmpA = 0;
tmp = new u8 [Header.Xsize * 256 * Header.BPC];
if (!tmp)
return false;
if (Header.Zsize >= 1)
{
tmpR = new u8[Header.Xsize * Header.BPC];
if (!tmpR)
return false;
}
if (Header.Zsize >= 2)
{
tmpG = new u8[Header.Xsize * Header.BPC];
if (!tmpG)
return false;
}
if (Header.Zsize >= 3)
{
tmpB = new u8[Header.Xsize * Header.BPC];
if (!tmpB)
return false;
}
if (Header.Zsize >= 4)
{
tmpA = new u8[Header.Xsize * Header.BPC];
if (!tmpA)
return false;
}
return true;
}
} rgbStruct;
//! Surface Loader for Silicon Graphics RGB files
class CImageLoaderRGB : public IImageLoader
{
public:
//! constructor
CImageLoaderRGB();
//! returns true if the file maybe is able to be loaded by this class
//! based on the file extension (e.g. ".tga")
virtual bool isALoadableFileExtension(const io::path& filename) const _IRR_OVERRIDE_;
//! returns true if the file maybe is able to be loaded by this class
virtual bool isALoadableFileFormat(io::IReadFile* file) const _IRR_OVERRIDE_;
//! creates a surface from the file
virtual IImage* loadImage(io::IReadFile* file) const _IRR_OVERRIDE_;
private:
bool readHeader(io::IReadFile* file, rgbStruct& rgb) const;
void readRGBrow(u8 *buf, int y, int z, io::IReadFile* file, rgbStruct& rgb) const;
void processFile(io::IReadFile *file, rgbStruct& rgb) const;
bool checkFormat(io::IReadFile *file, rgbStruct& rgb) const;
bool readOffsetTables(io::IReadFile* file, rgbStruct& rgb) const;
void converttoARGB(u32* in, const u32 size) const;
};
} // end namespace video
} // end namespace irr
#endif // _IRR_COMPILE_WITH_RGB_LOADER_
#endif // __C_IMAGE_LOADER_RGB_H_INCLUDED__

View File

@ -1,237 +0,0 @@
// Copyright (C) 2002-2012 Nikolaus Gebhardt
// This file is part of the "Irrlicht Engine".
// For conditions of distribution and use, see copyright notice in irrlicht.h
#include "CImageLoaderTGA.h"
#ifdef _IRR_COMPILE_WITH_TGA_LOADER_
#include "IReadFile.h"
#include "os.h"
#include "CColorConverter.h"
#include "CImage.h"
#include "irrString.h"
namespace irr
{
namespace video
{
//! returns true if the file maybe is able to be loaded by this class
//! based on the file extension (e.g. ".tga")
bool CImageLoaderTGA::isALoadableFileExtension(const io::path& filename) const
{
return core::hasFileExtension ( filename, "tga" );
}
//! loads a compressed tga.
u8 *CImageLoaderTGA::loadCompressedImage(io::IReadFile *file, const STGAHeader& header) const
{
// This was written and sent in by Jon Pry, thank you very much!
// I only changed the formatting a little bit.
s32 bytesPerPixel = header.PixelDepth/8;
s32 imageSize = header.ImageHeight * header.ImageWidth * bytesPerPixel;
u8* data = new u8[imageSize];
s32 currentByte = 0;
while(currentByte < imageSize)
{
u8 chunkheader = 0;
file->read(&chunkheader, sizeof(u8)); // Read The Chunk's Header
if(chunkheader < 128) // If The Chunk Is A 'RAW' Chunk
{
chunkheader++; // Add 1 To The Value To Get Total Number Of Raw Pixels
file->read(&data[currentByte], bytesPerPixel * chunkheader);
currentByte += bytesPerPixel * chunkheader;
}
else
{
// thnx to neojzs for some fixes with this code
// If It's An RLE Header
chunkheader -= 127; // Subtract 127 To Get Rid Of The ID Bit
s32 dataOffset = currentByte;
file->read(&data[dataOffset], bytesPerPixel);
currentByte += bytesPerPixel;
for(s32 counter = 1; counter < chunkheader; counter++)
{
for(s32 elementCounter=0; elementCounter < bytesPerPixel; elementCounter++)
data[currentByte + elementCounter] = data[dataOffset + elementCounter];
currentByte += bytesPerPixel;
}
}
}
return data;
}
//! returns true if the file maybe is able to be loaded by this class
bool CImageLoaderTGA::isALoadableFileFormat(io::IReadFile* file) const
{
if (!file)
return false;
STGAFooter footer;
memset(&footer, 0, sizeof(STGAFooter));
file->seek(file->getSize()-sizeof(STGAFooter));
file->read(&footer, sizeof(STGAFooter));
return (!strcmp(footer.Signature,"TRUEVISION-XFILE.")); // very old tgas are refused.
}
//! creates a surface from the file
IImage* CImageLoaderTGA::loadImage(io::IReadFile* file) const
{
STGAHeader header;
u32 *palette = 0;
file->read(&header, sizeof(STGAHeader));
#ifdef __BIG_ENDIAN__
header.ColorMapLength = os::Byteswap::byteswap(header.ColorMapLength);
header.ImageWidth = os::Byteswap::byteswap(header.ImageWidth);
header.ImageHeight = os::Byteswap::byteswap(header.ImageHeight);
#endif
// skip image identification field
if (header.IdLength)
file->seek(header.IdLength, true);
if (header.ColorMapType)
{
// create 32 bit palette
palette = new u32[ header.ColorMapLength];
// read color map
u8 * colorMap = new u8[header.ColorMapEntrySize/8 * header.ColorMapLength];
file->read(colorMap,header.ColorMapEntrySize/8 * header.ColorMapLength);
// convert to 32-bit palette
switch ( header.ColorMapEntrySize )
{
case 16:
CColorConverter::convert_A1R5G5B5toA8R8G8B8(colorMap, header.ColorMapLength, palette);
break;
case 24:
CColorConverter::convert_B8G8R8toA8R8G8B8(colorMap, header.ColorMapLength, palette);
break;
case 32:
CColorConverter::convert_B8G8R8A8toA8R8G8B8(colorMap, header.ColorMapLength, palette);
break;
}
delete [] colorMap;
}
// read image
u8* data = 0;
if ( header.ImageType == 1 || // Uncompressed, color-mapped images.
header.ImageType == 2 || // Uncompressed, RGB images
header.ImageType == 3 // Uncompressed, black and white images
)
{
const s32 imageSize = header.ImageHeight * header.ImageWidth * header.PixelDepth/8;
data = new u8[imageSize];
file->read(data, imageSize);
}
else
if(header.ImageType == 10)
{
// Runlength encoded RGB images
data = loadCompressedImage(file, header);
}
else
{
os::Printer::log("Unsupported TGA file type", file->getFileName(), ELL_ERROR);
delete [] palette;
return 0;
}
IImage* image = 0;
switch(header.PixelDepth)
{
case 8:
{
if (header.ImageType==3) // grey image
{
image = new CImage(ECF_R8G8B8,
core::dimension2d<u32>(header.ImageWidth, header.ImageHeight));
if (image)
CColorConverter::convert8BitTo24Bit((u8*)data,
(u8*)image->getData(),
header.ImageWidth,header.ImageHeight,
0, 0, (header.ImageDescriptor&0x20)==0);
}
else
{
image = new CImage(ECF_A1R5G5B5,
core::dimension2d<u32>(header.ImageWidth, header.ImageHeight));
if (image)
CColorConverter::convert8BitTo16Bit((u8*)data,
(s16*)image->getData(),
header.ImageWidth,header.ImageHeight,
(s32*) palette, 0,
(header.ImageDescriptor&0x20)==0);
}
}
break;
case 16:
image = new CImage(ECF_A1R5G5B5,
core::dimension2d<u32>(header.ImageWidth, header.ImageHeight));
if (image)
CColorConverter::convert16BitTo16Bit((s16*)data,
(s16*)image->getData(), header.ImageWidth, header.ImageHeight, 0, (header.ImageDescriptor&0x20)==0);
break;
case 24:
image = new CImage(ECF_R8G8B8,
core::dimension2d<u32>(header.ImageWidth, header.ImageHeight));
if (image)
CColorConverter::convert24BitTo24Bit(
(u8*)data, (u8*)image->getData(), header.ImageWidth, header.ImageHeight, 0, (header.ImageDescriptor&0x20)==0, true);
break;
case 32:
image = new CImage(ECF_A8R8G8B8,
core::dimension2d<u32>(header.ImageWidth, header.ImageHeight));
if (image)
CColorConverter::convert32BitTo32Bit((s32*)data,
(s32*)image->getData(), header.ImageWidth, header.ImageHeight, 0, (header.ImageDescriptor&0x20)==0);
break;
default:
os::Printer::log("Unsupported TGA format", file->getFileName(), ELL_ERROR);
break;
}
delete [] data;
delete [] palette;
return image;
}
//! creates a loader which is able to load tgas
IImageLoader* createImageLoaderTGA()
{
return new CImageLoaderTGA();
}
} // end namespace video
} // end namespace irr
#endif

View File

@ -1,82 +0,0 @@
// Copyright (C) 2002-2012 Nikolaus Gebhardt
// This file is part of the "Irrlicht Engine".
// For conditions of distribution and use, see copyright notice in irrlicht.h
#ifndef __C_IMAGE_LOADER_TGA_H_INCLUDED__
#define __C_IMAGE_LOADER_TGA_H_INCLUDED__
#include "IrrCompileConfig.h"
#include "IImageLoader.h"
namespace irr
{
namespace video
{
#if defined(_IRR_COMPILE_WITH_TGA_LOADER_) || defined(_IRR_COMPILE_WITH_TGA_WRITER_)
// byte-align structures
#include "irrpack.h"
// these structs are also used in the TGA writer
struct STGAHeader{
u8 IdLength;
u8 ColorMapType;
u8 ImageType;
u8 FirstEntryIndex[2];
u16 ColorMapLength;
u8 ColorMapEntrySize;
u8 XOrigin[2];
u8 YOrigin[2];
u16 ImageWidth;
u16 ImageHeight;
u8 PixelDepth;
u8 ImageDescriptor;
} PACK_STRUCT;
struct STGAFooter
{
u32 ExtensionOffset;
u32 DeveloperOffset;
c8 Signature[18];
} PACK_STRUCT;
// Default alignment
#include "irrunpack.h"
#endif // compiled with loader or reader
#ifdef _IRR_COMPILE_WITH_TGA_LOADER_
/*!
Surface Loader for targa images
*/
class CImageLoaderTGA : public IImageLoader
{
public:
//! returns true if the file maybe is able to be loaded by this class
//! based on the file extension (e.g. ".tga")
virtual bool isALoadableFileExtension(const io::path& filename) const _IRR_OVERRIDE_;
//! returns true if the file maybe is able to be loaded by this class
virtual bool isALoadableFileFormat(io::IReadFile* file) const _IRR_OVERRIDE_;
//! creates a surface from the file
virtual IImage* loadImage(io::IReadFile* file) const _IRR_OVERRIDE_;
private:
//! loads a compressed tga. Was written and sent in by Jon Pry, thank you very much!
u8* loadCompressedImage(io::IReadFile *file, const STGAHeader& header) const;
};
#endif // compiled with loader
} // end namespace video
} // end namespace irr
#endif

View File

@ -1,282 +0,0 @@
// Copyright (C) 2004 Murphy McCauley
// Copyright (C) 2007-2012 Christian Stehno
// This file is part of the "Irrlicht Engine".
// For conditions of distribution and use, see copyright notice in irrlicht.h
#include "CImageLoaderWAL.h"
#include "CColorConverter.h"
#include "CImage.h"
#include "os.h"
#include "dimension2d.h"
#include "IVideoDriver.h"
#include "IFileSystem.h"
#include "IReadFile.h"
#include "irrString.h"
namespace irr
{
namespace video
{
#ifdef _IRR_COMPILE_WITH_LMP_LOADER_
// Palette quake2 colormap.h, 768 byte, last is transparent
static const u32 colormap_h[256] = {
0xFF000000,0xFF0F0F0F,0xFF1F1F1F,0xFF2F2F2F,0xFF3F3F3F,0xFF4B4B4B,0xFF5B5B5B,0xFF6B6B6B,
0xFF7B7B7B,0xFF8B8B8B,0xFF9B9B9B,0xFFABABAB,0xFFBBBBBB,0xFFCBCBCB,0xFFDBDBDB,0xFFEBEBEB,
0xFF0F0B07,0xFF170F0B,0xFF1F170B,0xFF271B0F,0xFF2F2313,0xFF372B17,0xFF3F2F17,0xFF4B371B,
0xFF533B1B,0xFF5B431F,0xFF634B1F,0xFF6B531F,0xFF73571F,0xFF7B5F23,0xFF836723,0xFF8F6F23,
0xFF0B0B0F,0xFF13131B,0xFF1B1B27,0xFF272733,0xFF2F2F3F,0xFF37374B,0xFF3F3F57,0xFF474767,
0xFF4F4F73,0xFF5B5B7F,0xFF63638B,0xFF6B6B97,0xFF7373A3,0xFF7B7BAF,0xFF8383BB,0xFF8B8BCB,
0xFF000000,0xFF070700,0xFF0B0B00,0xFF131300,0xFF1B1B00,0xFF232300,0xFF2B2B07,0xFF2F2F07,
0xFF373707,0xFF3F3F07,0xFF474707,0xFF4B4B0B,0xFF53530B,0xFF5B5B0B,0xFF63630B,0xFF6B6B0F,
0xFF070000,0xFF0F0000,0xFF170000,0xFF1F0000,0xFF270000,0xFF2F0000,0xFF370000,0xFF3F0000,
0xFF470000,0xFF4F0000,0xFF570000,0xFF5F0000,0xFF670000,0xFF6F0000,0xFF770000,0xFF7F0000,
0xFF131300,0xFF1B1B00,0xFF232300,0xFF2F2B00,0xFF372F00,0xFF433700,0xFF4B3B07,0xFF574307,
0xFF5F4707,0xFF6B4B0B,0xFF77530F,0xFF835713,0xFF8B5B13,0xFF975F1B,0xFFA3631F,0xFFAF6723,
0xFF231307,0xFF2F170B,0xFF3B1F0F,0xFF4B2313,0xFF572B17,0xFF632F1F,0xFF733723,0xFF7F3B2B,
0xFF8F4333,0xFF9F4F33,0xFFAF632F,0xFFBF772F,0xFFCF8F2B,0xFFDFAB27,0xFFEFCB1F,0xFFFFF31B,
0xFF0B0700,0xFF1B1300,0xFF2B230F,0xFF372B13,0xFF47331B,0xFF533723,0xFF633F2B,0xFF6F4733,
0xFF7F533F,0xFF8B5F47,0xFF9B6B53,0xFFA77B5F,0xFFB7876B,0xFFC3937B,0xFFD3A38B,0xFFE3B397,
0xFFAB8BA3,0xFF9F7F97,0xFF937387,0xFF8B677B,0xFF7F5B6F,0xFF775363,0xFF6B4B57,0xFF5F3F4B,
0xFF573743,0xFF4B2F37,0xFF43272F,0xFF371F23,0xFF2B171B,0xFF231313,0xFF170B0B,0xFF0F0707,
0xFFBB739F,0xFFAF6B8F,0xFFA35F83,0xFF975777,0xFF8B4F6B,0xFF7F4B5F,0xFF734353,0xFF6B3B4B,
0xFF5F333F,0xFF532B37,0xFF47232B,0xFF3B1F23,0xFF2F171B,0xFF231313,0xFF170B0B,0xFF0F0707,
0xFFDBC3BB,0xFFCBB3A7,0xFFBFA39B,0xFFAF978B,0xFFA3877B,0xFF977B6F,0xFF876F5F,0xFF7B6353,
0xFF6B5747,0xFF5F4B3B,0xFF533F33,0xFF433327,0xFF372B1F,0xFF271F17,0xFF1B130F,0xFF0F0B07,
0xFF6F837B,0xFF677B6F,0xFF5F7367,0xFF576B5F,0xFF4F6357,0xFF475B4F,0xFF3F5347,0xFF374B3F,
0xFF2F4337,0xFF2B3B2F,0xFF233327,0xFF1F2B1F,0xFF172317,0xFF0F1B13,0xFF0B130B,0xFF070B07,
0xFFFFF31B,0xFFEFDF17,0xFFDBCB13,0xFFCBB70F,0xFFBBA70F,0xFFAB970B,0xFF9B8307,0xFF8B7307,
0xFF7B6307,0xFF6B5300,0xFF5B4700,0xFF4B3700,0xFF3B2B00,0xFF2B1F00,0xFF1B0F00,0xFF0B0700,
0xFF0000FF,0xFF0B0BEF,0xFF1313DF,0xFF1B1BCF,0xFF2323BF,0xFF2B2BAF,0xFF2F2F9F,0xFF2F2F8F,
0xFF2F2F7F,0xFF2F2F6F,0xFF2F2F5F,0xFF2B2B4F,0xFF23233F,0xFF1B1B2F,0xFF13131F,0xFF0B0B0F,
0xFF2B0000,0xFF3B0000,0xFF4B0700,0xFF5F0700,0xFF6F0F00,0xFF7F1707,0xFF931F07,0xFFA3270B,
0xFFB7330F,0xFFC34B1B,0xFFCF632B,0xFFDB7F3B,0xFFE3974F,0xFFE7AB5F,0xFFEFBF77,0xFFF7D38B,
0xFFA77B3B,0xFFB79B37,0xFFC7C337,0xFFE7E357,0xFF7FBFFF,0xFFABE7FF,0xFFD7FFFF,0xFF670000,
0xFF8B0000,0xFFB30000,0xFFD70000,0xFFFF0000,0xFFFFF393,0xFFFFF7C7,0xFFFFFFFF,0x009F5B53
};
bool CImageLoaderLMP::isALoadableFileExtension(const io::path& filename) const
{
return core::hasFileExtension ( filename, "lmp" );
}
bool CImageLoaderLMP::isALoadableFileFormat(irr::io::IReadFile* file) const
{
return false;
}
/*!
Quake1, Quake2, Hallife lmp texture
*/
IImage* CImageLoaderLMP::loadImage(irr::io::IReadFile* file) const
{
SLMPHeader header;
file->seek(0);
file->read(&header, sizeof(header));
// maybe palette file
u32 rawtexsize = header.width * header.height;
if ( rawtexsize + sizeof ( header ) != (u32)file->getSize() )
return 0;
u8 *rawtex = new u8 [ rawtexsize ];
file->read(rawtex, rawtexsize);
IImage* image = new CImage(ECF_A8R8G8B8, core::dimension2d<u32>(header.width, header.height));
CColorConverter::convert8BitTo32Bit(rawtex, (u8*)image->getData(), header.width, header.height, (u8*) colormap_h, 0, false);
delete [] rawtex;
return image;
}
IImageLoader* createImageLoaderLMP()
{
return new irr::video::CImageLoaderLMP();
}
#endif
#ifdef _IRR_COMPILE_WITH_WAL_LOADER_
// Palette quake2 demo pics/colormap.pcx, last is transparent
static const u32 colormap_pcx[256] = {
0xFF000000,0xFF0F0F0F,0xFF1F1F1F,0xFF2F2F2F,0xFF3F3F3F,0xFF4B4B4B,0xFF5B5B5B,0xFF6B6B6B,
0xFF7B7B7B,0xFF8B8B8B,0xFF9B9B9B,0xFFABABAB,0xFFBBBBBB,0xFFCBCBCB,0xFFDBDBDB,0xFFEBEBEB,
0xFF634B23,0xFF5B431F,0xFF533F1F,0xFF4F3B1B,0xFF47371B,0xFF3F2F17,0xFF3B2B17,0xFF332713,
0xFF2F2313,0xFF2B1F13,0xFF271B0F,0xFF23170F,0xFF1B130B,0xFF170F0B,0xFF130F07,0xFF0F0B07,
0xFF5F5F6F,0xFF5B5B67,0xFF5B535F,0xFF574F5B,0xFF534B53,0xFF4F474B,0xFF473F43,0xFF3F3B3B,
0xFF3B3737,0xFF332F2F,0xFF2F2B2B,0xFF272727,0xFF232323,0xFF1B1B1B,0xFF171717,0xFF131313,
0xFF8F7753,0xFF7B6343,0xFF735B3B,0xFF674F2F,0xFFCF974B,0xFFA77B3B,0xFF8B672F,0xFF6F5327,
0xFFEB9F27,0xFFCB8B23,0xFFAF771F,0xFF93631B,0xFF774F17,0xFF5B3B0F,0xFF3F270B,0xFF231707,
0xFFA73B2B,0xFF9F2F23,0xFF972B1B,0xFF8B2713,0xFF7F1F0F,0xFF73170B,0xFF671707,0xFF571300,
0xFF4B0F00,0xFF430F00,0xFF3B0F00,0xFF330B00,0xFF2B0B00,0xFF230B00,0xFF1B0700,0xFF130700,
0xFF7B5F4B,0xFF735743,0xFF6B533F,0xFF674F3B,0xFF5F4737,0xFF574333,0xFF533F2F,0xFF4B372B,
0xFF433327,0xFF3F2F23,0xFF37271B,0xFF2F2317,0xFF271B13,0xFF1F170F,0xFF170F0B,0xFF0F0B07,
0xFF6F3B17,0xFF5F3717,0xFF532F17,0xFF432B17,0xFF372313,0xFF271B0F,0xFF1B130B,0xFF0F0B07,
0xFFB35B4F,0xFFBF7B6F,0xFFCB9B93,0xFFD7BBB7,0xFFCBD7DF,0xFFB3C7D3,0xFF9FB7C3,0xFF87A7B7,
0xFF7397A7,0xFF5B879B,0xFF47778B,0xFF2F677F,0xFF17536F,0xFF134B67,0xFF0F435B,0xFF0B3F53,
0xFF07374B,0xFF072F3F,0xFF072733,0xFF001F2B,0xFF00171F,0xFF000F13,0xFF00070B,0xFF000000,
0xFF8B5757,0xFF834F4F,0xFF7B4747,0xFF734343,0xFF6B3B3B,0xFF633333,0xFF5B2F2F,0xFF572B2B,
0xFF4B2323,0xFF3F1F1F,0xFF331B1B,0xFF2B1313,0xFF1F0F0F,0xFF130B0B,0xFF0B0707,0xFF000000,
0xFF979F7B,0xFF8F9773,0xFF878B6B,0xFF7F8363,0xFF777B5F,0xFF737357,0xFF6B6B4F,0xFF636347,
0xFF5B5B43,0xFF4F4F3B,0xFF434333,0xFF37372B,0xFF2F2F23,0xFF23231B,0xFF171713,0xFF0F0F0B,
0xFF9F4B3F,0xFF934337,0xFF8B3B2F,0xFF7F3727,0xFF772F23,0xFF6B2B1B,0xFF632317,0xFF571F13,
0xFF4F1B0F,0xFF43170B,0xFF37130B,0xFF2B0F07,0xFF1F0B07,0xFF170700,0xFF0B0000,0xFF000000,
0xFF777BCF,0xFF6F73C3,0xFF676BB7,0xFF6363A7,0xFF5B5B9B,0xFF53578F,0xFF4B4F7F,0xFF474773,
0xFF3F3F67,0xFF373757,0xFF2F2F4B,0xFF27273F,0xFF231F2F,0xFF1B1723,0xFF130F17,0xFF0B0707,
0xFF9BAB7B,0xFF8F9F6F,0xFF879763,0xFF7B8B57,0xFF73834B,0xFF677743,0xFF5F6F3B,0xFF576733,
0xFF4B5B27,0xFF3F4F1B,0xFF374313,0xFF2F3B0B,0xFF232F07,0xFF1B2300,0xFF131700,0xFF0B0F00,
0xFF00FF00,0xFF23E70F,0xFF3FD31B,0xFF53BB27,0xFF5FA72F,0xFF5F8F33,0xFF5F7B33,0xFFFFFFFF,
0xFFFFFFD3,0xFFFFFFA7,0xFFFFFF7F,0xFFFFFF53,0xFFFFFF27,0xFFFFEB1F,0xFFFFD717,0xFFFFBF0F,
0xFFFFAB07,0xFFFF9300,0xFFEF7F00,0xFFE36B00,0xFFD35700,0xFFC74700,0xFFB73B00,0xFFAB2B00,
0xFF9B1F00,0xFF8F1700,0xFF7F0F00,0xFF730700,0xFF5F0000,0xFF470000,0xFF2F0000,0xFF1B0000,
0xFFEF0000,0xFF3737FF,0xFFFF0000,0xFF0000FF,0xFF2B2B23,0xFF1B1B17,0xFF13130F,0xFFEB977F,
0xFFC37353,0xFF9F5733,0xFF7B3F1B,0xFFEBD3C7,0xFFC7AB9B,0xFFA78B77,0xFF876B57,0x009F5B53
};
/*!
Halflife
*/
bool CImageLoaderWAL2::isALoadableFileExtension(const io::path& filename) const
{
// embedded in Wad(WAD3 format). originally it has no extension
return core::hasFileExtension ( filename, "wal2" );
}
bool CImageLoaderWAL2::isALoadableFileFormat(irr::io::IReadFile* file) const
{
return false;
}
/*
Halflite Texture WAD
*/
IImage* CImageLoaderWAL2::loadImage(irr::io::IReadFile* file) const
{
miptex_halflife header;
file->seek(0);
file->read(&header, sizeof(header));
#ifdef __BIG_ENDIAN__
header.width = os::Byteswap::byteswap(header.width);
header.height = os::Byteswap::byteswap(header.height);
#endif
// palette
//u32 paletteofs = header.mipmap[0] + ((rawtexsize * 85) >> 6) + 2;
u32 *pal = new u32 [ 192 + 256 ];
u8 *s = (u8*) pal;
file->seek ( file->getSize() - 768 - 2 );
file->read ( s, 768 );
u32 i;
for ( i = 0; i < 256; ++i, s+= 3 )
{
pal [ 192 + i ] = 0xFF000000 | s[0] << 16 | s[1] << 8 | s[2];
}
ECOLOR_FORMAT format = ECF_R8G8B8;
// transparency in filename;-) funny. rgb:0x0000FF is colorkey
if ( file->getFileName().findFirst ( '{' ) >= 0 )
{
format = ECF_A8R8G8B8;
pal [ 192 + 255 ] &= 0x00FFFFFF;
}
u32 rawtexsize = header.width * header.height;
u8 *rawtex = new u8 [ rawtexsize ];
file->seek ( header.mipmap[0] );
file->read(rawtex, rawtexsize);
IImage* image = new CImage(format, core::dimension2d<u32>(header.width, header.height));
switch ( format )
{
case ECF_R8G8B8:
CColorConverter::convert8BitTo24Bit(rawtex, (u8*)image->getData(), header.width, header.height, (u8*) pal + 768, 0, false);
break;
case ECF_A8R8G8B8:
CColorConverter::convert8BitTo32Bit(rawtex, (u8*)image->getData(), header.width, header.height, (u8*) pal + 768, 0, false);
break;
default:
// Assuming there are no other color formats (I found no information about this format)
break;
}
delete [] rawtex;
delete [] pal;
return image;
}
bool CImageLoaderWAL::isALoadableFileExtension(const io::path& filename) const
{
return core::hasFileExtension ( filename, "wal" );
}
bool CImageLoaderWAL::isALoadableFileFormat(irr::io::IReadFile* file) const
{
return false;
}
/*!
quake2
*/
IImage* CImageLoaderWAL::loadImage(irr::io::IReadFile* file) const
{
miptex_quake2 header;
file->seek(0);
file->read(&header, sizeof(header));
#ifdef __BIG_ENDIAN__
header.width = os::Byteswap::byteswap(header.width);
header.height = os::Byteswap::byteswap(header.height);
#endif
u32 rawtexsize = header.width * header.height;
u8 *rawtex = new u8 [ rawtexsize ];
file->seek ( header.mipmap[0] );
file->read(rawtex, rawtexsize);
IImage* image = new CImage(ECF_A8R8G8B8, core::dimension2d<u32>(header.width, header.height));
CColorConverter::convert8BitTo32Bit(rawtex, (u8*)image->getData(), header.width, header.height, (u8*) colormap_pcx, 0, false);
delete [] rawtex;
return image;
}
IImageLoader* createImageLoaderWAL()
{
return new irr::video::CImageLoaderWAL();
}
IImageLoader* createImageLoaderHalfLife()
{
return new irr::video::CImageLoaderWAL2();
}
#endif
} // end namespace video
} // end namespace irr

View File

@ -1,100 +0,0 @@
// Copyright (C) 2004 Murphy McCauley
// Copyright (C) 2007-2012 Christian Stehno
// This file is part of the "Irrlicht Engine".
// For conditions of distribution and use, see copyright notice in irrlicht.h
/*
Thanks to:
Max McGuire for his Flipcode article about WAL textures
Nikolaus Gebhardt for the Irrlicht 3D engine
*/
#ifndef __C_IMAGE_LOADER_WAL_H_INCLUDED__
#define __C_IMAGE_LOADER_WAL_H_INCLUDED__
#include "IrrCompileConfig.h"
#include "IImageLoader.h"
namespace irr
{
namespace video
{
#ifdef _IRR_COMPILE_WITH_LMP_LOADER_
// byte-align structures
#include "irrpack.h"
struct SLMPHeader {
u32 width; // width
u32 height; // height
// variably sized
} PACK_STRUCT;
// Default alignment
#include "irrunpack.h"
//! An Irrlicht image loader for Quake1,2 engine lmp textures/palette
class CImageLoaderLMP : public irr::video::IImageLoader
{
public:
virtual bool isALoadableFileExtension(const io::path& filename) const _IRR_OVERRIDE_;
virtual bool isALoadableFileFormat(irr::io::IReadFile* file) const _IRR_OVERRIDE_;
virtual irr::video::IImage* loadImage(irr::io::IReadFile* file) const _IRR_OVERRIDE_;
};
#endif
#ifdef _IRR_COMPILE_WITH_WAL_LOADER_
//! An Irrlicht image loader for quake2 wal engine textures
class CImageLoaderWAL : public irr::video::IImageLoader
{
public:
virtual bool isALoadableFileExtension(const io::path& filename) const _IRR_OVERRIDE_;
virtual bool isALoadableFileFormat(irr::io::IReadFile* file) const _IRR_OVERRIDE_;
virtual irr::video::IImage* loadImage(irr::io::IReadFile* file) const _IRR_OVERRIDE_;
};
//! An Irrlicht image loader for Halflife 1 engine textures
class CImageLoaderWAL2 : public irr::video::IImageLoader
{
public:
virtual bool isALoadableFileExtension(const io::path& filename) const _IRR_OVERRIDE_;
virtual bool isALoadableFileFormat(irr::io::IReadFile* file) const _IRR_OVERRIDE_;
virtual irr::video::IImage* loadImage(irr::io::IReadFile* file) const _IRR_OVERRIDE_;
};
// byte-align structures
#include "irrpack.h"
// Halfelife wad3 type 67 file
struct miptex_halflife
{
c8 name[16];
u32 width, height;
u32 mipmap[4]; // four mip maps stored
} PACK_STRUCT;
//quake2 texture
struct miptex_quake2
{
c8 name[32];
u32 width;
u32 height;
u32 mipmap[4]; // four mip maps stored
c8 animname[32]; // next frame in animation chain
s32 flags;
s32 contents;
s32 value;
} PACK_STRUCT;
// Default alignment
#include "irrunpack.h"
#endif
}
}
#endif

View File

@ -1,137 +0,0 @@
// Copyright (C) 2002-2012 Nikolaus Gebhardt
// This file is part of the "Irrlicht Engine".
// For conditions of distribution and use, see copyright notice in irrlicht.h
#include "CImageWriterBMP.h"
#ifdef _IRR_COMPILE_WITH_BMP_WRITER_
#include "CImageLoaderBMP.h"
#include "IWriteFile.h"
#include "CColorConverter.h"
#include "irrString.h"
#include "os.h"
namespace irr
{
namespace video
{
IImageWriter* createImageWriterBMP()
{
return new CImageWriterBMP;
}
CImageWriterBMP::CImageWriterBMP()
{
#ifdef _DEBUG
setDebugName("CImageWriterBMP");
#endif
}
bool CImageWriterBMP::isAWriteableFileExtension(const io::path& filename) const
{
return core::hasFileExtension ( filename, "bmp" );
}
bool CImageWriterBMP::writeImage(io::IWriteFile* file, IImage* image, u32 param) const
{
// we always write 24-bit color because nothing really reads 32-bit
SBMPHeader imageHeader;
imageHeader.Id = 0x4d42;
imageHeader.Reserved = 0;
imageHeader.BitmapDataOffset = sizeof(imageHeader);
imageHeader.BitmapHeaderSize = 0x28;
imageHeader.Width = image->getDimension().Width;
imageHeader.Height = image->getDimension().Height;
imageHeader.Planes = 1;
imageHeader.BPP = 24;
imageHeader.Compression = 0;
imageHeader.PixelPerMeterX = 0;
imageHeader.PixelPerMeterY = 0;
imageHeader.Colors = 0;
imageHeader.ImportantColors = 0;
// data size is rounded up to next larger 4 bytes boundary
imageHeader.BitmapDataSize = imageHeader.Width * imageHeader.BPP / 8;
imageHeader.BitmapDataSize = (imageHeader.BitmapDataSize + 3) & ~3;
imageHeader.BitmapDataSize *= imageHeader.Height;
// file size is data size plus offset to data
imageHeader.FileSize = imageHeader.BitmapDataOffset + imageHeader.BitmapDataSize;
// bitmaps are stored upside down and padded so we always do this
void (*CColorConverter_convertFORMATtoFORMAT)(const void*, s32, void*) = 0;
switch(image->getColorFormat())
{
case ECF_R8G8B8:
CColorConverter_convertFORMATtoFORMAT
= CColorConverter::convert_R8G8B8toR8G8B8;
break;
case ECF_A8R8G8B8:
CColorConverter_convertFORMATtoFORMAT
= CColorConverter::convert_A8R8G8B8toB8G8R8;
break;
case ECF_A1R5G5B5:
CColorConverter_convertFORMATtoFORMAT
= CColorConverter::convert_A1R5G5B5toR8G8B8;
break;
case ECF_R5G6B5:
CColorConverter_convertFORMATtoFORMAT
= CColorConverter::convert_R5G6B5toR8G8B8;
break;
default:
os::Printer::log("CImageWriterBMP does not support image format", ColorFormatNames[image->getColorFormat()], ELL_WARNING);
break;
}
// couldn't find a color converter
if (!CColorConverter_convertFORMATtoFORMAT)
return false;
// write the bitmap header
if (file->write(&imageHeader, sizeof(imageHeader)) != sizeof(imageHeader))
return false;
u8* scan_lines = (u8*)image->getData();
if (!scan_lines)
return false;
// size of one pixel in bytes
u32 pixel_size = image->getBytesPerPixel();
// length of one row of the source image in bytes
u32 row_stride = (pixel_size * imageHeader.Width);
// length of one row in bytes, rounded up to nearest 4-byte boundary
size_t row_size = ((3 * imageHeader.Width) + 3) & ~3;
// allocate and clear memory for our scan line
u8* row_pointer = new u8[row_size];
memset(row_pointer, 0, row_size);
// convert the image to 24-bit BGR and flip it over
s32 y;
for (y = imageHeader.Height - 1; 0 <= y; --y)
{
if (image->getColorFormat()==ECF_R8G8B8)
CColorConverter::convert24BitTo24Bit(&scan_lines[y * row_stride], row_pointer, imageHeader.Width, 1, 0, false, true);
else
// source, length [pixels], destination
CColorConverter_convertFORMATtoFORMAT(&scan_lines[y * row_stride], imageHeader.Width, row_pointer);
if (file->write(row_pointer, row_size) < row_size)
break;
}
// clean up our scratch area
delete [] row_pointer;
return y < 0;
}
} // namespace video
} // namespace irr
#endif

View File

@ -1,37 +0,0 @@
// Copyright (C) 2002-2012 Nikolaus Gebhardt
// This file is part of the "Irrlicht Engine".
// For conditions of distribution and use, see copyright notice in irrlicht.h
#ifndef _C_IMAGE_WRITER_BMP_H_INCLUDED__
#define _C_IMAGE_WRITER_BMP_H_INCLUDED__
#include "IrrCompileConfig.h"
#ifdef _IRR_COMPILE_WITH_BMP_WRITER_
#include "IImageWriter.h"
namespace irr
{
namespace video
{
class CImageWriterBMP : public IImageWriter
{
public:
//! constructor
CImageWriterBMP();
//! return true if this writer can write a file with the given extension
virtual bool isAWriteableFileExtension(const io::path& filename) const _IRR_OVERRIDE_;
//! write image to file
virtual bool writeImage(io::IWriteFile *file, IImage *image, u32 param) const _IRR_OVERRIDE_;
};
} // namespace video
} // namespace irr
#endif
#endif // _C_IMAGE_WRITER_BMP_H_INCLUDED__

View File

@ -1,162 +0,0 @@
// Copyright (C) 2002-2012 Nikolaus Gebhardt
// This file is part of the "Irrlicht Engine".
// For conditions of distribution and use, see copyright notice in irrlicht.h
#include "CImageWriterPCX.h"
#ifdef _IRR_COMPILE_WITH_PCX_WRITER_
#include "CImageLoaderPCX.h"
#include "IWriteFile.h"
#include "os.h" // for logging
#include "irrString.h"
namespace irr
{
namespace video
{
IImageWriter* createImageWriterPCX()
{
return new CImageWriterPCX;
}
CImageWriterPCX::CImageWriterPCX()
{
#ifdef _DEBUG
setDebugName("CImageWriterPCX");
#endif
}
bool CImageWriterPCX::isAWriteableFileExtension(const io::path& filename) const
{
return core::hasFileExtension ( filename, "pcx" );
}
bool CImageWriterPCX::writeImage(io::IWriteFile *file, IImage *image,u32 param) const
{
if (!file || !image)
return false;
u8 d1;
u16 d2;
u32 i;
d1 = 10; // Manufacturer
file->write(&d1, 1);
d1 = 5; // Version
file->write(&d1, 1);
d1 = 1; // Encoding
file->write(&d1, 1);
d1 = 8; // Bits per Pixel
file->write(&d1, 1);
d2 = 0; // pixel origin
file->write(&d2, 2);
file->write(&d2, 2);
d2 = image->getDimension().Width-1; // width
#ifdef __BIG_ENDIAN__
d2 = os::Byteswap::byteswap(d2);
#endif
file->write(&d2, 2);
d2 = image->getDimension().Height-1; // height
#ifdef __BIG_ENDIAN__
d2 = os::Byteswap::byteswap(d2);
#endif
file->write(&d2, 2);
d2 = 300; // dpi
#ifdef __BIG_ENDIAN__
d2 = os::Byteswap::byteswap(d2);
#endif
file->write(&d2, 2);
file->write(&d2, 2);
d2 = 0; // palette (not used)
for (i=0; i<24; ++i)
{
file->write(&d2, 2);
}
d1 = 0; // reserved
file->write(&d1, 1);
d1 = 3; // planes
file->write(&d1, 1);
d2 = image->getDimension().Width; // pitch
if (d2&0x0001) // must be even
++d2;
#ifdef __BIG_ENDIAN__
d2 = os::Byteswap::byteswap(d2);
#endif
file->write(&d2, 2);
d2 = 1; // color mode
#ifdef __BIG_ENDIAN__
d2 = os::Byteswap::byteswap(d2);
#endif
file->write(&d2, 2);
d2 = 800; // screen width
#ifdef __BIG_ENDIAN__
d2 = os::Byteswap::byteswap(d2);
#endif
file->write(&d2, 2);
d2 = 600; // screen height
#ifdef __BIG_ENDIAN__
d2 = os::Byteswap::byteswap(d2);
#endif
file->write(&d2, 2);
d2 = 0; // filler (not used)
for (i=0; i<27; ++i)
{
file->write(&d2, 2);
}
u8 cnt, value;
for (i=0; i<image->getDimension().Height; ++i)
{
cnt = 0;
value = 0;
for (u32 j=0; j<3; ++j) // color planes
{
for (u32 k=0; k<image->getDimension().Width; ++k)
{
const SColor pix = image->getPixel(k,i);
if ((cnt!=0) && (cnt<63) &&
(((j==0) && (value==pix.getRed())) ||
((j==1) && (value==pix.getGreen())) ||
((j==2) && (value==pix.getBlue()))))
{
++cnt;
}
else
{
if (cnt!=0)
{
if ((cnt>1) || ((value&0xc0)==0xc0))
{
cnt |= 0xc0;
file->write(&cnt, 1);
}
file->write(&value, 1);
}
cnt=1;
if (j==0)
value=(u8)pix.getRed();
else if (j==1)
value=(u8)pix.getGreen();
else if (j==2)
value=(u8)pix.getBlue();
}
}
}
if ((cnt>1) || ((value&0xc0)==0xc0))
{
cnt |= 0xc0;
file->write(&cnt, 1);
}
file->write(&value, 1);
}
return true;
}
} // namespace video
} // namespace irr
#endif

View File

@ -1,37 +0,0 @@
// Copyright (C) 2002-2012 Nikolaus Gebhardt
// This file is part of the "Irrlicht Engine".
// For conditions of distribution and use, see copyright notice in irrlicht.h
#ifndef _C_IMAGE_WRITER_PCX_H_INCLUDED__
#define _C_IMAGE_WRITER_PCX_H_INCLUDED__
#include "IrrCompileConfig.h"
#ifdef _IRR_COMPILE_WITH_PCX_WRITER_
#include "IImageWriter.h"
namespace irr
{
namespace video
{
class CImageWriterPCX : public IImageWriter
{
public:
//! constructor
CImageWriterPCX();
//! return true if this writer can write a file with the given extension
virtual bool isAWriteableFileExtension(const io::path& filename) const _IRR_OVERRIDE_;
//! write image to file
virtual bool writeImage(io::IWriteFile *file, IImage *image, u32 param) const _IRR_OVERRIDE_;
};
} // namespace video
} // namespace irr
#endif
#endif // _C_IMAGE_WRITER_PCX_H_INCLUDED__

View File

@ -1,113 +0,0 @@
// Copyright (C) 2002-2012 Nikolaus Gebhardt
// This file is part of the "Irrlicht Engine".
// For conditions of distribution and use, see copyright notice in irrlicht.h
#include "CImageWriterPPM.h"
#ifdef _IRR_COMPILE_WITH_PPM_WRITER_
#include "IWriteFile.h"
#include "IImage.h"
#include "dimension2d.h"
#include "irrString.h"
namespace irr
{
namespace video
{
IImageWriter* createImageWriterPPM()
{
return new CImageWriterPPM;
}
CImageWriterPPM::CImageWriterPPM()
{
#ifdef _DEBUG
setDebugName("CImageWriterPPM");
#endif
}
bool CImageWriterPPM::isAWriteableFileExtension(const io::path& filename) const
{
return core::hasFileExtension ( filename, "ppm" );
}
bool CImageWriterPPM::writeImage(io::IWriteFile *file, IImage *image, u32 param) const
{
char cache[70];
int size;
const core::dimension2d<u32>& imageSize = image->getDimension();
const bool binary = false;
if (binary)
size = snprintf_irr(cache, 70, "P6\n");
else
size = snprintf_irr(cache, 70, "P3\n");
if ( size < 0 )
return false;
if (file->write(cache, (size_t)size) != (size_t)size)
return false;
size = snprintf_irr(cache, 70, "%u %u\n", imageSize.Width, imageSize.Height);
if ( size < 0 )
return false;
if (file->write(cache, (size_t)size) != (size_t)size)
return false;
size = snprintf_irr(cache, 70, "255\n");
if ( size < 0 )
return false;
if (file->write(cache, (size_t)size) != (size_t)size)
return false;
if (binary)
{
for (u32 h = 0; h < imageSize.Height; ++h)
{
for (u32 c = 0; c < imageSize.Width; ++c)
{
const video::SColor& pixel = image->getPixel(c, h);
const u8 r = (u8)(pixel.getRed() & 0xff);
const u8 g = (u8)(pixel.getGreen() & 0xff);
const u8 b = (u8)(pixel.getBlue() & 0xff);
file->write(&r, 1);
file->write(&g, 1);
file->write(&b, 1);
}
}
}
else
{
s32 n = 0;
for (u32 h = 0; h < imageSize.Height; ++h)
{
for (u32 c = 0; c < imageSize.Width; ++c, ++n)
{
const video::SColor& pixel = image->getPixel(c, h);
size = snprintf_irr(cache, 70, "%.3u %.3u %.3u%s", pixel.getRed(), pixel.getGreen(), pixel.getBlue(), n % 5 == 4 ? "\n" : " ");
if ( size < 0 )
return false;
if (file->write(cache, (size_t)size) != (size_t)size)
return false;
}
}
}
return true;
}
} // namespace video
} // namespace irr
#endif

View File

@ -1,37 +0,0 @@
// Copyright (C) 2002-2012 Nikolaus Gebhardt
// This file is part of the "Irrlicht Engine".
// For conditions of distribution and use, see copyright notice in irrlicht.h
#ifndef _C_IMAGE_WRITER_PPM_H_INCLUDED__
#define _C_IMAGE_WRITER_PPM_H_INCLUDED__
#include "IrrCompileConfig.h"
#ifdef _IRR_COMPILE_WITH_PPM_WRITER_
#include "IImageWriter.h"
namespace irr
{
namespace video
{
class CImageWriterPPM : public IImageWriter
{
public:
//! constructor
CImageWriterPPM();
//! return true if this writer can write a file with the given extension
virtual bool isAWriteableFileExtension(const io::path& filename) const _IRR_OVERRIDE_;
//! write image to file
virtual bool writeImage(io::IWriteFile *file, IImage *image, u32 param) const _IRR_OVERRIDE_;
};
} // namespace video
} // namespace irr
#endif // _C_IMAGE_WRITER_PPM_H_INCLUDED__
#endif

View File

@ -1,46 +0,0 @@
// Copyright (C) 2002-2012 Nikolaus Gebhardt
// This file is part of the "Irrlicht Engine".
// For conditions of distribution and use, see copyright notice in irrlicht.h
#include "CImageWriterPSD.h"
#ifdef _IRR_COMPILE_WITH_PSD_WRITER_
#include "CImageLoaderPSD.h"
#include "IWriteFile.h"
#include "os.h" // for logging
#include "irrString.h"
namespace irr
{
namespace video
{
IImageWriter* createImageWriterPSD()
{
return new CImageWriterPSD;
}
CImageWriterPSD::CImageWriterPSD()
{
#ifdef _DEBUG
setDebugName("CImageWriterPSD");
#endif
}
bool CImageWriterPSD::isAWriteableFileExtension(const io::path& filename) const
{
return core::hasFileExtension ( filename, "psd" );
}
bool CImageWriterPSD::writeImage(io::IWriteFile *file, IImage *image,u32 param) const
{
os::Printer::log("PSD writer not yet implemented. Image not written.", ELL_WARNING);
return false;
}
} // namespace video
} // namespace irr
#endif

View File

@ -1,37 +0,0 @@
// Copyright (C) 2002-2012 Nikolaus Gebhardt
// This file is part of the "Irrlicht Engine".
// For conditions of distribution and use, see copyright notice in irrlicht.h
#ifndef _C_IMAGE_WRITER_PSD_H_INCLUDED__
#define _C_IMAGE_WRITER_PSD_H_INCLUDED__
#include "IrrCompileConfig.h"
#ifdef _IRR_COMPILE_WITH_PSD_WRITER_
#include "IImageWriter.h"
namespace irr
{
namespace video
{
class CImageWriterPSD : public IImageWriter
{
public:
//! constructor
CImageWriterPSD();
//! return true if this writer can write a file with the given extension
virtual bool isAWriteableFileExtension(const io::path& filename) const _IRR_OVERRIDE_;
//! write image to file
virtual bool writeImage(io::IWriteFile *file, IImage *image,u32 param) const _IRR_OVERRIDE_;
};
} // namespace video
} // namespace irr
#endif // _I_IMAGE_WRITER_PSD_H_INCLUDED__
#endif

View File

@ -1,145 +0,0 @@
// Copyright (C) 2002-2012 Nikolaus Gebhardt
// This file is part of the "Irrlicht Engine".
// For conditions of distribution and use, see copyright notice in irrlicht.h
#include "CImageWriterTGA.h"
#ifdef _IRR_COMPILE_WITH_TGA_WRITER_
#include "CImageLoaderTGA.h"
#include "IWriteFile.h"
#include "CColorConverter.h"
#include "irrString.h"
#include "os.h"
namespace irr
{
namespace video
{
IImageWriter* createImageWriterTGA()
{
return new CImageWriterTGA;
}
CImageWriterTGA::CImageWriterTGA()
{
#ifdef _DEBUG
setDebugName("CImageWriterTGA");
#endif
}
bool CImageWriterTGA::isAWriteableFileExtension(const io::path& filename) const
{
return core::hasFileExtension ( filename, "tga" );
}
bool CImageWriterTGA::writeImage(io::IWriteFile *file, IImage *image,u32 param) const
{
STGAHeader imageHeader;
imageHeader.IdLength = 0;
imageHeader.ColorMapType = 0;
imageHeader.ImageType = 2;
imageHeader.FirstEntryIndex[0] = 0;
imageHeader.FirstEntryIndex[1] = 0;
imageHeader.ColorMapLength = 0;
imageHeader.ColorMapEntrySize = 0;
imageHeader.XOrigin[0] = 0;
imageHeader.XOrigin[1] = 0;
imageHeader.YOrigin[0] = 0;
imageHeader.YOrigin[1] = 0;
imageHeader.ImageWidth = image->getDimension().Width;
imageHeader.ImageHeight = image->getDimension().Height;
// top left of image is the top. the image loader needs to
// be fixed to only swap/flip
imageHeader.ImageDescriptor = (1 << 5);
// chances are good we'll need to swizzle data, so i'm going
// to convert and write one scan line at a time. it's also
// a bit cleaner this way
void (*CColorConverter_convertFORMATtoFORMAT)(const void*, s32, void*) = 0;
switch(image->getColorFormat())
{
case ECF_A8R8G8B8:
CColorConverter_convertFORMATtoFORMAT
= CColorConverter::convert_A8R8G8B8toA8R8G8B8;
imageHeader.PixelDepth = 32;
imageHeader.ImageDescriptor |= 8;
break;
case ECF_A1R5G5B5:
CColorConverter_convertFORMATtoFORMAT
= CColorConverter::convert_A1R5G5B5toA1R5G5B5;
imageHeader.PixelDepth = 16;
imageHeader.ImageDescriptor |= 1;
break;
case ECF_R5G6B5:
CColorConverter_convertFORMATtoFORMAT
= CColorConverter::convert_R5G6B5toA1R5G5B5;
imageHeader.PixelDepth = 16;
imageHeader.ImageDescriptor |= 1;
break;
case ECF_R8G8B8:
CColorConverter_convertFORMATtoFORMAT
= CColorConverter::convert_R8G8B8toR8G8B8;
imageHeader.PixelDepth = 24;
imageHeader.ImageDescriptor |= 0;
break;
default:
os::Printer::log("CImageWriterTGA does not support image format", ColorFormatNames[image->getColorFormat()], ELL_WARNING);
break;
}
// couldn't find a color converter
if (!CColorConverter_convertFORMATtoFORMAT)
return false;
if (file->write(&imageHeader, sizeof(imageHeader)) != sizeof(imageHeader))
return false;
u8* scan_lines = (u8*)image->getData();
if (!scan_lines)
return false;
// size of one pixel in bytes
u32 pixel_size = image->getBytesPerPixel();
// length of one row of the source image in bytes
u32 row_stride = (pixel_size * imageHeader.ImageWidth);
// length of one output row in bytes
size_t row_size = ((imageHeader.PixelDepth / 8) * imageHeader.ImageWidth);
// allocate a row do translate data into
u8* row_pointer = new u8[row_size];
u32 y;
for (y = 0; y < imageHeader.ImageHeight; ++y)
{
// source, length [pixels], destination
if (image->getColorFormat()==ECF_R8G8B8)
CColorConverter::convert24BitTo24Bit(&scan_lines[y * row_stride], row_pointer, imageHeader.ImageWidth, 1, 0, 0, true);
else
CColorConverter_convertFORMATtoFORMAT(&scan_lines[y * row_stride], imageHeader.ImageWidth, row_pointer);
if (file->write(row_pointer, row_size) != row_size)
break;
}
delete [] row_pointer;
STGAFooter imageFooter;
imageFooter.ExtensionOffset = 0;
imageFooter.DeveloperOffset = 0;
strncpy(imageFooter.Signature, "TRUEVISION-XFILE.", 18);
if (file->write(&imageFooter, sizeof(imageFooter)) < (s32)sizeof(imageFooter))
return false;
return imageHeader.ImageHeight <= y;
}
} // namespace video
} // namespace irr
#endif

View File

@ -1,37 +0,0 @@
// Copyright (C) 2002-2012 Nikolaus Gebhardt
// This file is part of the "Irrlicht Engine".
// For conditions of distribution and use, see copyright notice in irrlicht.h
#ifndef _C_IMAGE_WRITER_TGA_H_INCLUDED__
#define _C_IMAGE_WRITER_TGA_H_INCLUDED__
#include "IrrCompileConfig.h"
#ifdef _IRR_COMPILE_WITH_TGA_WRITER_
#include "IImageWriter.h"
namespace irr
{
namespace video
{
class CImageWriterTGA : public IImageWriter
{
public:
//! constructor
CImageWriterTGA();
//! return true if this writer can write a file with the given extension
virtual bool isAWriteableFileExtension(const io::path& filename) const _IRR_OVERRIDE_;
//! write image to file
virtual bool writeImage(io::IWriteFile *file, IImage *image,u32 param) const _IRR_OVERRIDE_;
};
} // namespace video
} // namespace irr
#endif // _C_IMAGE_WRITER_TGA_H_INCLUDED__
#endif

View File

@ -1,380 +0,0 @@
// Copyright (C) 2002-2012 Nikolaus Gebhardt
// This file is part of the "Irrlicht Engine".
// For conditions of distribution and use, see copyright notice in irrlicht.h
// This file was written by Jonas Petersen and modified by Nikolaus Gebhardt.
// See CLMTSMeshFileLoder.h for details.
/*
CLMTSMeshFileLoader.cpp
LMTSMeshFileLoader
Written by Jonas Petersen (a.k.a. jox)
Version 1.5 - 15 March 2005
Get the latest version here: http://development.mindfloaters.de/
This class allows loading meshes with lightmaps (*.lmts + *.tga files) that were created
using Pulsar LMTools by Lord Trancos (http://www.geocities.com/dxlab/index_en.html)
Notes:
- This version does not support user data in the *.lmts files, but still loads those files (by skipping the extra data).
License:
--------
It's free. You are encouraged to give me credit if you use it in your software.
Version History:
----------------
Version 1.5 - 15 March 2005
- Did a better cleanup. No memory leaks in case of an loading error.
- Added "#include <stdio.h>" for sprintf.
Version 1.4 - 12 March 2005
- Fixed bug in texture and subset loading code that would possibly cause crash.
- Fixed memory cleanup to avoid leak when loading more then one mesh
- Used the irrlicht Logger instead of cerr to output warnings and errors.
For this I had to change the constructor
from:
CLMTSMeshFileLoader(io::IFileSystem* fs, video::IVideoDriver* driver)
to:
CLMTSMeshFileLoader(IrrlichtDevice* device)
Version 1.3 - 15 February 2005
- Fixed bug that prevented loading more than one different lmts files.
- Removed unnecessary "#include <os.h>".
- Added "std::" in front of "cerr". This was necessary for Visual Studio .NET,
I hope it's not disturbing other compilers.
- Added warning message when a texture can not be loaded.
- Changed the documentation a bit (minor).
Version 1.2
- To avoid confusion I skipped version 1.2 because the website was offering
version 1.2 even though it was only version 1.1. Sorry about that.
Version 1.1 - 29 July 2004
- Added setTexturePath() function
- Minor improvements
Version 1.0 - 29 July 2004
- Initial release
*/
//////////////////////////////////////////////////////////////////////
#include "IrrCompileConfig.h"
#ifdef _IRR_COMPILE_WITH_LMTS_LOADER_
#include "CLMTSMeshFileLoader.h"
#include "CMeshTextureLoader.h"
#include "SMeshBufferLightMap.h"
#include "SAnimatedMesh.h"
#include "SMeshBuffer.h"
#include "irrString.h"
#include "IReadFile.h"
#include "IAttributes.h"
#include "ISceneManager.h"
#include "os.h"
namespace irr
{
namespace scene
{
CLMTSMeshFileLoader::CLMTSMeshFileLoader(io::IFileSystem* fs,
video::IVideoDriver* driver, io::IAttributes* parameters)
: Textures(0), Subsets(0), Triangles(0),
Parameters(parameters), Driver(driver), FileSystem(fs), FlipEndianess(false)
{
#ifdef _DEBUG
setDebugName("CLMTSMeshFileLoader");
#endif
if (Driver)
Driver->grab();
if (FileSystem)
FileSystem->grab();
TextureLoader = new CMeshTextureLoader( FileSystem, Driver );
}
CLMTSMeshFileLoader::~CLMTSMeshFileLoader()
{
cleanup();
if (Driver)
Driver->drop();
if (FileSystem)
FileSystem->drop();
}
void CLMTSMeshFileLoader::cleanup()
{
delete [] Textures;
Textures = 0;
delete [] Subsets;
Subsets = 0;
delete [] Triangles;
Triangles = 0;
}
bool CLMTSMeshFileLoader::isALoadableFileExtension(const io::path& filename) const
{
return core::hasFileExtension ( filename, "lmts" );
}
IAnimatedMesh* CLMTSMeshFileLoader::createMesh(io::IReadFile* file)
{
if ( getMeshTextureLoader() )
getMeshTextureLoader()->setMeshFile(file);
u32 i;
u32 id;
// HEADER
file->read(&Header, sizeof(SLMTSHeader));
if (Header.MagicID == 0x4C4D5354)
{
FlipEndianess = true;
Header.MagicID = os::Byteswap::byteswap(Header.MagicID);
Header.Version = os::Byteswap::byteswap(Header.Version);
Header.HeaderSize = os::Byteswap::byteswap(Header.HeaderSize);
Header.TextureCount = os::Byteswap::byteswap(Header.TextureCount);
Header.SubsetCount = os::Byteswap::byteswap(Header.SubsetCount);
Header.TriangleCount = os::Byteswap::byteswap(Header.TriangleCount);
Header.SubsetSize = os::Byteswap::byteswap(Header.SubsetSize);
Header.VertexSize = os::Byteswap::byteswap(Header.VertexSize);
}
if (Header.MagicID != 0x53544D4C) { // "LMTS"
os::Printer::log("LMTS ERROR: wrong header magic id!", ELL_ERROR);
return 0;
}
//Skip any User Data (arbitrary app specific data)
const s32 userSize = Header.HeaderSize - sizeof(SLMTSHeader);
if (userSize>0)
file->seek(userSize,true);
// TEXTURES
file->read(&id, sizeof(u32));
if (FlipEndianess)
id = os::Byteswap::byteswap(id);
if (id != 0x54584554) { // "TEXT"
os::Printer::log("LMTS ERROR: wrong texture magic id!", ELL_ERROR);
return 0;
}
Textures = new SLMTSTextureInfoEntry[Header.TextureCount];
file->read(Textures, sizeof(SLMTSTextureInfoEntry)*Header.TextureCount);
if (FlipEndianess)
{
for (i=0; i<Header.TextureCount; ++i)
Textures[i].Flags = os::Byteswap::byteswap(Textures[i].Flags);
}
// SUBSETS
file->read(&id, sizeof(u32));
if (FlipEndianess)
id = os::Byteswap::byteswap(id);
if (id != 0x53425553) // "SUBS"
{
os::Printer::log("LMTS ERROR: wrong subset magic id!", ELL_ERROR);
cleanup();
return 0;
}
Subsets = new SLMTSSubsetInfoEntry[Header.SubsetCount];
const s32 subsetUserSize = Header.SubsetSize - sizeof(SLMTSSubsetInfoEntry);
for (i=0; i<Header.SubsetCount; ++i)
{
file->read(&Subsets[i], sizeof(SLMTSSubsetInfoEntry));
if (FlipEndianess)
{
Subsets[i].Offset = os::Byteswap::byteswap(Subsets[i].Offset);
Subsets[i].Count = os::Byteswap::byteswap(Subsets[i].Count);
Subsets[i].TextID1 = os::Byteswap::byteswap(Subsets[i].TextID1);
Subsets[i].TextID2 = os::Byteswap::byteswap(Subsets[i].TextID2);
}
if (subsetUserSize>0)
file->seek(subsetUserSize,true);
}
// TRIANGLES
file->read(&id, sizeof(u32));
if (FlipEndianess)
id = os::Byteswap::byteswap(id);
if (id != 0x53495254) // "TRIS"
{
os::Printer::log("LMTS ERROR: wrong triangle magic id!", ELL_ERROR);
cleanup();
return 0;
}
Triangles = new SLMTSTriangleDataEntry[(Header.TriangleCount*3)];
const s32 triUserSize = Header.VertexSize - sizeof(SLMTSTriangleDataEntry);
for (i=0; i<(Header.TriangleCount*3); ++i)
{
file->read(&Triangles[i], sizeof(SLMTSTriangleDataEntry));
if (FlipEndianess)
{
Triangles[i].X = os::Byteswap::byteswap(Triangles[i].X);
Triangles[i].Y = os::Byteswap::byteswap(Triangles[i].Y);
Triangles[i].Z = os::Byteswap::byteswap(Triangles[i].Z);
Triangles[i].U1 = os::Byteswap::byteswap(Triangles[i].U1);
Triangles[i].V1 = os::Byteswap::byteswap(Triangles[i].U2);
Triangles[i].U2 = os::Byteswap::byteswap(Triangles[i].V1);
Triangles[i].V2 = os::Byteswap::byteswap(Triangles[i].V2);
}
if (triUserSize>0)
file->seek(triUserSize,true);
}
/////////////////////////////////////////////////////////////////
SMesh* mesh = new SMesh();
constructMesh(mesh);
loadTextures(mesh);
cleanup();
SAnimatedMesh* am = new SAnimatedMesh();
am->Type = EAMT_LMTS; // not unknown to irrlicht anymore
am->addMesh(mesh);
am->recalculateBoundingBox();
mesh->drop();
return am;
}
void CLMTSMeshFileLoader::constructMesh(SMesh* mesh)
{
for (s32 i=0; i<Header.SubsetCount; ++i)
{
scene::SMeshBufferLightMap* meshBuffer = new scene::SMeshBufferLightMap();
// EMT_LIGHTMAP_M2/EMT_LIGHTMAP_M4 also possible
meshBuffer->Material.MaterialType = video::EMT_LIGHTMAP;
meshBuffer->Material.Wireframe = false;
meshBuffer->Material.Lighting = false;
mesh->addMeshBuffer(meshBuffer);
const u32 offs = Subsets[i].Offset * 3;
for (u32 sc=0; sc<Subsets[i].Count; sc++)
{
const u32 idx = meshBuffer->getVertexCount();
for (u32 vu=0; vu<3; ++vu)
{
const SLMTSTriangleDataEntry& v = Triangles[offs+(3*sc)+vu];
meshBuffer->Vertices.push_back(
video::S3DVertex2TCoords(
v.X, v.Y, v.Z,
video::SColor(255,255,255,255),
v.U1, v.V1, v.U2, v.V2));
}
const core::vector3df normal = core::plane3df(
meshBuffer->Vertices[idx].Pos,
meshBuffer->Vertices[idx+1].Pos,
meshBuffer->Vertices[idx+2].Pos).Normal;
meshBuffer->Vertices[idx].Normal = normal;
meshBuffer->Vertices[idx+1].Normal = normal;
meshBuffer->Vertices[idx+2].Normal = normal;
meshBuffer->Indices.push_back(idx);
meshBuffer->Indices.push_back(idx+1);
meshBuffer->Indices.push_back(idx+2);
}
meshBuffer->drop();
}
for (u32 j=0; j<mesh->MeshBuffers.size(); ++j)
mesh->MeshBuffers[j]->recalculateBoundingBox();
mesh->recalculateBoundingBox();
}
void CLMTSMeshFileLoader::loadTextures(SMesh* mesh)
{
if (!Driver || !FileSystem)
return;
// load textures
// a little too much space, but won't matter here
core::array<video::ITexture*> tex;
tex.reallocate(Header.TextureCount);
core::array<video::ITexture*> lig;
lig.reallocate(Header.TextureCount);
core::array<u32> id2id;
id2id.reallocate(Header.TextureCount);
if ( getMeshTextureLoader() )
{
if ( Parameters->existsAttribute(LMTS_TEXTURE_PATH) )
getMeshTextureLoader()->setTexturePath(Parameters->getAttributeAsString(LMTS_TEXTURE_PATH));
}
core::stringc s;
for (u32 t=0; t<Header.TextureCount; ++t)
{
video::ITexture* tmptex = getMeshTextureLoader() ? getMeshTextureLoader()->getTexture(Textures[t].Filename) : NULL;
if ( !tmptex )
{
os::Printer::log("LMTS WARNING: Texture does not exist", s.c_str(), ELL_WARNING);
}
if (Textures[t].Flags & 0x01)
{
id2id.push_back(lig.size());
lig.push_back(tmptex);
}
else
{
id2id.push_back(tex.size());
tex.push_back(tmptex);
}
}
// attach textures to materials.
for (u32 i=0; i<Header.SubsetCount; ++i)
{
if (Subsets[i].TextID1 < Header.TextureCount && id2id[Subsets[i].TextID1] < tex.size())
mesh->getMeshBuffer(i)->getMaterial().setTexture(0, tex[id2id[Subsets[i].TextID1]]);
if (Subsets[i].TextID2 < Header.TextureCount && id2id[Subsets[i].TextID2] < lig.size())
mesh->getMeshBuffer(i)->getMaterial().setTexture(1, lig[id2id[Subsets[i].TextID2]]);
if (!mesh->getMeshBuffer(i)->getMaterial().getTexture(1))
mesh->getMeshBuffer(i)->getMaterial().MaterialType = video::EMT_SOLID;
}
}
} // end namespace scene
} // end namespace irr
#endif // _IRR_COMPILE_WITH_LMTS_LOADER_

View File

@ -1,109 +0,0 @@
// Copyright (C) 2002-2012 Nikolaus Gebhardt
// This file is part of the "Irrlicht Engine".
// For conditions of distribution and use, see copyright notice in irrlicht.h
//
// I (Nikolaus Gebhardt) did some few changes to Jonas Petersen's original loader:
// - removed setTexturePath() and replaced with the ISceneManager::getStringParameter()-stuff.
// - added EAMT_LMTS enumeration value
// Thanks a lot to Jonas Petersen for his work
// on this and that he gave me his permission to add it into Irrlicht.
/*
CLMTSMeshFileLoader.h
LMTSMeshFileLoader
Written by Jonas Petersen (a.k.a. jox)
Version 1.5 - 15 March 2005
*/
#if !defined(__C_LMTS_MESH_FILE_LOADER_H_INCLUDED__)
#define __C_LMTS_MESH_FILE_LOADER_H_INCLUDED__
#include "IMeshLoader.h"
#include "SMesh.h"
#include "IFileSystem.h"
#include "IVideoDriver.h"
namespace irr
{
namespace scene
{
class CLMTSMeshFileLoader : public IMeshLoader
{
public:
CLMTSMeshFileLoader(io::IFileSystem* fs,
video::IVideoDriver* driver, io::IAttributes* parameters);
virtual ~CLMTSMeshFileLoader();
virtual bool isALoadableFileExtension(const io::path& filename) const _IRR_OVERRIDE_;
virtual IAnimatedMesh* createMesh(io::IReadFile* file) _IRR_OVERRIDE_;
private:
void constructMesh(SMesh* mesh);
void loadTextures(SMesh* mesh);
void cleanup();
// byte-align structures
#include "irrpack.h"
struct SLMTSHeader
{
u32 MagicID;
u32 Version;
u32 HeaderSize;
u16 TextureCount;
u16 SubsetCount;
u32 TriangleCount;
u16 SubsetSize;
u16 VertexSize;
} PACK_STRUCT;
struct SLMTSTextureInfoEntry
{
c8 Filename[256];
u16 Flags;
} PACK_STRUCT;
struct SLMTSSubsetInfoEntry
{
u32 Offset;
u32 Count;
u16 TextID1;
u16 TextID2;
} PACK_STRUCT;
struct SLMTSTriangleDataEntry
{
f32 X;
f32 Y;
f32 Z;
f32 U1;
f32 V1;
f32 U2;
f32 V2;
} PACK_STRUCT;
// Default alignment
#include "irrunpack.h"
SLMTSHeader Header;
SLMTSTextureInfoEntry* Textures;
SLMTSSubsetInfoEntry* Subsets;
SLMTSTriangleDataEntry* Triangles;
io::IAttributes* Parameters;
video::IVideoDriver* Driver;
io::IFileSystem* FileSystem;
bool FlipEndianess;
};
} // end namespace scene
} // end namespace irr
#endif // !defined(__C_LMTS_MESH_FILE_LOADER_H_INCLUDED__)

File diff suppressed because it is too large Load Diff

View File

@ -1,87 +0,0 @@
// Copyright (C) 2002-2012 Nikolaus Gebhardt
// This file is part of the "Irrlicht Engine".
// For conditions of distribution and use, see copyright notice in irrlicht.h
#ifndef __C_LWO_MESH_FILE_LOADER_H_INCLUDED__
#define __C_LWO_MESH_FILE_LOADER_H_INCLUDED__
#include "IMeshLoader.h"
#include "SMeshBuffer.h"
#include "irrString.h"
namespace irr
{
namespace io
{
class IReadFile;
class IFileSystem;
} // end namespace io
namespace scene
{
struct SMesh;
class ISceneManager;
//! Meshloader capable of loading Lightwave 3D meshes.
class CLWOMeshFileLoader : public IMeshLoader
{
public:
//! Constructor
CLWOMeshFileLoader(scene::ISceneManager* smgr, io::IFileSystem* fs);
//! destructor
virtual ~CLWOMeshFileLoader();
//! returns true if the file maybe is able to be loaded by this class
//! based on the file extension (e.g. ".bsp")
virtual bool isALoadableFileExtension(const io::path& filename) const _IRR_OVERRIDE_;
//! creates/loads an animated mesh from the file.
//! \return Pointer to the created mesh. Returns 0 if loading failed.
//! If you no longer need the mesh, you should call IAnimatedMesh::drop().
//! See IUnknown::drop() for more information.
virtual IAnimatedMesh* createMesh(io::IReadFile* file) _IRR_OVERRIDE_;
private:
struct tLWOMaterial;
bool readFileHeader();
bool readChunks();
void readObj1(u32 size);
void readTagMapping(u32 size);
void readVertexMapping(u32 size);
void readDiscVertexMapping (u32 size);
void readObj2(u32 size);
void readMat(u32 size);
u32 readString(core::stringc& name, u32 size=0);
u32 readVec(core::vector3df& vec);
u32 readVX(u32& num);
u32 readColor(video::SColor& color);
video::ITexture* loadTexture(const core::stringc& file);
scene::ISceneManager* SceneManager;
io::IFileSystem* FileSystem;
io::IReadFile* File;
SMesh* Mesh;
core::array<core::vector3df> Points;
core::array<core::array<u32> > Indices;
core::array<core::stringc> UvName;
core::array<core::array<u32> > UvIndex;
core::array<core::stringc> DUvName;
core::array<core::array<u32> > VmPolyPointsIndex;
core::array<core::array<core::vector2df> > VmCoordsIndex;
core::array<u16> MaterialMapping;
core::array<core::array<core::vector2df> > TCoords;
core::array<tLWOMaterial*> Materials;
core::array<core::stringc> Images;
u8 FormatVersion;
};
} // end namespace scene
} // end namespace irr
#endif

View File

@ -1,281 +0,0 @@
// Copyright (C) 2002-2012 Nikolaus Gebhardt
// This file is part of the "Irrlicht Engine".
// For conditions of distribution and use, see copyright notice in irrlicht.h
#include "CLightSceneNode.h"
#include "IVideoDriver.h"
#include "ISceneManager.h"
#include "ICameraSceneNode.h"
#include "os.h"
namespace irr
{
namespace scene
{
//! constructor
CLightSceneNode::CLightSceneNode(ISceneNode* parent, ISceneManager* mgr, s32 id,
const core::vector3df& position, video::SColorf color, f32 radius)
: ILightSceneNode(parent, mgr, id, position), DriverLightIndex(-1), LightIsOn(true)
{
#ifdef _DEBUG
setDebugName("CLightSceneNode");
#endif
LightData.DiffuseColor = color;
// set some useful specular color
LightData.SpecularColor = color.getInterpolated(video::SColor(255,255,255,255),0.7f);
setRadius(radius);
}
//! pre render event
void CLightSceneNode::OnRegisterSceneNode()
{
doLightRecalc(); // TODO: since doLightRecalc has now been added to updateAbsolutePosition it might be possible to remove this one.
if (IsVisible)
SceneManager->registerNodeForRendering(this, ESNRP_LIGHT);
ISceneNode::OnRegisterSceneNode();
}
//! render
void CLightSceneNode::render()
{
video::IVideoDriver* driver = SceneManager->getVideoDriver();
if (!driver)
return;
if ( DebugDataVisible & scene::EDS_BBOX )
{
driver->setTransform(video::ETS_WORLD, AbsoluteTransformation);
video::SMaterial m;
m.Lighting = false;
driver->setMaterial(m);
switch ( LightData.Type )
{
case video::ELT_POINT:
case video::ELT_SPOT:
driver->draw3DBox(BBox, LightData.DiffuseColor.toSColor());
break;
case video::ELT_DIRECTIONAL:
driver->draw3DLine(core::vector3df(0.f, 0.f, 0.f),
LightData.Direction * LightData.Radius,
LightData.DiffuseColor.toSColor());
break;
default:
break;
}
}
DriverLightIndex = driver->addDynamicLight(LightData);
setVisible(LightIsOn);
}
//! sets the light data
void CLightSceneNode::setLightData(const video::SLight& light)
{
LightData = light;
}
//! \return Returns the light data.
const video::SLight& CLightSceneNode::getLightData() const
{
return LightData;
}
//! \return Returns the light data.
video::SLight& CLightSceneNode::getLightData()
{
return LightData;
}
void CLightSceneNode::setVisible(bool isVisible)
{
ISceneNode::setVisible(isVisible);
if(DriverLightIndex < 0)
return;
video::IVideoDriver* driver = SceneManager->getVideoDriver();
if (!driver)
return;
LightIsOn = isVisible;
driver->turnLightOn((u32)DriverLightIndex, LightIsOn);
}
//! returns the axis aligned bounding box of this node
const core::aabbox3d<f32>& CLightSceneNode::getBoundingBox() const
{
return BBox;
}
//! Sets the light's radius of influence.
/** Outside this radius the light won't lighten geometry and cast no
shadows. Setting the radius will also influence the attenuation, setting
it to (0,1/radius,0). If you want to override this behavior, set the
attenuation after the radius.
\param radius The new radius. */
void CLightSceneNode::setRadius(f32 radius)
{
LightData.Radius=radius;
LightData.Attenuation.set(0.f, 1.f/radius, 0.f);
doLightRecalc();
}
//! Gets the light's radius of influence.
/** \return The current radius. */
f32 CLightSceneNode::getRadius() const
{
return LightData.Radius;
}
//! Sets the light type.
/** \param type The new type. */
void CLightSceneNode::setLightType(video::E_LIGHT_TYPE type)
{
LightData.Type=type;
}
//! Gets the light type.
/** \return The current light type. */
video::E_LIGHT_TYPE CLightSceneNode::getLightType() const
{
return LightData.Type;
}
//! Sets whether this light casts shadows.
/** Enabling this flag won't automatically cast shadows, the meshes
will still need shadow scene nodes attached. But one can enable or
disable distinct lights for shadow casting for performance reasons.
\param shadow True if this light shall cast shadows. */
void CLightSceneNode::enableCastShadow(bool shadow)
{
LightData.CastShadows=shadow;
}
//! Check whether this light casts shadows.
/** \return True if light would cast shadows, else false. */
bool CLightSceneNode::getCastShadow() const
{
return LightData.CastShadows;
}
void CLightSceneNode::doLightRecalc()
{
if ((LightData.Type == video::ELT_SPOT) || (LightData.Type == video::ELT_DIRECTIONAL))
{
LightData.Direction = core::vector3df(.0f,.0f,1.0f);
getAbsoluteTransformation().rotateVect(LightData.Direction);
LightData.Direction.normalize();
}
if ((LightData.Type == video::ELT_SPOT) || (LightData.Type == video::ELT_POINT))
{
const f32 r = LightData.Radius * LightData.Radius * 0.5f;
BBox.MaxEdge.set( r, r, r );
BBox.MinEdge.set( -r, -r, -r );
//setAutomaticCulling( scene::EAC_BOX );
setAutomaticCulling( scene::EAC_OFF );
LightData.Position = getAbsolutePosition();
}
if (LightData.Type == video::ELT_DIRECTIONAL)
{
BBox.reset( 0, 0, 0 );
setAutomaticCulling( scene::EAC_OFF );
}
}
void CLightSceneNode::updateAbsolutePosition()
{
ILightSceneNode::updateAbsolutePosition();
doLightRecalc();
}
//! Writes attributes of the scene node.
void CLightSceneNode::serializeAttributes(io::IAttributes* out, io::SAttributeReadWriteOptions* options) const
{
ILightSceneNode::serializeAttributes(out, options);
out->addColorf ("AmbientColor", LightData.AmbientColor);
out->addColorf ("DiffuseColor", LightData.DiffuseColor);
out->addColorf ("SpecularColor", LightData.SpecularColor);
out->addVector3d("Attenuation", LightData.Attenuation);
out->addFloat ("Radius", LightData.Radius);
out->addFloat ("OuterCone", LightData.OuterCone);
out->addFloat ("InnerCone", LightData.InnerCone);
out->addFloat ("Falloff", LightData.Falloff);
out->addBool ("CastShadows", LightData.CastShadows);
out->addEnum ("LightType", LightData.Type, video::LightTypeNames);
}
//! Reads attributes of the scene node.
void CLightSceneNode::deserializeAttributes(io::IAttributes* in, io::SAttributeReadWriteOptions* options)
{
LightData.AmbientColor = in->getAttributeAsColorf("AmbientColor");
LightData.DiffuseColor = in->getAttributeAsColorf("DiffuseColor");
LightData.SpecularColor = in->getAttributeAsColorf("SpecularColor");
//TODO: clearify Radius and Linear Attenuation
#if 0
setRadius ( in->getAttributeAsFloat("Radius") );
#else
LightData.Radius = in->getAttributeAsFloat("Radius");
#endif
if (in->existsAttribute("Attenuation")) // might not exist in older files
LightData.Attenuation = in->getAttributeAsVector3d("Attenuation");
if (in->existsAttribute("OuterCone")) // might not exist in older files
LightData.OuterCone = in->getAttributeAsFloat("OuterCone");
if (in->existsAttribute("InnerCone")) // might not exist in older files
LightData.InnerCone = in->getAttributeAsFloat("InnerCone");
if (in->existsAttribute("Falloff")) // might not exist in older files
LightData.Falloff = in->getAttributeAsFloat("Falloff");
LightData.CastShadows = in->getAttributeAsBool("CastShadows");
LightData.Type = (video::E_LIGHT_TYPE)in->getAttributeAsEnumeration("LightType", video::LightTypeNames);
doLightRecalc ();
ILightSceneNode::deserializeAttributes(in, options);
}
//! Creates a clone of this scene node and its children.
ISceneNode* CLightSceneNode::clone(ISceneNode* newParent, ISceneManager* newManager)
{
if (!newParent)
newParent = Parent;
if (!newManager)
newManager = SceneManager;
CLightSceneNode* nb = new CLightSceneNode(newParent,
newManager, ID, RelativeTranslation, LightData.DiffuseColor, LightData.Radius);
nb->cloneMembers(this, newManager);
nb->LightData = LightData;
nb->BBox = BBox;
if ( newParent )
nb->drop();
return nb;
}
} // end namespace scene
} // end namespace irr

View File

@ -1,109 +0,0 @@
// Copyright (C) 2002-2012 Nikolaus Gebhardt
// This file is part of the "Irrlicht Engine".
// For conditions of distribution and use, see copyright notice in irrlicht.h
#ifndef __C_LIGHT_SCENE_NODE_H_INCLUDED__
#define __C_LIGHT_SCENE_NODE_H_INCLUDED__
#include "ILightSceneNode.h"
namespace irr
{
namespace scene
{
//! Scene node which is a dynamic light. You can switch the light on and off by
//! making it visible or not, and let it be animated by ordinary scene node animators.
class CLightSceneNode : public ILightSceneNode
{
public:
//! constructor
CLightSceneNode(ISceneNode* parent, ISceneManager* mgr, s32 id,
const core::vector3df& position, video::SColorf color, f32 range);
//! pre render event
virtual void OnRegisterSceneNode() _IRR_OVERRIDE_;
//! render
virtual void render() _IRR_OVERRIDE_;
//! set node light data from light info
virtual void setLightData(const video::SLight& light) _IRR_OVERRIDE_;
//! \return Returns the light data.
virtual const video::SLight& getLightData() const _IRR_OVERRIDE_;
//! \return Returns the light data.
virtual video::SLight& getLightData() _IRR_OVERRIDE_;
//! Sets if the node should be visible or not.
/** All children of this node won't be visible either, when set
to true.
\param isVisible If the node shall be visible. */
virtual void setVisible(bool isVisible) _IRR_OVERRIDE_;
//! returns the axis aligned bounding box of this node
virtual const core::aabbox3d<f32>& getBoundingBox() const _IRR_OVERRIDE_;
//! Returns type of the scene node
virtual ESCENE_NODE_TYPE getType() const _IRR_OVERRIDE_ { return ESNT_LIGHT; }
//! Writes attributes of the scene node.
virtual void serializeAttributes(io::IAttributes* out, io::SAttributeReadWriteOptions* options=0) const _IRR_OVERRIDE_;
//! Reads attributes of the scene node.
virtual void deserializeAttributes(io::IAttributes* in, io::SAttributeReadWriteOptions* options=0) _IRR_OVERRIDE_;
//! Creates a clone of this scene node and its children.
virtual ISceneNode* clone(ISceneNode* newParent=0, ISceneManager* newManager=0) _IRR_OVERRIDE_;
//! Sets the light's radius of influence.
/** Outside this radius the light won't lighten geometry and cast no
shadows. Setting the radius will also influence the attenuation, setting
it to (0,1/radius,0). If you want to override this behavior, set the
attenuation after the radius.
\param radius The new radius. */
virtual void setRadius(f32 radius) _IRR_OVERRIDE_;
//! Gets the light's radius of influence.
/** \return The current radius. */
virtual f32 getRadius() const _IRR_OVERRIDE_;
//! Sets the light type.
/** \param type The new type. */
virtual void setLightType(video::E_LIGHT_TYPE type) _IRR_OVERRIDE_;
//! Gets the light type.
/** \return The current light type. */
virtual video::E_LIGHT_TYPE getLightType() const _IRR_OVERRIDE_;
//! Sets whether this light casts shadows.
/** Enabling this flag won't automatically cast shadows, the meshes
will still need shadow scene nodes attached. But one can enable or
disable distinct lights for shadow casting for performance reasons.
\param shadow True if this light shall cast shadows. */
virtual void enableCastShadow(bool shadow=true) _IRR_OVERRIDE_;
//! Check whether this light casts shadows.
/** \return True if light would cast shadows, else false. */
virtual bool getCastShadow() const _IRR_OVERRIDE_;
//! Updates the absolute position based on the relative and the parents position
virtual void updateAbsolutePosition() _IRR_OVERRIDE_;
private:
video::SLight LightData;
core::aabbox3d<f32> BBox;
s32 DriverLightIndex;
bool LightIsOn;
void doLightRecalc();
};
} // end namespace scene
} // end namespace irr
#endif

View File

@ -1,363 +0,0 @@
// Copyright (C) 2002-2012 Nikolaus Gebhardt
// This file is part of the "Irrlicht Engine".
// For conditions of distribution and use, see copyright notice in irrlicht.h
#include "IrrCompileConfig.h"
#ifdef _IRR_COMPILE_WITH_MD2_LOADER_
#include "CMD2MeshFileLoader.h"
#include "CAnimatedMeshMD2.h"
#include "os.h"
namespace irr
{
namespace scene
{
// structs needed to load the md2-format
const s32 MD2_MAGIC_NUMBER = 844121161;
const s32 MD2_VERSION = 8;
const s32 MD2_MAX_VERTS = 2048;
// byte-align structures
#include "irrpack.h"
struct SMD2Header
{
s32 magic; // four character code "IDP2"
s32 version; // must be 8
s32 skinWidth; // width of the texture
s32 skinHeight; // height of the texture
s32 frameSize; // size in bytes of an animation frame
s32 numSkins; // number of textures
s32 numVertices; // total number of vertices
s32 numTexcoords; // number of vertices with texture coords
s32 numTriangles; // number of triangles
s32 numGlCommands; // number of opengl commands (triangle strip or triangle fan)
s32 numFrames; // animation keyframe count
s32 offsetSkins; // offset in bytes to 64 character skin names
s32 offsetTexcoords; // offset in bytes to texture coordinate list
s32 offsetTriangles; // offset in bytes to triangle list
s32 offsetFrames; // offset in bytes to frame list
s32 offsetGlCommands;// offset in bytes to opengl commands
s32 offsetEnd; // offset in bytes to end of file
} PACK_STRUCT;
struct SMD2Vertex
{
u8 vertex[3]; // [0] = X, [1] = Z, [2] = Y
u8 lightNormalIndex; // index in the normal table
} PACK_STRUCT;
struct SMD2Frame
{
f32 scale[3]; // first scale the vertex position
f32 translate[3]; // then translate the position
c8 name[16]; // the name of the animation that this key belongs to
SMD2Vertex vertices[1]; // vertex 1 of SMD2Header.numVertices
} PACK_STRUCT;
struct SMD2Triangle
{
u16 vertexIndices[3];
u16 textureIndices[3];
} PACK_STRUCT;
struct SMD2TextureCoordinate
{
s16 s;
s16 t;
} PACK_STRUCT;
struct SMD2GLCommand
{
f32 s, t;
s32 vertexIndex;
} PACK_STRUCT;
// Default alignment
#include "irrunpack.h"
//! Constructor
CMD2MeshFileLoader::CMD2MeshFileLoader()
{
#ifdef _DEBUG
setDebugName("CMD2MeshFileLoader");
#endif
}
//! returns true if the file maybe is able to be loaded by this class
//! based on the file extension (e.g. ".bsp")
bool CMD2MeshFileLoader::isALoadableFileExtension(const io::path& filename) const
{
return core::hasFileExtension ( filename, "md2" );
}
//! creates/loads an animated mesh from the file.
//! \return Pointer to the created mesh. Returns 0 if loading failed.
//! If you no longer need the mesh, you should call IAnimatedMesh::drop().
//! See IReferenceCounted::drop() for more information.
IAnimatedMesh* CMD2MeshFileLoader::createMesh(io::IReadFile* file)
{
IAnimatedMesh* msh = new CAnimatedMeshMD2();
if (msh)
{
if (loadFile(file, (CAnimatedMeshMD2*)msh) )
return msh;
msh->drop();
}
return 0;
}
//! loads an md2 file
bool CMD2MeshFileLoader::loadFile(io::IReadFile* file, CAnimatedMeshMD2* mesh)
{
if (!file)
return false;
SMD2Header header;
file->read(&header, sizeof(SMD2Header));
#ifdef __BIG_ENDIAN__
header.magic = os::Byteswap::byteswap(header.magic);
header.version = os::Byteswap::byteswap(header.version);
header.skinWidth = os::Byteswap::byteswap(header.skinWidth);
header.skinHeight = os::Byteswap::byteswap(header.skinHeight);
header.frameSize = os::Byteswap::byteswap(header.frameSize);
header.numSkins = os::Byteswap::byteswap(header.numSkins);
header.numVertices = os::Byteswap::byteswap(header.numVertices);
header.numTexcoords = os::Byteswap::byteswap(header.numTexcoords);
header.numTriangles = os::Byteswap::byteswap(header.numTriangles);
header.numGlCommands = os::Byteswap::byteswap(header.numGlCommands);
header.numFrames = os::Byteswap::byteswap(header.numFrames);
header.offsetSkins = os::Byteswap::byteswap(header.offsetSkins);
header.offsetTexcoords = os::Byteswap::byteswap(header.offsetTexcoords);
header.offsetTriangles = os::Byteswap::byteswap(header.offsetTriangles);
header.offsetFrames = os::Byteswap::byteswap(header.offsetFrames);
header.offsetGlCommands = os::Byteswap::byteswap(header.offsetGlCommands);
header.offsetEnd = os::Byteswap::byteswap(header.offsetEnd);
#endif
if (header.magic != MD2_MAGIC_NUMBER || header.version != MD2_VERSION)
{
os::Printer::log("MD2 Loader: Wrong file header", file->getFileName(), ELL_WARNING);
return false;
}
//
// prepare mesh and allocate memory
//
mesh->FrameCount = header.numFrames;
// create keyframes
mesh->FrameTransforms.set_used(header.numFrames);
// create vertex arrays for each keyframe
delete [] mesh->FrameList;
mesh->FrameList = new core::array<CAnimatedMeshMD2::SMD2Vert>[header.numFrames];
// allocate space in vertex arrays
s32 i;
for (i=0; i<header.numFrames; ++i)
mesh->FrameList[i].reallocate(header.numVertices);
// allocate interpolation buffer vertices
mesh->InterpolationBuffer->Vertices.set_used(header.numTriangles*3);
// populate triangles
mesh->InterpolationBuffer->Indices.reallocate(header.numTriangles*3);
const s32 count = header.numTriangles*3;
for (i=0; i<count; i+=3)
{
mesh->InterpolationBuffer->Indices.push_back(i);
mesh->InterpolationBuffer->Indices.push_back(i+1);
mesh->InterpolationBuffer->Indices.push_back(i+2);
}
//
// read texture coordinates
//
file->seek(header.offsetTexcoords);
SMD2TextureCoordinate* textureCoords = new SMD2TextureCoordinate[header.numTexcoords];
if (!file->read(textureCoords, sizeof(SMD2TextureCoordinate)*header.numTexcoords))
{
delete[] textureCoords;
os::Printer::log("MD2 Loader: Error reading TextureCoords.", file->getFileName(), ELL_ERROR);
return false;
}
#ifdef __BIG_ENDIAN__
for (i=0; i<header.numTexcoords; ++i)
{
textureCoords[i].s = os::Byteswap::byteswap(textureCoords[i].s);
textureCoords[i].t = os::Byteswap::byteswap(textureCoords[i].t);
}
#endif
// read Triangles
file->seek(header.offsetTriangles);
SMD2Triangle *triangles = new SMD2Triangle[header.numTriangles];
if (!file->read(triangles, header.numTriangles *sizeof(SMD2Triangle)))
{
delete[] triangles;
delete[] textureCoords;
os::Printer::log("MD2 Loader: Error reading triangles.", file->getFileName(), ELL_ERROR);
return false;
}
#ifdef __BIG_ENDIAN__
for (i=0; i<header.numTriangles; ++i)
{
triangles[i].vertexIndices[0] = os::Byteswap::byteswap(triangles[i].vertexIndices[0]);
triangles[i].vertexIndices[1] = os::Byteswap::byteswap(triangles[i].vertexIndices[1]);
triangles[i].vertexIndices[2] = os::Byteswap::byteswap(triangles[i].vertexIndices[2]);
triangles[i].textureIndices[0] = os::Byteswap::byteswap(triangles[i].textureIndices[0]);
triangles[i].textureIndices[1] = os::Byteswap::byteswap(triangles[i].textureIndices[1]);
triangles[i].textureIndices[2] = os::Byteswap::byteswap(triangles[i].textureIndices[2]);
}
#endif
// read Vertices
u8 buffer[MD2_MAX_VERTS*4+128];
SMD2Frame* frame = (SMD2Frame*)buffer;
file->seek(header.offsetFrames);
for (i = 0; i<header.numFrames; ++i)
{
// read vertices
file->read(frame, header.frameSize);
#ifdef __BIG_ENDIAN__
frame->scale[0] = os::Byteswap::byteswap(frame->scale[0]);
frame->scale[1] = os::Byteswap::byteswap(frame->scale[1]);
frame->scale[2] = os::Byteswap::byteswap(frame->scale[2]);
frame->translate[0] = os::Byteswap::byteswap(frame->translate[0]);
frame->translate[1] = os::Byteswap::byteswap(frame->translate[1]);
frame->translate[2] = os::Byteswap::byteswap(frame->translate[2]);
#endif
//
// store frame data
//
CAnimatedMeshMD2::SAnimationData adata;
adata.begin = i;
adata.end = i;
adata.fps = 7;
// Add new named animation if necessary
if (frame->name[0])
{
// get animation name
for (s32 s = 0; s < 16 && frame->name[s]!=0 && (frame->name[s] < '0' || frame->name[s] > '9'); ++s)
{
adata.name += frame->name[s];
}
// Does this keyframe have the same animation name as the current animation?
if (!mesh->AnimationData.empty() && mesh->AnimationData[mesh->AnimationData.size()-1].name == adata.name)
{
// Increase the length of the animation
++mesh->AnimationData[mesh->AnimationData.size() - 1].end;
}
else
{
// Add the new animation
mesh->AnimationData.push_back(adata);
}
}
// save keyframe scale and translation
mesh->FrameTransforms[i].scale.X = frame->scale[0];
mesh->FrameTransforms[i].scale.Z = frame->scale[1];
mesh->FrameTransforms[i].scale.Y = frame->scale[2];
mesh->FrameTransforms[i].translate.X = frame->translate[0];
mesh->FrameTransforms[i].translate.Z = frame->translate[1];
mesh->FrameTransforms[i].translate.Y = frame->translate[2];
// add vertices
for (s32 j=0; j<header.numTriangles; ++j)
{
for (u32 ti=0; ti<3; ++ti)
{
CAnimatedMeshMD2::SMD2Vert v;
u32 num = triangles[j].vertexIndices[ti];
v.Pos.X = frame->vertices[num].vertex[0];
v.Pos.Z = frame->vertices[num].vertex[1];
v.Pos.Y = frame->vertices[num].vertex[2];
v.NormalIdx = frame->vertices[num].lightNormalIndex;
mesh->FrameList[i].push_back(v);
}
}
// calculate bounding boxes
if (header.numVertices)
{
core::aabbox3d<f32> box;
core::vector3df pos;
pos.X = f32(mesh->FrameList[i] [0].Pos.X) * mesh->FrameTransforms[i].scale.X + mesh->FrameTransforms[i].translate.X;
pos.Y = f32(mesh->FrameList[i] [0].Pos.Y) * mesh->FrameTransforms[i].scale.Y + mesh->FrameTransforms[i].translate.Y;
pos.Z = f32(mesh->FrameList[i] [0].Pos.Z) * mesh->FrameTransforms[i].scale.Z + mesh->FrameTransforms[i].translate.Z;
box.reset(pos);
for (s32 j=1; j<header.numTriangles*3; ++j)
{
pos.X = f32(mesh->FrameList[i] [j].Pos.X) * mesh->FrameTransforms[i].scale.X + mesh->FrameTransforms[i].translate.X;
pos.Y = f32(mesh->FrameList[i] [j].Pos.Y) * mesh->FrameTransforms[i].scale.Y + mesh->FrameTransforms[i].translate.Y;
pos.Z = f32(mesh->FrameList[i] [j].Pos.Z) * mesh->FrameTransforms[i].scale.Z + mesh->FrameTransforms[i].translate.Z;
box.addInternalPoint(pos);
}
mesh->BoxList.push_back(box);
}
}
// populate interpolation buffer with texture coordinates and colors
if (header.numFrames)
{
f32 dmaxs = 1.0f/(header.skinWidth);
f32 dmaxt = 1.0f/(header.skinHeight);
for (s32 t=0; t<header.numTriangles; ++t)
{
for (s32 n=0; n<3; ++n)
{
mesh->InterpolationBuffer->Vertices[t*3 + n].TCoords.X = (textureCoords[triangles[t].textureIndices[n]].s + 0.5f) * dmaxs;
mesh->InterpolationBuffer->Vertices[t*3 + n].TCoords.Y = (textureCoords[triangles[t].textureIndices[n]].t + 0.5f) * dmaxt;
mesh->InterpolationBuffer->Vertices[t*3 + n].Color = video::SColor(255,255,255,255);
}
}
}
// clean up
delete [] triangles;
delete [] textureCoords;
// init buffer with start frame.
mesh->getMesh(0);
return true;
}
} // end namespace scene
} // end namespace irr
#endif // _IRR_COMPILE_WITH_MD2_LOADER_

View File

@ -1,45 +0,0 @@
// Copyright (C) 2002-2012 Nikolaus Gebhardt
// This file is part of the "Irrlicht Engine".
// For conditions of distribution and use, see copyright notice in irrlicht.h
#ifndef __C_MD2_MESH_FILE_LOADER_H_INCLUDED__
#define __C_MD2_MESH_FILE_LOADER_H_INCLUDED__
#include "IMeshLoader.h"
namespace irr
{
namespace scene
{
class CAnimatedMeshMD2;
//! Meshloader capable of loading MD2 files
class CMD2MeshFileLoader : public IMeshLoader
{
public:
//! Constructor
CMD2MeshFileLoader();
//! returns true if the file maybe is able to be loaded by this class
//! based on the file extension (e.g. ".bsp")
virtual bool isALoadableFileExtension(const io::path& filename) const _IRR_OVERRIDE_;
//! creates/loads an animated mesh from the file.
//! \return Pointer to the created mesh. Returns 0 if loading failed.
//! If you no longer need the mesh, you should call IAnimatedMesh::drop().
//! See IReferenceCounted::drop() for more information.
virtual IAnimatedMesh* createMesh(io::IReadFile* file) _IRR_OVERRIDE_;
private:
//! Loads the file data into the mesh
bool loadFile(io::IReadFile* file, CAnimatedMeshMD2* mesh);
};
} // end namespace scene
} // end namespace irr
#endif // __C_MD2_MESH_LOADER_H_INCLUDED__

View File

@ -1,53 +0,0 @@
// Copyright (C) 2002-2012 Nikolaus Gebhardt
// This file is part of the "Irrlicht Engine".
// For conditions of distribution and use, see copyright notice in irrlicht.h
#include "IrrCompileConfig.h"
#ifdef _IRR_COMPILE_WITH_MD3_LOADER_
#include "CMD3MeshFileLoader.h"
#include "CAnimatedMeshMD3.h"
#include "irrString.h"
namespace irr
{
namespace scene
{
//! Constructor
CMD3MeshFileLoader::CMD3MeshFileLoader( scene::ISceneManager* smgr)
: SceneManager(smgr)
{
}
//! destructor
CMD3MeshFileLoader::~CMD3MeshFileLoader()
{
}
//! returns true if the file maybe is able to be loaded by this class
//! based on the file extension (e.g. ".bsp")
bool CMD3MeshFileLoader::isALoadableFileExtension(const io::path& filename) const
{
return core::hasFileExtension ( filename, "md3" );
}
IAnimatedMesh* CMD3MeshFileLoader::createMesh(io::IReadFile* file)
{
CAnimatedMeshMD3 * mesh = new CAnimatedMeshMD3();
if ( mesh->loadModelFile ( 0, file, SceneManager->getFileSystem(), SceneManager->getVideoDriver() ) )
return mesh;
mesh->drop ();
return 0;
}
} // end namespace scene
} // end namespace irr
#endif // _IRR_COMPILE_WITH_MD3_LOADER_

View File

@ -1,49 +0,0 @@
// Copyright (C) 2002-2012 Nikolaus Gebhardt / Thomas Alten
// This file is part of the "Irrlicht Engine".
// For conditions of distribution and use, see copyright notice in irrlicht.h
#ifndef __C_MD3_MESH_FILE_LOADER_H_INCLUDED__
#define __C_MD3_MESH_FILE_LOADER_H_INCLUDED__
#include "IMeshLoader.h"
#include "IFileSystem.h"
#include "IVideoDriver.h"
#include "ISceneManager.h"
#include "IQ3Shader.h"
namespace irr
{
namespace scene
{
//! Meshloader capable of loading md3 files.
class CMD3MeshFileLoader : public IMeshLoader
{
public:
//! Constructor
CMD3MeshFileLoader( scene::ISceneManager* smgr );
//! destructor
virtual ~CMD3MeshFileLoader();
//! returns true if the file maybe is able to be loaded by this class
//! based on the file extension (e.g. ".bsp")
virtual bool isALoadableFileExtension(const io::path& filename) const _IRR_OVERRIDE_;
//! creates/loads an animated mesh from the file.
//! \return Pointer to the created mesh. Returns 0 if loading failed.
//! If you no longer need the mesh, you should call IAnimatedMesh::drop().
//! See IReferenceCounted::drop() for more information.
virtual IAnimatedMesh* createMesh(io::IReadFile* file) _IRR_OVERRIDE_;
private:
scene::ISceneManager* SceneManager;
};
} // end namespace scene
} // end namespace irr
#endif

View File

@ -1,872 +0,0 @@
// Copyright (C) 2002-2012 Nikolaus Gebhardt
// 2019 additional alignment and big_endian fixes by Corto and Salas00
// This file is part of the "Irrlicht Engine".
// For conditions of distribution and use, see copyright notice in irrlicht.h
#include "IrrCompileConfig.h"
#ifdef _IRR_COMPILE_WITH_MS3D_LOADER_
#include "IReadFile.h"
#include "os.h"
#include "CMS3DMeshFileLoader.h"
#include "CSkinnedMesh.h"
namespace irr
{
namespace scene
{
#ifdef _DEBUG
#define _IRR_DEBUG_MS3D_LOADER_
#endif
// byte-align structures
#include "irrpack.h"
namespace {
// File header
struct MS3DHeader
{
char ID[10];
int Version;
} PACK_STRUCT;
// Vertex information
struct MS3DVertex
{
u8 pad1[3];
u8 Flags;
float Vertex[3];
char BoneID;
u8 RefCount;
u8 pad2[2];
} PACK_STRUCT;
#define MS3DVERTEX_NUM_PAD_BYTES 5
// Triangle information
struct MS3DTriangle
{
u16 Flags;
u16 VertexIndices[3];
float VertexNormals[3][3];
float S[3], T[3];
u8 SmoothingGroup;
u8 GroupIndex;
u8 pad1[2];
} PACK_STRUCT;
#define MS3DTRIANGLE_NUM_PAD_BYTES 2
// Material information
struct MS3DMaterial
{
char Name[32];
float Ambient[4];
float Diffuse[4];
float Specular[4];
float Emissive[4];
float Shininess; // 0.0f - 128.0f
float Transparency; // 0.0f - 1.0f
u8 Mode; // 0, 1, 2 is unused now
char Texture[128];
char Alphamap[128];
u8 pad1[3];
} PACK_STRUCT;
#define MS3DMATERIAL_NUM_PAD_BYTES 3
// Joint information
struct MS3DJoint
{
u8 pad[3];
u8 Flags;
char Name[32];
char ParentName[32];
float Rotation[3];
float Translation[3];
u16 NumRotationKeyframes;
u16 NumTranslationKeyframes;
} PACK_STRUCT;
#define MS3DJOINT_NUM_PAD_BYTES 3
// Keyframe data
struct MS3DKeyframe
{
float Time;
float Parameter[3];
} PACK_STRUCT;
// vertex weights in 1.8.x
struct MS3DVertexWeights
{
char boneIds[3];
u8 weights[3];
} PACK_STRUCT;
} // end namespace
// Default alignment
#include "irrunpack.h"
// Get float encoded in little endian in way not causing troubles when floats have to be memory aligned.
static inline float get_unaligned_le_float(const u8 *ptr)
{
union {
u8 u[4];
float f;
} tmp;
#ifdef __BIG_ENDIAN__
tmp.u[0] = ptr[3];
tmp.u[1] = ptr[2];
tmp.u[2] = ptr[1];
tmp.u[3] = ptr[0];
#else
tmp.f = *(float*)ptr;
#endif
return tmp.f;
}
struct SGroup
{
core::stringc Name;
core::array<u16> VertexIds;
u16 MaterialIdx;
};
//! Constructor
CMS3DMeshFileLoader::CMS3DMeshFileLoader(video::IVideoDriver *driver)
: Driver(driver), AnimatedMesh(0)
{
#ifdef _DEBUG
setDebugName("CMS3DMeshFileLoader");
#endif
}
//! returns true if the file maybe is able to be loaded by this class
//! based on the file extension (e.g. ".bsp")
bool CMS3DMeshFileLoader::isALoadableFileExtension(const io::path& filename) const
{
return core::hasFileExtension ( filename, "ms3d" );
}
//! creates/loads an animated mesh from the file.
//! \return Pointer to the created mesh. Returns 0 if loading failed.
//! If you no longer need the mesh, you should call IAnimatedMesh::drop().
//! See IReferenceCounted::drop() for more information.
IAnimatedMesh* CMS3DMeshFileLoader::createMesh(io::IReadFile* file)
{
if (!file)
return 0;
AnimatedMesh = new CSkinnedMesh();
if ( load(file) )
{
AnimatedMesh->finalize();
}
else
{
AnimatedMesh->drop();
AnimatedMesh = 0;
}
return AnimatedMesh;
}
//! loads a milkshape file
bool CMS3DMeshFileLoader::load(io::IReadFile* file)
{
if (!file)
return false;
// find file size
const long fileSize = file->getSize();
// read whole file
u8* buffer = new u8[fileSize];
size_t read = file->read(buffer, fileSize);
if (read != (size_t)fileSize)
{
delete [] buffer;
os::Printer::log("Could not read full file. Loading failed", file->getFileName(), ELL_ERROR);
return false;
}
// read header
const u8 *pPtr = (u8*)((void*)buffer);
MS3DHeader *pHeader = (MS3DHeader*)pPtr;
pPtr += sizeof(MS3DHeader);
if ( strncmp( pHeader->ID, "MS3D000000", 10 ) != 0 )
{
delete [] buffer;
os::Printer::log("Not a valid Milkshape3D Model File. Loading failed", file->getFileName(), ELL_ERROR);
return false;
}
#ifdef __BIG_ENDIAN__
pHeader->Version = os::Byteswap::byteswap(pHeader->Version);
#endif
if ( pHeader->Version < 3 || pHeader->Version > 4 )
{
delete [] buffer;
os::Printer::log("Only Milkshape3D version 3 and 4 (1.3 to 1.8) is supported. Loading failed", file->getFileName(), ELL_ERROR);
return false;
}
#ifdef _IRR_DEBUG_MS3D_LOADER_
os::Printer::log("Loaded header version", core::stringc(pHeader->Version).c_str());
#endif
// get pointers to data
// vertices
u16 numVertices = *(u16*)pPtr;
#ifdef __BIG_ENDIAN__
numVertices = os::Byteswap::byteswap(numVertices);
#endif
#ifdef _IRR_DEBUG_MS3D_LOADER_
os::Printer::log("Load vertices", core::stringc(numVertices).c_str());
#endif
pPtr += sizeof(u16);
MS3DVertex *vertices = new MS3DVertex[numVertices];
if (pPtr + ((sizeof(MS3DVertex) - MS3DVERTEX_NUM_PAD_BYTES) * numVertices) > buffer+fileSize)
{
delete [] buffer;
os::Printer::log("Loading failed. Corrupted data found.", file->getFileName(), ELL_ERROR);
return false;
}
for (u16 tmp=0; tmp<numVertices; ++tmp)
{
//printf("&vertices[tmp].Vertex[0] = %p (%d)\n", &vertices[tmp].Vertex[0], (int)((long long)(&vertices[tmp].Vertex[0]) % 4));
memcpy(&vertices[tmp].Flags, pPtr, sizeof(struct MS3DVertex) - MS3DVERTEX_NUM_PAD_BYTES);
#ifdef __BIG_ENDIAN__
vertices[tmp].Vertex[0] = os::Byteswap::byteswap(vertices[tmp].Vertex[0]);
vertices[tmp].Vertex[1] = os::Byteswap::byteswap(vertices[tmp].Vertex[1]);
vertices[tmp].Vertex[2] = -os::Byteswap::byteswap(vertices[tmp].Vertex[2]);
#else
vertices[tmp].Vertex[2] = -vertices[tmp].Vertex[2];
#endif
// Go to the next vertex structure
pPtr += sizeof(struct MS3DVertex) - MS3DVERTEX_NUM_PAD_BYTES;
}
// triangles
u16 numTriangles = *(u16*)pPtr;
#ifdef __BIG_ENDIAN__
numTriangles = os::Byteswap::byteswap(numTriangles);
#endif
#ifdef _IRR_DEBUG_MS3D_LOADER_
os::Printer::log("Load Triangles", core::stringc(numTriangles).c_str());
#endif
pPtr += sizeof(u16);
MS3DTriangle *triangles = new MS3DTriangle[numTriangles];
if (pPtr + ((sizeof(MS3DTriangle) - MS3DTRIANGLE_NUM_PAD_BYTES) * numTriangles) > buffer+fileSize)
{
delete [] buffer;
os::Printer::log("Loading failed. Corrupted data found.", file->getFileName(), ELL_ERROR);
return false;
}
for (u16 tmp=0; tmp<numTriangles; ++tmp)
{
memcpy(&triangles[tmp].Flags, pPtr, sizeof(struct MS3DTriangle) - MS3DTRIANGLE_NUM_PAD_BYTES);
#ifdef __BIG_ENDIAN__
triangles[tmp].Flags = os::Byteswap::byteswap(triangles[tmp].Flags);
for (u16 j=0; j<3; ++j)
{
triangles[tmp].VertexIndices[j] = os::Byteswap::byteswap(triangles[tmp].VertexIndices[j]);
triangles[tmp].VertexNormals[j][0] = os::Byteswap::byteswap(triangles[tmp].VertexNormals[j][0]);
triangles[tmp].VertexNormals[j][1] = os::Byteswap::byteswap(triangles[tmp].VertexNormals[j][1]);
triangles[tmp].VertexNormals[j][2] = -os::Byteswap::byteswap(triangles[tmp].VertexNormals[j][2]);
triangles[tmp].S[j] = os::Byteswap::byteswap(triangles[tmp].S[j]);
triangles[tmp].T[j] = os::Byteswap::byteswap(triangles[tmp].T[j]);
}
#else
triangles[tmp].VertexNormals[0][2] = -triangles[tmp].VertexNormals[0][2];
triangles[tmp].VertexNormals[1][2] = -triangles[tmp].VertexNormals[1][2];
triangles[tmp].VertexNormals[2][2] = -triangles[tmp].VertexNormals[2][2];
#endif
// Go to the next triangle structure
pPtr += sizeof(struct MS3DTriangle) - MS3DTRIANGLE_NUM_PAD_BYTES;
}
// groups
u16 numGroups = *(u16*)pPtr;
#ifdef __BIG_ENDIAN__
numGroups = os::Byteswap::byteswap(numGroups);
#endif
#ifdef _IRR_DEBUG_MS3D_LOADER_
os::Printer::log("Load Groups", core::stringc(numGroups).c_str());
#endif
pPtr += sizeof(u16);
core::array<SGroup> groups;
groups.reallocate(numGroups);
//store groups
u32 i;
for (i=0; i<numGroups; ++i)
{
groups.push_back(SGroup());
SGroup& grp = groups.getLast();
// The byte flag is before the name, so add 1
grp.Name = ((const c8*) pPtr) + 1;
pPtr += 33; // name and 1 byte flags
u16 triangleCount = *(u16*)pPtr;
#ifdef __BIG_ENDIAN__
triangleCount = os::Byteswap::byteswap(triangleCount);
#endif
pPtr += sizeof(u16);
grp.VertexIds.reallocate(triangleCount);
//pPtr += sizeof(u16) * triangleCount; // triangle indices
for (u16 j=0; j<triangleCount; ++j)
{
#ifdef __BIG_ENDIAN__
grp.VertexIds.push_back(os::Byteswap::byteswap(*(u16*)pPtr));
#else
grp.VertexIds.push_back(*(u16*)pPtr);
#endif
pPtr += sizeof (u16);
}
grp.MaterialIdx = *(u8*)pPtr;
if (grp.MaterialIdx == 255)
grp.MaterialIdx = 0;
pPtr += sizeof(c8); // material index
if (pPtr > buffer+fileSize)
{
delete [] buffer;
os::Printer::log("Loading failed. Corrupted data found.", file->getFileName(), ELL_ERROR);
return false;
}
}
// load materials
u16 numMaterials = *(u16*)pPtr;
#ifdef __BIG_ENDIAN__
numMaterials = os::Byteswap::byteswap(numMaterials);
#endif
#ifdef _IRR_DEBUG_MS3D_LOADER_
os::Printer::log("Load Materials", core::stringc(numMaterials).c_str());
#endif
pPtr += sizeof(u16);
if(numMaterials == 0)
{
// if there are no materials, add at least one buffer
AnimatedMesh->addMeshBuffer();
}
MS3DMaterial *material = new MS3DMaterial;
for (i=0; i<numMaterials; ++i)
{
memcpy(material, pPtr, sizeof(struct MS3DMaterial) - MS3DMATERIAL_NUM_PAD_BYTES);
#ifdef __BIG_ENDIAN__
for (u16 j=0; j<4; ++j)
material->Ambient[j] = os::Byteswap::byteswap(material->Ambient[j]);
for (u16 j=0; j<4; ++j)
material->Diffuse[j] = os::Byteswap::byteswap(material->Diffuse[j]);
for (u16 j=0; j<4; ++j)
material->Specular[j] = os::Byteswap::byteswap(material->Specular[j]);
for (u16 j=0; j<4; ++j)
material->Emissive[j] = os::Byteswap::byteswap(material->Emissive[j]);
material->Shininess = os::Byteswap::byteswap(material->Shininess);
material->Transparency = os::Byteswap::byteswap(material->Transparency);
#endif
pPtr += (sizeof(MS3DMaterial) - MS3DMATERIAL_NUM_PAD_BYTES);
if (pPtr > buffer+fileSize)
{
delete [] buffer;
os::Printer::log("Loading failed. Corrupted data found.", file->getFileName(), ELL_ERROR);
return false;
}
scene::SSkinMeshBuffer *tmpBuffer = AnimatedMesh->addMeshBuffer();
tmpBuffer->Material.MaterialType = video::EMT_SOLID;
tmpBuffer->Material.AmbientColor = video::SColorf(material->Ambient[0], material->Ambient[1], material->Ambient[2], material->Ambient[3]).toSColor ();
tmpBuffer->Material.DiffuseColor = video::SColorf(material->Diffuse[0], material->Diffuse[1], material->Diffuse[2], material->Diffuse[3]).toSColor ();
tmpBuffer->Material.EmissiveColor = video::SColorf(material->Emissive[0], material->Emissive[1], material->Emissive[2], material->Emissive[3]).toSColor ();
tmpBuffer->Material.SpecularColor = video::SColorf(material->Specular[0], material->Specular[1], material->Specular[2], material->Specular[3]).toSColor ();
tmpBuffer->Material.Shininess = material->Shininess;
core::stringc TexturePath(material->Texture);
if (TexturePath.trim()!="")
{
TexturePath=stripPathFromString(file->getFileName(),true) + stripPathFromString(TexturePath,false);
tmpBuffer->Material.setTexture(0, Driver->getTexture(TexturePath));
}
core::stringc AlphamapPath=(const c8*)material->Alphamap;
if (AlphamapPath.trim()!="")
{
AlphamapPath=stripPathFromString(file->getFileName(),true) + stripPathFromString(AlphamapPath,false);
tmpBuffer->Material.setTexture(2, Driver->getTexture(AlphamapPath));
}
}
delete material;
// animation time
f32 framesPerSecond = get_unaligned_le_float(pPtr);
#ifdef _IRR_DEBUG_MS3D_LOADER_
os::Printer::log("FPS", core::stringc(framesPerSecond).c_str());
#endif
pPtr += sizeof(float) * 2; // fps and current time
if (framesPerSecond<1.f)
framesPerSecond=1.f;
AnimatedMesh->setAnimationSpeed(framesPerSecond);
// ignore, calculated inside SkinnedMesh
// s32 frameCount = *(int*)pPtr;
#ifdef __BIG_ENDIAN__
// frameCount = os::Byteswap::byteswap(frameCount);
#endif
pPtr += sizeof(int);
u16 jointCount = *(u16*)pPtr;
#ifdef __BIG_ENDIAN__
jointCount = os::Byteswap::byteswap(jointCount);
#endif
#ifdef _IRR_DEBUG_MS3D_LOADER_
os::Printer::log("Joints", core::stringc(jointCount).c_str());
#endif
pPtr += sizeof(u16);
if (pPtr > buffer+fileSize)
{
delete [] buffer;
os::Printer::log("Loading failed. Corrupted data found.", file->getFileName(), ELL_ERROR);
return false;
}
core::array<core::stringc> parentNames;
parentNames.reallocate(jointCount);
// load joints
for (i=0; i<jointCount; ++i)
{
u32 j;
MS3DJoint *pJoint = new MS3DJoint;
//printf("&pJoint->Rotation[0] = %p (%d)\n", &pJoint->Rotation[0], (int)((long long)(&pJoint->Rotation[0]) % 4));
memcpy(&pJoint->Flags, pPtr, sizeof(MS3DJoint) - MS3DJOINT_NUM_PAD_BYTES);
#ifdef __BIG_ENDIAN__
for (j=0; j<3; ++j)
pJoint->Rotation[j] = os::Byteswap::byteswap(pJoint->Rotation[j]);
for (j=0; j<3; ++j)
pJoint->Translation[j] = os::Byteswap::byteswap(pJoint->Translation[j]);
pJoint->NumRotationKeyframes= os::Byteswap::byteswap(pJoint->NumRotationKeyframes);
pJoint->NumTranslationKeyframes = os::Byteswap::byteswap(pJoint->NumTranslationKeyframes);
#endif
pPtr = pPtr + sizeof(MS3DJoint) - MS3DJOINT_NUM_PAD_BYTES;
if (pPtr > buffer+fileSize)
{
delete [] buffer;
os::Printer::log("Loading failed. Corrupted data found.", file->getFileName(), ELL_ERROR);
return false;
}
ISkinnedMesh::SJoint *jnt = AnimatedMesh->addJoint();
jnt->Name = pJoint->Name;
#ifdef _IRR_DEBUG_MS3D_LOADER_
os::Printer::log("Joint", jnt->Name.c_str());
os::Printer::log("Rotation keyframes", core::stringc(pJoint->NumRotationKeyframes).c_str());
os::Printer::log("Translation keyframes", core::stringc(pJoint->NumTranslationKeyframes).c_str());
#endif
jnt->LocalMatrix.makeIdentity();
jnt->LocalMatrix.setRotationRadians(
core::vector3df(pJoint->Rotation[0], pJoint->Rotation[1], pJoint->Rotation[2]) );
// convert right-handed to left-handed
jnt->LocalMatrix[2]=-jnt->LocalMatrix[2];
jnt->LocalMatrix[6]=-jnt->LocalMatrix[6];
jnt->LocalMatrix[8]=-jnt->LocalMatrix[8];
jnt->LocalMatrix[9]=-jnt->LocalMatrix[9];
jnt->LocalMatrix.setTranslation(
core::vector3df(pJoint->Translation[0], pJoint->Translation[1], -pJoint->Translation[2]) );
jnt->Animatedposition.set(jnt->LocalMatrix.getTranslation());
jnt->Animatedrotation.set(jnt->LocalMatrix.getRotationDegrees());
parentNames.push_back( (c8*)pJoint->ParentName );
/*if (pJoint->NumRotationKeyframes ||
pJoint->NumTranslationKeyframes)
HasAnimation = true;
*/
MS3DKeyframe* kf = new MS3DKeyframe;
// get rotation keyframes
const u16 numRotationKeyframes = pJoint->NumRotationKeyframes;
for (j=0; j < numRotationKeyframes; ++j)
{
memcpy(kf, pPtr, sizeof(MS3DKeyframe));
//printf("rotation kf = %p (%d)\n", kf, (int)((long long)kf % 4));
#ifdef __BIG_ENDIAN__
kf->Time = os::Byteswap::byteswap(kf->Time);
for (u32 l=0; l<3; ++l)
kf->Parameter[l] = os::Byteswap::byteswap(kf->Parameter[l]);
#endif
pPtr += sizeof(MS3DKeyframe);
if (pPtr > buffer+fileSize)
{
delete [] buffer;
os::Printer::log("Loading failed. Corrupted data found.", file->getFileName(), ELL_ERROR);
return false;
}
ISkinnedMesh::SRotationKey *k=AnimatedMesh->addRotationKey(jnt);
k->frame = kf->Time * framesPerSecond-1;
core::matrix4 tmpMatrix;
tmpMatrix.setRotationRadians(
core::vector3df(kf->Parameter[0], kf->Parameter[1], kf->Parameter[2]) );
// convert right-handed to left-handed
tmpMatrix[2]=-tmpMatrix[2];
tmpMatrix[6]=-tmpMatrix[6];
tmpMatrix[8]=-tmpMatrix[8];
tmpMatrix[9]=-tmpMatrix[9];
tmpMatrix=jnt->LocalMatrix*tmpMatrix;
// IRR_TEST_BROKEN_QUATERNION_USE: TODO - switched from tmpMatrix to tmpMatrix.getTransposed() for downward compatibility.
// Not tested so far if this was correct or wrong before quaternion fix!
k->rotation = core::quaternion(tmpMatrix.getTransposed());
}
// get translation keyframes
const u16 numTranslationKeyframes = pJoint->NumTranslationKeyframes;
for (j=0; j<numTranslationKeyframes; ++j)
{
memcpy(kf, pPtr, sizeof(MS3DKeyframe));
//printf("translation kf = %p (%d)\n", kf, (int)((long long)kf % 4));
#ifdef __BIG_ENDIAN__
kf->Time = os::Byteswap::byteswap(kf->Time);
for (u32 l=0; l<3; ++l)
kf->Parameter[l] = os::Byteswap::byteswap(kf->Parameter[l]);
#endif
pPtr += sizeof(MS3DKeyframe);
if (pPtr > buffer+fileSize)
{
delete [] buffer;
os::Printer::log("Loading failed. Corrupted data found.", file->getFileName(), ELL_ERROR);
return false;
}
ISkinnedMesh::SPositionKey *k=AnimatedMesh->addPositionKey(jnt);
k->frame = kf->Time * framesPerSecond-1;
k->position = core::vector3df
(kf->Parameter[0]+pJoint->Translation[0],
kf->Parameter[1]+pJoint->Translation[1],
-kf->Parameter[2]-pJoint->Translation[2]);
}
delete kf;
delete pJoint;
}
core::array<MS3DVertexWeights> vertexWeights;
f32 weightFactor=0;
if (jointCount && (pHeader->Version == 4) && (pPtr < buffer+fileSize))
{
s32 subVersion = *(s32*)pPtr; // comment subVersion, always 1
#ifdef __BIG_ENDIAN__
subVersion = os::Byteswap::byteswap(subVersion);
#endif
pPtr += sizeof(s32);
for (u32 j=0; j<4; ++j) // four comment groups
{
#ifdef _IRR_DEBUG_MS3D_LOADER_
os::Printer::log("Skipping comment group", core::stringc(j+1).c_str());
#endif
u32 numComments = *(u32*)pPtr;
#ifdef __BIG_ENDIAN__
numComments = os::Byteswap::byteswap(numComments);
#endif
pPtr += sizeof(u32);
for (i=0; i<numComments; ++i)
{
// according to scorpiomidget this field does
// not exist for model comments. So avoid to
// read it
if (j!=3)
pPtr += sizeof(s32); // index
s32 commentLength = *(s32*)pPtr;
#ifdef __BIG_ENDIAN__
commentLength = os::Byteswap::byteswap(commentLength);
#endif
pPtr += sizeof(s32);
pPtr += commentLength;
}
if (pPtr > buffer+fileSize)
{
delete [] buffer;
os::Printer::log("Loading failed. Corrupted data found.", file->getFileName(), ELL_ERROR);
return false;
}
}
if (pPtr < buffer+fileSize)
{
subVersion = *(s32*)pPtr; // vertex subVersion, 1 or 2
#ifdef __BIG_ENDIAN__
subVersion = os::Byteswap::byteswap(subVersion);
#endif
if (subVersion==1)
weightFactor=1.f/255.f;
else
weightFactor=1.f/100.f;
pPtr += sizeof(s32);
#ifdef _IRR_DEBUG_MS3D_LOADER_
os::Printer::log("Reading vertex weights");
#endif
// read vertex weights, ignoring data 'extra' from 1.8.2
vertexWeights.reallocate(numVertices);
const char offset = (subVersion==1)?6:10;
for (i=0; i<numVertices; ++i)
{
vertexWeights.push_back(*(MS3DVertexWeights*)pPtr);
pPtr += offset;
}
if (pPtr > buffer+fileSize)
{
delete [] buffer;
os::Printer::log("Loading failed. Corrupted data found.", file->getFileName(), ELL_ERROR);
return false;
}
}
if (pPtr < buffer+fileSize)
{
subVersion = *(s32*)pPtr; // joint subVersion, 1 or 2
#ifdef __BIG_ENDIAN__
subVersion = os::Byteswap::byteswap(subVersion);
#endif
pPtr += sizeof(s32);
// skip joint colors
#ifdef _IRR_DEBUG_MS3D_LOADER_
os::Printer::log("Skip joint color");
#endif
pPtr += 3*sizeof(float)*jointCount;
if (pPtr > buffer+fileSize)
{
delete [] buffer;
os::Printer::log("Loading failed. Corrupted data found", file->getFileName(), ELL_ERROR);
return false;
}
}
if (pPtr < buffer+fileSize)
{
subVersion = *(s32*)pPtr; // model subVersion, 1 or 2
#ifdef __BIG_ENDIAN__
subVersion = os::Byteswap::byteswap(subVersion);
#endif
pPtr += sizeof(s32);
#ifdef _IRR_DEBUG_MS3D_LOADER_
os::Printer::log("Skip model extra information");
#endif
// now the model extra information would follow
// we also skip this for now
}
}
//find parent of every joint
for (u32 jointnum=0; jointnum<AnimatedMesh->getAllJoints().size(); ++jointnum)
{
for (u32 j2=0; j2<AnimatedMesh->getAllJoints().size(); ++j2)
{
if (jointnum != j2 && parentNames[jointnum] == AnimatedMesh->getAllJoints()[j2]->Name )
{
AnimatedMesh->getAllJoints()[j2]->Children.push_back(AnimatedMesh->getAllJoints()[jointnum]);
break;
}
}
}
// create vertices and indices, attach them to the joints.
video::S3DVertex v;
core::array<video::S3DVertex> *Vertices;
core::array<u16> Indices;
for (i=0; i<numTriangles; ++i)
{
u32 tmp = groups[triangles[i].GroupIndex].MaterialIdx;
Vertices = &AnimatedMesh->getMeshBuffers()[tmp]->Vertices_Standard;
for (s32 j = 2; j!=-1; --j)
{
const u32 vertidx = triangles[i].VertexIndices[j];
v.TCoords.X = triangles[i].S[j];
v.TCoords.Y = triangles[i].T[j];
v.Normal.X = triangles[i].VertexNormals[j][0];
v.Normal.Y = triangles[i].VertexNormals[j][1];
v.Normal.Z = triangles[i].VertexNormals[j][2];
if(triangles[i].GroupIndex < groups.size() &&
groups[triangles[i].GroupIndex].MaterialIdx < AnimatedMesh->getMeshBuffers().size())
v.Color = AnimatedMesh->getMeshBuffers()[groups[triangles[i].GroupIndex].MaterialIdx]->Material.DiffuseColor;
else
v.Color.set(255,255,255,255);
v.Pos.X = vertices[vertidx].Vertex[0];
v.Pos.Y = vertices[vertidx].Vertex[1];
v.Pos.Z = vertices[vertidx].Vertex[2];
// check if we already have this vertex in our vertex array
s32 index = -1;
for (u32 iV = 0; iV < Vertices->size(); ++iV)
{
if (v == (*Vertices)[iV])
{
index = (s32)iV;
break;
}
}
if (index == -1)
{
index = Vertices->size();
const u32 matidx = groups[triangles[i].GroupIndex].MaterialIdx;
if (vertexWeights.size()==0)
{
const s32 boneid = vertices[vertidx].BoneID;
if ((u32)boneid < AnimatedMesh->getAllJoints().size())
{
ISkinnedMesh::SWeight *w=AnimatedMesh->addWeight(AnimatedMesh->getAllJoints()[boneid]);
w->buffer_id = matidx;
w->strength = 1.0f;
w->vertex_id = index;
}
}
else if (jointCount) // new weights from 1.8.x
{
f32 sum = 1.0f;
s32 boneid = vertices[vertidx].BoneID;
if (((u32)boneid < AnimatedMesh->getAllJoints().size()) && (vertexWeights[vertidx].weights[0] != 0))
{
ISkinnedMesh::SWeight *w=AnimatedMesh->addWeight(AnimatedMesh->getAllJoints()[boneid]);
w->buffer_id = matidx;
sum -= (w->strength = vertexWeights[vertidx].weights[0]*weightFactor);
w->vertex_id = index;
}
boneid = vertexWeights[vertidx].boneIds[0];
if (((u32)boneid < AnimatedMesh->getAllJoints().size()) && (vertexWeights[vertidx].weights[1] != 0))
{
ISkinnedMesh::SWeight *w=AnimatedMesh->addWeight(AnimatedMesh->getAllJoints()[boneid]);
w->buffer_id = matidx;
sum -= (w->strength = vertexWeights[vertidx].weights[1]*weightFactor);
w->vertex_id = index;
}
boneid = vertexWeights[vertidx].boneIds[1];
if (((u32)boneid < AnimatedMesh->getAllJoints().size()) && (vertexWeights[vertidx].weights[2] != 0))
{
ISkinnedMesh::SWeight *w=AnimatedMesh->addWeight(AnimatedMesh->getAllJoints()[boneid]);
w->buffer_id = matidx;
sum -= (w->strength = vertexWeights[vertidx].weights[2]*weightFactor);
w->vertex_id = index;
}
boneid = vertexWeights[vertidx].boneIds[2];
if (((u32)boneid < AnimatedMesh->getAllJoints().size()) && (sum > 0.f))
{
ISkinnedMesh::SWeight *w=AnimatedMesh->addWeight(AnimatedMesh->getAllJoints()[boneid]);
w->buffer_id = matidx;
w->strength = sum;
w->vertex_id = index;
}
// fallback, if no bone chosen. Seems to be an error in the specs
boneid = vertices[vertidx].BoneID;
if ((sum == 1.f) && ((u32)boneid < AnimatedMesh->getAllJoints().size()))
{
ISkinnedMesh::SWeight *w=AnimatedMesh->addWeight(AnimatedMesh->getAllJoints()[boneid]);
w->buffer_id = matidx;
w->strength = 1.f;
w->vertex_id = index;
}
}
Vertices->push_back(v);
}
Indices.push_back(index);
}
}
//create groups
s32 iIndex = -1;
for (i=0; i<groups.size(); ++i)
{
SGroup& grp = groups[i];
if (grp.MaterialIdx >= AnimatedMesh->getMeshBuffers().size())
grp.MaterialIdx = 0;
core::array<u16>& indices = AnimatedMesh->getMeshBuffers()[grp.MaterialIdx]->Indices;
for (u32 k=0; k < grp.VertexIds.size(); ++k)
for (u32 l=0; l<3; ++l)
indices.push_back(Indices[++iIndex]);
}
delete [] buffer;
delete [] triangles;
delete [] vertices;
return true;
}
core::stringc CMS3DMeshFileLoader::stripPathFromString(const core::stringc& inString, bool returnPath) const
{
s32 slashIndex=inString.findLast('/'); // forward slash
s32 backSlash=inString.findLast('\\'); // back slash
if (backSlash>slashIndex) slashIndex=backSlash;
if (slashIndex==-1)//no slashes found
{
if (returnPath)
return core::stringc(); //no path to return
else
return inString;
}
if (returnPath)
return inString.subString(0, slashIndex + 1);
else
return inString.subString(slashIndex+1, inString.size() - (slashIndex+1));
}
} // end namespace scene
} // end namespace irr
#endif

View File

@ -1,49 +0,0 @@
// Copyright (C) 2002-2012 Nikolaus Gebhardt
// This file is part of the "Irrlicht Engine".
// For conditions of distribution and use, see copyright notice in irrlicht.h
#ifndef __C_MS3D_MESH_FILE_LOADER_H_INCLUDED__
#define __C_MS3D_MESH_FILE_LOADER_H_INCLUDED__
#include "IMeshLoader.h"
#include "IVideoDriver.h"
#include "CSkinnedMesh.h"
namespace irr
{
namespace scene
{
//! Meshloader capable of loading Milkshape 3D files
class CMS3DMeshFileLoader : public IMeshLoader
{
public:
//! Constructor
CMS3DMeshFileLoader(video::IVideoDriver* driver);
//! returns true if the file might be loadable by this class
//! based on the file extension (e.g. ".bsp")
virtual bool isALoadableFileExtension(const io::path& filename) const _IRR_OVERRIDE_;
//! creates/loads an animated mesh from the file.
//! \return Pointer to the created mesh. Returns 0 if loading failed.
//! If you no longer need the mesh, you should call IAnimatedMesh::drop().
//! See IReferenceCounted::drop() for more information.
virtual IAnimatedMesh* createMesh(io::IReadFile* file) _IRR_OVERRIDE_;
private:
core::stringc stripPathFromString(const core::stringc& inString, bool returnPath) const;
bool load(io::IReadFile* file);
video::IVideoDriver* Driver;
CSkinnedMesh* AnimatedMesh;
};
} // end namespace scene
} // end namespace irr
#endif

View File

@ -1,445 +0,0 @@
// Copyright (C) 2002-2012 Nikolaus Gebhardt
// This file is part of the "Irrlicht Engine".
// For conditions of distribution and use, see copyright notice in irrlicht.h
//
// This file was originally written by ZDimitor.
//----------------------------------------------------------------------
// somefuncs.h - part of the My3D Tools
//
// This tool was created by Zhuck Dmitry (ZDimitor).
// Everyone can use it as wants ( i'll be happy if it helps to someone :) ).
//----------------------------------------------------------------------
//**********************************************************************
// some useful functions
//**********************************************************************
#ifndef __C_MY3D_HELPER_H_INCLUDED__
#define __C_MY3D_HELPER_H_INCLUDED__
#include "irrTypes.h"
namespace irr
{
namespace scene
{
//**********************************************************************
// MY3D stuff
//**********************************************************************
// byte-align structures
#include "irrpack.h"
struct SMyVector3
{ SMyVector3 () {;}
SMyVector3 (f32 __X, f32 __Y, f32 __Z)
: X(__X), Y(__Y), Z(__Z) {}
f32 X, Y, Z;
} PACK_STRUCT;
struct SMyVector2
{ SMyVector2 () {;}
SMyVector2(f32 __X, f32 __Y)
: X(__X), Y(__Y) {}
f32 X, Y;
} PACK_STRUCT;
struct SMyVertex
{ SMyVertex () {;}
SMyVertex (SMyVector3 _Coord, SMyColor _Color, SMyVector3 _Normal)
:Coord(_Coord), Color(_Color), Normal(_Normal) {;}
SMyVector3 Coord;
SMyColor Color;
SMyVector3 Normal;
} PACK_STRUCT;
struct SMyTVertex
{ SMyTVertex () {;}
SMyTVertex (SMyVector2 _TCoord)
: TCoord(_TCoord) {;}
SMyVector2 TCoord;
} PACK_STRUCT;
struct SMyFace
{ SMyFace() {;}
SMyFace(u32 __A, u32 __B, u32 __C)
: A(__A), B(__B), C(__C) {}
u32 A, B, C;
} PACK_STRUCT;
// file header (6 bytes)
struct SMyFileHeader
{ u32 MyId; // MY3D
u16 Ver; // Version
} PACK_STRUCT;
// scene header
struct SMySceneHeader
{ SMyColor BackgrColor; // background color
SMyColor AmbientColor; // ambient color
s32 MaterialCount; // material count
s32 MeshCount; // mesh count
} PACK_STRUCT;
// mesh header
struct SMyMeshHeader
{ c8 Name[256]; // material name
u32 MatIndex; // index of the mesh material
u32 TChannelCnt; // mesh mapping channels count
} PACK_STRUCT;
// texture data header
struct SMyTexDataHeader
{ c8 Name[256]; // texture name
u32 ComprMode; //compression mode
u32 PixelFormat;
u32 Width; // image width
u32 Height; // image height
} PACK_STRUCT;
// pixel color 24bit (R8G8B8)
struct SMyPixelColor24
{ SMyPixelColor24() {;}
SMyPixelColor24(u8 __r, u8 __g, u8 __b)
: r(__r), g(__g), b(__b) {}
u8 r, g, b;
} PACK_STRUCT;
// pixel color 16bit (A1R5G5B5)
struct SMyPixelColor16
{ SMyPixelColor16() {;}
SMyPixelColor16(s16 _argb): argb(_argb) {;}
SMyPixelColor16(u8 r, u8 g, u8 b)
{ argb = ((r&0x1F)<<10) | ((g&0x1F)<<5) | (b&0x1F);
}
s16 argb;
} PACK_STRUCT;
// RLE Header
struct SMyRLEHeader
{ SMyRLEHeader() {}
u32 nEncodedBytes;
u32 nDecodedBytes;
} PACK_STRUCT;
// Default alignment
#include "irrunpack.h"
} // end namespace
} // end namespace
//-----------------------------------------------------------------------------
namespace irr
{
namespace core
{
//-----------------RLE stuff-----------------------------------------
int rle_encode (
unsigned char *in_buf, int in_buf_size,
unsigned char *out_buf, int out_buf_size
);
unsigned long process_comp(
unsigned char *buf, int buf_size,
unsigned char *out_buf, int out_buf_size
);
void process_uncomp(
unsigned char, unsigned char *out_buf, int out_buf_size
);
void flush_outbuf(
unsigned char *out_buf, int out_buf_size
);
unsigned long get_byte (
unsigned char *ch,
unsigned char *in_buf, int in_buf_size,
unsigned char *out_buf, int out_buf_size
);
void put_byte(
unsigned char ch, unsigned char *out_buf, int out_buf_size
);
//-----------------------------------------------------------
const unsigned long LIMIT = 1; // was #define LIMIT 1
const unsigned long NON_MATCH = 2; // was: #define NON_MATCH 2
const unsigned long EOD_FOUND = 3; // was: #define EOD_FOUND 3
const unsigned long EOD = 0x00454f44; // was: #define EOD 'EOD'
//-----------------------------------------------------------
// number of decoded bytes
static int nDecodedBytes=0;
// number of coded bytes
static int nCodedBytes=0;
// number of read bytes
static int nReadedBytes=0;
// table used to look for sequences of repeating bytes
static unsigned char tmpbuf[4]; // we use subscripts 1 - 3
static int tmpbuf_cnt;
// output buffer for non-compressed output data
static unsigned char outbuf[128];
static int outbuf_cnt;
//-----------------------------------------------------------
int rle_encode (
unsigned char *in_buf, int in_buf_size,
unsigned char *out_buf, int out_buf_size
)
{
unsigned long ret_code;
unsigned char ch=0;
nCodedBytes=0;
nReadedBytes=0;
tmpbuf_cnt = 0; // no. of char's in tmpbuf
outbuf_cnt = 0; // no. of char's in outbuf
while (1)
{
if (get_byte(&ch, in_buf, in_buf_size,
out_buf, out_buf_size) == (int)EOD) // read next byte into ch
break;
tmpbuf[++tmpbuf_cnt] = (unsigned char) ch;
if (tmpbuf_cnt == 3)
{
// see if all 3 match each other
if ((tmpbuf[1] == tmpbuf[2]) && (tmpbuf[2] == tmpbuf[3]))
{
// they do - add compression
// this will process all bytes in input file until
// a non-match occurs, or 128 bytes are processed,
// or we find eod */
ret_code = process_comp(in_buf, in_buf_size, out_buf, out_buf_size);
if (ret_code == (int)EOD_FOUND)
break; // stop compressing
if (ret_code == (int)NON_MATCH)
tmpbuf_cnt=1; /* save the char that didn't match */
else
// we just compressed the max. of 128 bytes
tmpbuf_cnt=0; /* start over for next chunk */
}
else
{
// we know the first byte doesn't match 2 or more
// others, so just send it out as uncompressed. */
process_uncomp(tmpbuf[1], out_buf, out_buf_size);
// see if the last 2 bytes in the buffer match
if (tmpbuf[2] == tmpbuf[3])
{
// move byte 3 to position 1 and pretend we just
// have 2 bytes -- note that the first byte was
// already sent to output */
tmpbuf[1]=tmpbuf[3];
tmpbuf_cnt=2;
}
else
{
// send byte 2 and keep byte 3 - it may match the
// next byte. Move byte 3 to position 1 and set
// count to 1. Note that the first byte was
// already sent to output
process_uncomp(tmpbuf[2], out_buf, out_buf_size);
tmpbuf[1]=tmpbuf[3];
tmpbuf_cnt=1;
}
}
}
} // end while
flush_outbuf(out_buf, out_buf_size);
return nCodedBytes;
}
//------------------------------------------------------------------
// This flushes any non-compressed data not yet sent, then it processes
// repeating bytes until > 128, or EOD, or non-match.
// return values: LIMIT, EOD_FOUND, NON_MATCH
// Prior to ANY return, it writes out the 2 byte compressed code.
// If a NON_MATCH was found, this returns with the non-matching char
// residing in tmpbuf[0].
// Inputs: tmpbuf[0], input file
// Outputs: tmpbuf[0] (sometimes), output file, and return code
//------------------------------------------------------------------
unsigned long process_comp(
unsigned char *buf, int buf_size,
unsigned char *out_buf, int out_buf_size)
{
// we start out with 3 repeating bytes
int len = 3;
unsigned char ch = 0;
// we're starting a repeating chunk - end the non-repeaters
flush_outbuf(out_buf, out_buf_size);
while (get_byte(&ch, buf, buf_size, out_buf, out_buf_size) != (int)EOD)
{
if (ch != tmpbuf[1])
{
// send no. of repeated bytes to be encoded
put_byte((unsigned char)((--len) | 0x80), out_buf, out_buf_size);
// send the byte's value being repeated
put_byte((unsigned char)tmpbuf[1], out_buf, out_buf_size);
/* save the non-matching character just read */
tmpbuf[1]=(unsigned char) ch;
return NON_MATCH;
}
/* we know the new byte is part of the repeating seq */
len++;
if (len == 128)
{
// send no. of repeated bytes to be encoded
put_byte((unsigned char)((--len) | 0x80), out_buf, out_buf_size);
// send the byte's value being repeated
put_byte((unsigned char)tmpbuf[1], out_buf, out_buf_size);
return LIMIT;
}
} // end while
// if flow comes here, we just read an EOD
// send no. of repeated bytes to be encoded
put_byte((unsigned char)((--len) | 0x80), out_buf, out_buf_size);
// send the byte's value being repeated
put_byte((unsigned char)tmpbuf[1], out_buf, out_buf_size);
return EOD_FOUND;
}
//----------------------------------------------------------------
// This adds 1 non-repeating byte to outbuf. If outbuf becomes full
// with 128 bytes, it flushes outbuf.
// There are no return codes and no bytes are read from the input.
//----------------------------------------------------------------
void process_uncomp(
unsigned char char1, unsigned char *out_buf, int out_buf_size
)
{
outbuf[outbuf_cnt++] = char1;
if (outbuf_cnt == 128)
flush_outbuf(out_buf, out_buf_size);
}
//-----------------------------------------------------------
// This flushes any non-compressed data not yet sent.
// On exit, outbuf_cnt will equal zero.
//-----------------------------------------------------------
void flush_outbuf(unsigned char *out_buf, int out_buf_size)
{
if (!outbuf_cnt)
return; // nothing to do */
// send no. of unencoded bytes to be sent
put_byte((unsigned char)(outbuf_cnt - 1), out_buf, out_buf_size);
for (int pos=0; outbuf_cnt; outbuf_cnt--)
put_byte((unsigned char)outbuf[pos++], out_buf, out_buf_size);
}
//---------------------------------------------------
void put_byte(unsigned char b, unsigned char *out_buf, int out_buf_size)
{
if (nCodedBytes<=(out_buf_size-1))
{
out_buf[nCodedBytes++] = b;
out_buf[nCodedBytes] = 0;
}
}
//---------------------------------------------------
// This reads the next byte into ch. It returns EOD
// at end-of-data
//---------------------------------------------------
unsigned long get_byte(
unsigned char *ch,
unsigned char *in_buf, int in_buf_size,
unsigned char *out_buf, int out_buf_size
)
{
if (nReadedBytes>=in_buf_size)
{
// there are either 0, 1, or 2 char's to write before we quit
if (tmpbuf_cnt == 1)
process_uncomp(tmpbuf[1], out_buf, out_buf_size);
else
{
if (tmpbuf_cnt == 2)
{
process_uncomp(tmpbuf[1], out_buf, out_buf_size);
process_uncomp(tmpbuf[2], out_buf, out_buf_size);
}
}
nReadedBytes =0;
return EOD;
}
(*ch) = (unsigned char)in_buf[nReadedBytes++];
return 0;
}
//-----------------------------------------------------------
int rle_decode (
unsigned char *in_buf, int in_buf_size,
unsigned char *out_buf, int out_buf_size
)
{
nDecodedBytes=0;
nReadedBytes=0;
int ch, i;
while (1)
{
if (nReadedBytes>=in_buf_size)
break;
else
ch=in_buf[nReadedBytes];
nReadedBytes++;
if (ch > 127)
{
i = ch - 127; // i is the number of repetitions
// get the byte to be repeated
if (nReadedBytes>=in_buf_size)
break;
else
ch=in_buf[nReadedBytes];
nReadedBytes++;
// uncompress a chunk
for (; i; --i)
{
if (nDecodedBytes<out_buf_size)
out_buf[nDecodedBytes] = ch;
nDecodedBytes++;
}
}
else
{
// copy out some uncompressed bytes
// i is the no. of bytes
for (i = ch + 1; i; --i)
{
if (nReadedBytes>=in_buf_size)
break;
else
ch=in_buf[nReadedBytes];
nReadedBytes++;
if (nDecodedBytes<out_buf_size)
out_buf[nDecodedBytes] = ch;
nDecodedBytes++;
}
}
} // end while
return nDecodedBytes;
}
} //end namespace core
} //end namespace irr
#endif // __C_MY3D_HELPER_H_INCLUDED__

View File

@ -1,886 +0,0 @@
// Copyright (C) 2002-2012 Nikolaus Gebhardt
// This file is part of the "Irrlicht Engine".
// For conditions of distribution and use, see copyright notice in irrlicht.h
//
// This file was originally written by ZDimitor.
//-----------------------------------------------------------------------------
// This tool created by ZDimitor everyone can use it as wants
//-----------------------------------------------------------------------------
#include "IrrCompileConfig.h"
#ifdef _IRR_COMPILE_WITH_MY3D_LOADER_
#include "CMY3DMeshFileLoader.h"
#include "CMeshTextureLoader.h"
#include "SAnimatedMesh.h"
#include "SMeshBuffer.h"
#include "IReadFile.h"
#include "IAttributes.h"
#include "CMY3DHelper.h"
#include "os.h"
// v3.15 - May 16, 2005
namespace irr
{
namespace scene
{
static const u32 MY3D_ID = 0x4d593344;
static const u16 MY3D_VER = 0x0003;
static const u16 MY3D_SCENE_HEADER_ID = 0x1000;
static const u16 MY3D_MAT_LIST_ID = 0x2000;
static const u16 MY3D_MAT_HEADER_ID = 0x2100;
static const u16 MY3D_TEX_FNAME_ID = 0x2101;
static const u16 MY3D_TEXDATA_HEADER_ID = 0x2501;
static const u16 MY3D_TEXDATA_RLE_HEADER_ID = 0x2502;
static const u16 MY3D_MESH_LIST_ID = 0x3000;
static const u16 MY3D_MESH_HEADER_ID = 0x3100;
static const u16 MY3D_VERTS_ID = 0x3101;
static const u16 MY3D_FACES_ID = 0x3102;
static const u16 MY3D_TVERTS_ID = 0x3103;
static const u16 MY3D_TFACES_ID = 0x3104;
static const u16 MY3D_FILE_END_ID = 0xFFFF;
static const unsigned long MY3D_TEXDATA_COMPR_NONE_ID = 0x4e4f4e45;
static const unsigned long MY3D_TEXDATA_COMPR_SIMPLE_ID = 0x53494d50;
static const unsigned long MY3D_TEXDATA_COMPR_RLE_ID = 0x20524c45;
static const unsigned long MY3D_PIXEL_FORMAT_24 = 0x5f32345f;
static const unsigned long MY3D_PIXEL_FORMAT_16 = 0x5f31365f;
CMY3DMeshFileLoader::CMY3DMeshFileLoader(ISceneManager* scmgr, io::IFileSystem* fs)
: SceneManager(scmgr), FileSystem(fs)
{
#ifdef _DEBUG
setDebugName("CMY3DMeshFileLoader");
#endif
if (FileSystem)
FileSystem->grab();
TextureLoader = new CMeshTextureLoader( FileSystem, SceneManager->getVideoDriver() );
}
CMY3DMeshFileLoader::~CMY3DMeshFileLoader()
{
if (FileSystem)
FileSystem->drop();
}
bool CMY3DMeshFileLoader::isALoadableFileExtension(const io::path& filename) const
{
return core::hasFileExtension ( filename, "my3d" );
}
IAnimatedMesh* CMY3DMeshFileLoader::createMesh(io::IReadFile* file)
{
if ( getMeshTextureLoader() )
{
getMeshTextureLoader()->setMeshFile(file);
if ( SceneManager->getParameters()->existsAttribute(MY3D_TEXTURE_PATH) )
getMeshTextureLoader()->setTexturePath(SceneManager->getParameters()->getAttributeAsString(MY3D_TEXTURE_PATH));
}
MaterialEntry.clear();
MeshBufferEntry.clear();
ChildNodes.clear();
// read file into memory
SMyFileHeader fileHeader;
file->read(&fileHeader, sizeof(SMyFileHeader));
#ifdef __BIG_ENDIAN__
fileHeader.MyId = os::Byteswap::byteswap(fileHeader.MyId);
fileHeader.Ver = os::Byteswap::byteswap(fileHeader.Ver);
#endif
if (fileHeader.MyId!=MY3D_ID || fileHeader.Ver!=MY3D_VER)
{
os::Printer::log("Bad MY3D file header, loading failed!", ELL_ERROR);
return 0;
}
u16 id;
file->read(&id, sizeof(id));
#ifdef __BIG_ENDIAN__
id = os::Byteswap::byteswap(id);
#endif
if (id!=MY3D_SCENE_HEADER_ID)
{
os::Printer::log("Cannot find MY3D_SCENE_HEADER_ID, loading failed!", ELL_ERROR);
return 0;
}
SMySceneHeader sceneHeader;
file->read(&sceneHeader, sizeof(SMySceneHeader));
#ifdef __BIG_ENDIAN__
sceneHeader.MaterialCount = os::Byteswap::byteswap(sceneHeader.MaterialCount);
sceneHeader.MeshCount = os::Byteswap::byteswap(sceneHeader.MeshCount);
#endif
file->read(&id, sizeof(id));
#ifdef __BIG_ENDIAN__
id = os::Byteswap::byteswap(id);
#endif
if (id!=MY3D_MAT_LIST_ID)
{
os::Printer::log("Can not find MY3D_MAT_LIST_ID, loading failed!", ELL_ERROR);
return 0;
}
file->read(&id, sizeof(id));
#ifdef __BIG_ENDIAN__
id = os::Byteswap::byteswap(id);
#endif
c8 namebuf[256];
for (s32 m=0; m<sceneHeader.MaterialCount; ++m)
{
if (id != MY3D_MAT_HEADER_ID)
{
os::Printer::log("Cannot find MY3D_MAT_HEADER_ID, loading failed!", ELL_ERROR);
return 0;
}
// read material header
MaterialEntry.push_back(SMyMaterialEntry());
SMyMaterialEntry& me=MaterialEntry.getLast();
file->read(&(me.Header), sizeof(SMyMaterialHeader));
// read next identificator
file->read(&id, sizeof(id));
#ifdef __BIG_ENDIAN__
id = os::Byteswap::byteswap(id);
#endif
bool gotLightMap=false, gotMainMap=false;
for (u32 t=0; t<me.Header.TextureCount; ++t)
{
if (id==MY3D_TEX_FNAME_ID)
file->read(namebuf, 256);
else
{
me.Texture2 = readEmbeddedLightmap(file, namebuf);
if (!me.Texture2)
return 0;
gotLightMap = true;
}
const core::stringc name(namebuf);
const s32 pos = name.findLast('.');
const core::stringc LightingMapStr = "LightingMap";
const s32 ls = LightingMapStr.size();
const bool isSubString = (LightingMapStr == name.subString(core::max_(0, (pos - ls)), ls));
if ((isSubString || (name[pos-1]=='m' &&
name[pos-2]=='l' && name[pos-3]=='_')) &&
!gotLightMap)
{
const bool oldMipMapState = SceneManager->getVideoDriver()->getTextureCreationFlag(video::ETCF_CREATE_MIP_MAPS);
SceneManager->getVideoDriver()->setTextureCreationFlag(video::ETCF_CREATE_MIP_MAPS, false);
me.Texture2FileName = "Lightmaps/";
me.Texture2FileName.append(name);
me.Texture2 = getMeshTextureLoader() ? getMeshTextureLoader()->getTexture(me.Texture2FileName) : NULL;
me.MaterialType = video::EMT_LIGHTMAP_M2;
gotLightMap = true;
SceneManager->getVideoDriver()->setTextureCreationFlag(video::ETCF_CREATE_MIP_MAPS, oldMipMapState);
}
else
if (!gotLightMap && gotMainMap)
{
if ( getMeshTextureLoader() )
{
me.Texture2 = getMeshTextureLoader() ? getMeshTextureLoader()->getTexture(name) : NULL;
if ( me.Texture2 )
me.Texture2FileName = me.Texture2->getName();
}
else
me.Texture2FileName = name;
me.MaterialType = video::EMT_REFLECTION_2_LAYER;
}
else
if (!gotMainMap && !gotLightMap)
{
if ( getMeshTextureLoader() )
{
me.Texture1 = getMeshTextureLoader() ? getMeshTextureLoader()->getTexture(name) : NULL;
if ( me.Texture1 )
me.Texture1FileName = me.Texture1->getName();
}
else
me.Texture1FileName = name;
gotMainMap = true;
me.MaterialType = video::EMT_SOLID;
}
else
if (gotLightMap)
{
me.MaterialType = video::EMT_LIGHTMAP_M2;
}
file->read(&id, sizeof(id));
#ifdef __BIG_ENDIAN__
id = os::Byteswap::byteswap(id);
#endif
}
// override material types based on their names
if (!strncmp(me.Header.Name, "AlphaChannel-", 13))
me.MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL;
else
if (!strncmp(me.Header.Name, "SphereMap-", 10))
me.MaterialType = video::EMT_SPHERE_MAP;
}
// loading meshes
if (id!=MY3D_MESH_LIST_ID)
{
os::Printer::log("Can not find MY3D_MESH_LIST_ID, loading failed!", ELL_ERROR);
return 0;
}
file->read(&id, sizeof(id));
#ifdef __BIG_ENDIAN__
id = os::Byteswap::byteswap(id);
#endif
for (s32 mesh_id=0; mesh_id<sceneHeader.MeshCount; mesh_id++)
{
// Warning!!! In some cases MY3D exporter uncorrectly calculates
// MeshCount (it's a problem, has to be solved) thats why
// i added this code line
if (id!=MY3D_MESH_HEADER_ID)
break;
if (id!=MY3D_MESH_HEADER_ID)
{
os::Printer::log("Can not find MY3D_MESH_HEADER_ID, loading failed!", ELL_ERROR);
return 0;
}
SMyMeshHeader meshHeader;
file->read(&meshHeader, sizeof(SMyMeshHeader));
core::array <SMyVertex> Vertex;
core::array <SMyFace> Face;
core::array <SMyTVertex> TVertex1, TVertex2;
core::array <SMyFace> TFace1, TFace2;
s32 vertsNum=0;
s32 facesNum=0;
// vertices
file->read(&id, sizeof(id));
#ifdef __BIG_ENDIAN__
id = os::Byteswap::byteswap(id);
#endif
if (id!=MY3D_VERTS_ID)
{
os::Printer::log("Can not find MY3D_VERTS_ID, loading failed!", ELL_ERROR);
return 0;
}
file->read(&vertsNum, sizeof(vertsNum));
Vertex.set_used(vertsNum);
file->read(Vertex.pointer(), sizeof(SMyVertex)*vertsNum);
// faces
file->read(&id, sizeof(id));
#ifdef __BIG_ENDIAN__
id = os::Byteswap::byteswap(id);
#endif
if (id!=MY3D_FACES_ID)
{
os::Printer::log("Can not find MY3D_FACES_ID, loading failed!", ELL_ERROR);
return 0;
}
file->read(&facesNum, sizeof(facesNum));
Face.set_used(facesNum);
file->read(Face.pointer(), sizeof(SMyFace)*facesNum);
// reading texture channels
for (s32 tex=0; tex<(s32)meshHeader.TChannelCnt; tex++)
{
// Max 2 texture channels allowed (but in format .my3d can be more)
s32 tVertsNum=0, tFacesNum=0;
// reading texture coords
file->read(&id, sizeof(id));
#ifdef __BIG_ENDIAN__
id = os::Byteswap::byteswap(id);
#endif
if (id!=MY3D_TVERTS_ID)
{
core::stringc msg="Can not find MY3D_TVERTS_ID (";
msg.append(core::stringc(tex));
msg.append("texture channel), loading failed!");
os::Printer::log(msg.c_str(), ELL_ERROR);
return 0;
}
file->read(&tVertsNum, sizeof(tVertsNum));
if (tex==0)
{
// 1st texture channel
TVertex1.set_used(tVertsNum);
file->read(TVertex1.pointer(), sizeof(SMyTVertex)*tVertsNum);
}
else
if (tex==1)
{
// 2nd texture channel
TVertex2.set_used(tVertsNum);
file->read(TVertex2.pointer(), sizeof(SMyTVertex)*tVertsNum);
}
else
{
// skip other texture channels
file->seek(file->getPos()+sizeof(SMyTVertex)*tVertsNum);
}
// reading texture faces
file->read(&id, sizeof(id));
#ifdef __BIG_ENDIAN__
id = os::Byteswap::byteswap(id);
#endif
if (id!=MY3D_TFACES_ID)
{
core::stringc msg="Can not find MY3D_TFACES_ID (";
msg.append(core::stringc(tex));
msg.append("texture channel), loading failed!");
os::Printer::log(msg.c_str(), ELL_ERROR);
return 0;
}
file->read(&tFacesNum, sizeof(tFacesNum));
if (tex==0)
{
// 1st texture channel
TFace1.set_used(tFacesNum);
file->read(TFace1.pointer(), sizeof(SMyFace)*tFacesNum);
}
else if (tex==1)
{
// 2nd texture channel
TFace2.set_used(tFacesNum);
file->read(TFace2.pointer(), sizeof(SMyFace)*tFacesNum);
}
else
{
// skip other texture channels
file->seek(file->getPos()+sizeof(SMyFace)*tFacesNum);
}
}
// trying to find material
SMyMaterialEntry* matEnt = getMaterialEntryByIndex(meshHeader.MatIndex);
// creating geometry for the mesh
// trying to find mesh buffer for this material
SMeshBufferLightMap* buffer = getMeshBufferByMaterialIndex(meshHeader.MatIndex);
if (!buffer ||
(buffer->Vertices.size()+vertsNum) > SceneManager->getVideoDriver()->getMaximalPrimitiveCount())
{
// creating new mesh buffer for this material
buffer = new scene::SMeshBufferLightMap();
buffer->Material.MaterialType = video::EMT_LIGHTMAP_M2; // EMT_LIGHTMAP_M4 also possible
buffer->Material.Wireframe = false;
buffer->Material.Lighting = false;
if (matEnt)
{
buffer->Material.MaterialType = matEnt->MaterialType;
if (buffer->Material.MaterialType == video::EMT_REFLECTION_2_LAYER)
{
buffer->Material.Lighting = true;
buffer->Material.setTexture(1, matEnt->Texture1);
buffer->Material.setTexture(0, matEnt->Texture2);
}
else
{
buffer->Material.setTexture(0, matEnt->Texture1);
buffer->Material.setTexture(1, matEnt->Texture2);
}
if (buffer->Material.MaterialType == video::EMT_TRANSPARENT_ALPHA_CHANNEL)
{
buffer->Material.BackfaceCulling = true;
buffer->Material.Lighting = true;
}
else
if (buffer->Material.MaterialType == video::EMT_SPHERE_MAP)
{
buffer->Material.Lighting = true;
}
buffer->Material.AmbientColor = video::SColor(
matEnt->Header.AmbientColor.A, matEnt->Header.AmbientColor.R,
matEnt->Header.AmbientColor.G, matEnt->Header.AmbientColor.B
);
buffer->Material.DiffuseColor = video::SColor(
matEnt->Header.DiffuseColor.A, matEnt->Header.DiffuseColor.R,
matEnt->Header.DiffuseColor.G, matEnt->Header.DiffuseColor.B
);
buffer->Material.EmissiveColor = video::SColor(
matEnt->Header.EmissiveColor.A, matEnt->Header.EmissiveColor.R,
matEnt->Header.EmissiveColor.G, matEnt->Header.EmissiveColor.B
);
buffer->Material.SpecularColor = video::SColor(
matEnt->Header.SpecularColor.A, matEnt->Header.SpecularColor.R,
matEnt->Header.SpecularColor.G, matEnt->Header.SpecularColor.B
);
}
else
{
buffer->Material.setTexture(0, 0);
buffer->Material.setTexture(1, 0);
buffer->Material.AmbientColor = video::SColor(255, 255, 255, 255);
buffer->Material.DiffuseColor = video::SColor(255, 255, 255, 255);
buffer->Material.EmissiveColor = video::SColor(0, 0, 0, 0);
buffer->Material.SpecularColor = video::SColor(0, 0, 0, 0);
}
if (matEnt && matEnt->Header.Transparency!=0)
{
if (buffer->Material.MaterialType == video::EMT_REFLECTION_2_LAYER )
{
buffer->Material.MaterialType = video::EMT_TRANSPARENT_REFLECTION_2_LAYER;
buffer->Material.Lighting = true;
buffer->Material.BackfaceCulling = true;
}
else
{
buffer->Material.MaterialType = video::EMT_TRANSPARENT_VERTEX_ALPHA;
buffer->Material.Lighting = false;
buffer->Material.BackfaceCulling = false;
}
}
else if (
!buffer->Material.getTexture(1) &&
buffer->Material.MaterialType != video::EMT_TRANSPARENT_ALPHA_CHANNEL &&
buffer->Material.MaterialType != video::EMT_SPHERE_MAP)
{
buffer->Material.MaterialType = video::EMT_SOLID;
buffer->Material.Lighting = true;
}
MeshBufferEntry.push_back(
SMyMeshBufferEntry(meshHeader.MatIndex, buffer));
}
video::S3DVertex2TCoords VertexA, VertexB, VertexC;
// vertices (A, B, C) color
video::SColor vert_color;
if (matEnt &&
(buffer->Material.MaterialType == video::EMT_TRANSPARENT_VERTEX_ALPHA ||
buffer->Material.MaterialType == video::EMT_TRANSPARENT_REFLECTION_2_LAYER))
{
video::SColor color(
matEnt->Header.DiffuseColor.A, matEnt->Header.DiffuseColor.R,
matEnt->Header.DiffuseColor.G, matEnt->Header.DiffuseColor.B);
vert_color = color.getInterpolated(video::SColor(0,0,0,0),
1-matEnt->Header.Transparency);
}
else
{
vert_color = buffer->Material.DiffuseColor;
}
VertexA.Color = VertexB.Color = VertexC.Color = vert_color;
if (buffer->Material.MaterialType == video::EMT_TRANSPARENT_ALPHA_CHANNEL)
{
buffer->Indices.reallocate(buffer->Indices.size()+6*facesNum);
buffer->Vertices.reallocate(buffer->Vertices.size()+6*facesNum);
}
else
{
buffer->Indices.reallocate(buffer->Indices.size()+3*facesNum);
buffer->Vertices.reallocate(buffer->Vertices.size()+3*facesNum);
}
for (int f=0; f<facesNum; f++)
{
// vertex A
VertexA.Pos.X = Vertex[Face[f].C].Coord.X;
VertexA.Pos.Y = Vertex[Face[f].C].Coord.Y;
VertexA.Pos.Z = Vertex[Face[f].C].Coord.Z;
VertexA.Normal.X = Vertex[Face[f].C].Normal.X;
VertexA.Normal.Y = Vertex[Face[f].C].Normal.Y;
VertexA.Normal.Z = Vertex[Face[f].C].Normal.Z;
if (meshHeader.TChannelCnt>0)
{
VertexA.TCoords.X = TVertex1[TFace1[f].C].TCoord.X;
VertexA.TCoords.Y = TVertex1[TFace1[f].C].TCoord.Y;
}
if (meshHeader.TChannelCnt>1)
{
VertexA.TCoords2.X = TVertex2[TFace2[f].C].TCoord.X;
VertexA.TCoords2.Y = TVertex2[TFace2[f].C].TCoord.Y;
}
// vertex B
VertexB.Pos.X = Vertex[Face[f].B].Coord.X;
VertexB.Pos.Y = Vertex[Face[f].B].Coord.Y;
VertexB.Pos.Z = Vertex[Face[f].B].Coord.Z;
VertexB.Normal.X = Vertex[Face[f].B].Normal.X;
VertexB.Normal.Y = Vertex[Face[f].B].Normal.Y;
VertexB.Normal.Z = Vertex[Face[f].B].Normal.Z;
if (meshHeader.TChannelCnt>0)
{
VertexB.TCoords.X = TVertex1[TFace1[f].B].TCoord.X;
VertexB.TCoords.Y = TVertex1[TFace1[f].B].TCoord.Y;
}
if (meshHeader.TChannelCnt>1)
{
VertexB.TCoords2.X = TVertex2[TFace2[f].B].TCoord.X;
VertexB.TCoords2.Y = TVertex2[TFace2[f].B].TCoord.Y;
}
// vertex C
VertexC.Pos.X = Vertex[Face[f].A].Coord.X;
VertexC.Pos.Y = Vertex[Face[f].A].Coord.Y;
VertexC.Pos.Z = Vertex[Face[f].A].Coord.Z;
VertexC.Normal.X = Vertex[Face[f].A].Normal.X;
VertexC.Normal.Y = Vertex[Face[f].A].Normal.Y;
VertexC.Normal.Z = Vertex[Face[f].A].Normal.Z;
if (meshHeader.TChannelCnt>0)
{
VertexC.TCoords.X = TVertex1[TFace1[f].A].TCoord.X;
VertexC.TCoords.Y = TVertex1[TFace1[f].A].TCoord.Y;
}
if (meshHeader.TChannelCnt>1)
{
VertexC.TCoords2.X = TVertex2[TFace2[f].A].TCoord.X;
VertexC.TCoords2.Y = TVertex2[TFace2[f].A].TCoord.Y;
}
// store 3d data in mesh buffer
buffer->Indices.push_back(buffer->Vertices.size());
buffer->Vertices.push_back(VertexA);
buffer->Indices.push_back(buffer->Vertices.size());
buffer->Vertices.push_back(VertexB);
buffer->Indices.push_back(buffer->Vertices.size());
buffer->Vertices.push_back(VertexC);
//*****************************************************************
// !!!!!! W A R N I N G !!!!!!!
//*****************************************************************
// For materials with alpha channel we duplicate all faces.
// This has be done for proper lighting calculation of the back faces.
// So you must remember this while you creating your models !!!!!
//*****************************************************************
// !!!!!! W A R N I N G !!!!!!!
//*****************************************************************
if (buffer->Material.MaterialType == video::EMT_TRANSPARENT_ALPHA_CHANNEL)
{
VertexA.Normal = core::vector3df(-VertexA.Normal.X, -VertexA.Normal.Y, -VertexA.Normal.Z);
VertexB.Normal = core::vector3df(-VertexB.Normal.X, -VertexB.Normal.Y, -VertexB.Normal.Z);
VertexC.Normal = core::vector3df(-VertexC.Normal.X, -VertexC.Normal.Y, -VertexC.Normal.Z);
buffer->Indices.push_back(buffer->Vertices.size());
buffer->Vertices.push_back(VertexC);
buffer->Indices.push_back(buffer->Vertices.size());
buffer->Vertices.push_back(VertexB);
buffer->Indices.push_back(buffer->Vertices.size());
buffer->Vertices.push_back(VertexA);
}
}
file->read(&id, sizeof(id));
#ifdef __BIG_ENDIAN__
id = os::Byteswap::byteswap(id);
#endif
}
// creating mesh
SMesh* mesh = new SMesh();
for (u32 num=0; num<MeshBufferEntry.size(); ++num)
{
SMeshBufferLightMap* buffer = MeshBufferEntry[num].MeshBuffer;
if (!buffer)
continue;
mesh->addMeshBuffer(buffer);
buffer->recalculateBoundingBox();
buffer->drop();
}
mesh->recalculateBoundingBox();
if (id != MY3D_FILE_END_ID)
os::Printer::log("Loading finished, but can not find MY3D_FILE_END_ID token.", ELL_WARNING);
SAnimatedMesh* am = new SAnimatedMesh();
am->addMesh(mesh);
mesh->drop();
am->recalculateBoundingBox();
return am;
}
video::ITexture* CMY3DMeshFileLoader::readEmbeddedLightmap(io::IReadFile* file, char* namebuf)
{
static int LightMapIndex=0;
u16 id;
file->read(&id, sizeof(id));
#ifdef __BIG_ENDIAN__
id = os::Byteswap::byteswap(id);
#endif
if (id!=MY3D_TEXDATA_HEADER_ID)
{
os::Printer::log("Can not find MY3D_TEXDATA_HEADER_ID, loading failed!", ELL_ERROR);
return 0;
}
SMyTexDataHeader texDataHeader;
file->read(&texDataHeader, sizeof(SMyTexDataHeader));
strcpy(texDataHeader.Name, namebuf);
char LightMapName[255];
sprintf(LightMapName,"My3D.Lightmap.%d",++LightMapIndex);
core::stringc pixFormatStr;
if (texDataHeader.PixelFormat == MY3D_PIXEL_FORMAT_24)
pixFormatStr = "24bit,";
else
if (texDataHeader.PixelFormat == MY3D_PIXEL_FORMAT_16)
pixFormatStr = "16bit,";
else
{
core::stringc msg="Unknown format of image data (";
msg.append(LightMapName);
msg.append("), loading failed!");
os::Printer::log(msg.c_str(), ELL_ERROR);
return 0;
}
if (texDataHeader.ComprMode != MY3D_TEXDATA_COMPR_NONE_ID &&
texDataHeader.ComprMode != MY3D_TEXDATA_COMPR_RLE_ID &&
texDataHeader.ComprMode != MY3D_TEXDATA_COMPR_SIMPLE_ID )
{
os::Printer::log("Unknown method of compression image data, loading failed!", ELL_ERROR);
return 0;
}
const u32 num_pixels = texDataHeader.Width*texDataHeader.Height;
void* data = 0;
if (texDataHeader.ComprMode==MY3D_TEXDATA_COMPR_NONE_ID)
{
// none compressed image data
if (texDataHeader.PixelFormat == MY3D_PIXEL_FORMAT_24)
{
data = (void*) new SMyPixelColor24[num_pixels];
file->read(data, sizeof(SMyPixelColor24)*num_pixels);
}
else
{
data = (void*) new SMyPixelColor16[num_pixels];
file->read(data, sizeof(SMyPixelColor16)*num_pixels);
}
}
else
if (texDataHeader.ComprMode==MY3D_TEXDATA_COMPR_RLE_ID)
{
// read RLE header identificator
file->read(&id, sizeof(id));
#ifdef __BIG_ENDIAN__
id = os::Byteswap::byteswap(id);
#endif
if (id!=MY3D_TEXDATA_RLE_HEADER_ID)
{
os::Printer::log("Can not find MY3D_TEXDATA_RLE_HEADER_ID, loading failed!", ELL_ERROR);
return 0;
}
// read RLE header
SMyRLEHeader rleHeader;
file->read(&rleHeader, sizeof(SMyRLEHeader));
//allocate memory for input and output buffers
void *input_buffer = (void*) new unsigned char[rleHeader.nEncodedBytes];
void *output_buffer = (void*) new unsigned char[rleHeader.nDecodedBytes];
// read encoded data
file->read(input_buffer, rleHeader.nEncodedBytes);
// decode data
data = 0;//(void*) new unsigned char[rleHeader.nDecodedBytes];
s32 decodedBytes = core::rle_decode(
(unsigned char*)input_buffer, rleHeader.nEncodedBytes,
(unsigned char*)output_buffer, rleHeader.nDecodedBytes);
if (decodedBytes!=(s32)rleHeader.nDecodedBytes)
{
os::Printer::log("Error extracting data from RLE compression, loading failed!", ELL_ERROR);
return 0;
}
// free input buffer
delete [] (unsigned char*)input_buffer;
// here decoded data
data = output_buffer;
}
else if (texDataHeader.ComprMode==MY3D_TEXDATA_COMPR_SIMPLE_ID)
{
// simple compressed image data
if (texDataHeader.PixelFormat == MY3D_PIXEL_FORMAT_24)
data = (void*) new SMyPixelColor24[num_pixels];
else
data = (void*) new SMyPixelColor16[num_pixels];
u32 nReadedPixels=0, nToRead=0;
while (true)
{
file->read(&nToRead, sizeof(nToRead));
if ((nReadedPixels+nToRead) > num_pixels)
break;
if (texDataHeader.PixelFormat == MY3D_PIXEL_FORMAT_24)
{
SMyPixelColor24 col24;
file->read(&col24, sizeof(SMyPixelColor24));
for (u32 p=0; p<nToRead; p++)
{
((SMyPixelColor24*)data)[nReadedPixels+p] =
SMyPixelColor24(col24.r, col24.g, col24.b);
}
}
else
{
SMyPixelColor16 col16;
file->read(&col16, sizeof(SMyPixelColor16));
for (u32 p=0; p<nToRead; p++)
((SMyPixelColor16*)data)[nReadedPixels+p].argb = col16.argb;
}
nReadedPixels+=nToRead;
if (nReadedPixels >= num_pixels)
break;
}
if (nReadedPixels != num_pixels)
{
os::Printer::log("Image data seems to be corrupted, loading failed!", ELL_ERROR);
return 0;
}
}
//! Creates a software image from a byte array.
video::IImage* light_img = 0;
if (texDataHeader.PixelFormat == MY3D_PIXEL_FORMAT_24)
{
// 24 bit lightmap format
light_img = SceneManager->getVideoDriver()->createImageFromData(
video::ECF_R8G8B8,
core::dimension2d<u32>(texDataHeader.Width, texDataHeader.Height),
data, true);
}
else
{
// 16 bit lightmap format
light_img = SceneManager->getVideoDriver()->createImageFromData(
video::ECF_A1R5G5B5,
core::dimension2d<u32>(texDataHeader.Width, texDataHeader.Height),
data, true);
}
const bool oldMipMapState = SceneManager->getVideoDriver()->getTextureCreationFlag(video::ETCF_CREATE_MIP_MAPS);
SceneManager->getVideoDriver()->setTextureCreationFlag(video::ETCF_CREATE_MIP_MAPS, false);
video::ITexture* lmtex = SceneManager->getVideoDriver()->addTexture(LightMapName, light_img);
SceneManager->getVideoDriver()->setTextureCreationFlag(video::ETCF_CREATE_MIP_MAPS, oldMipMapState);
light_img->drop();
return lmtex;
}
CMY3DMeshFileLoader::SMyMaterialEntry* CMY3DMeshFileLoader::getMaterialEntryByIndex(u32 matInd)
{
for (u32 m=0; m<MaterialEntry.size(); ++m)
if (MaterialEntry[m].Header.Index == matInd)
return &MaterialEntry[m];
return 0;
}
SMeshBufferLightMap* CMY3DMeshFileLoader::getMeshBufferByMaterialIndex(u32 matInd)
{
for (u32 m=0; m<MeshBufferEntry.size(); ++m)
{
if (MeshBufferEntry[m].MaterialIndex == (s32)matInd)
return MeshBufferEntry[m].MeshBuffer;
}
return 0;
}
const core::array<ISceneNode*>& CMY3DMeshFileLoader::getChildNodes() const
{
return ChildNodes;
}
} // end namespace scnene
} // end namespace irr
#endif // _IRR_COMPILE_WITH_MY3D_LOADER_

View File

@ -1,131 +0,0 @@
// Copyright (C) 2002-2012 Nikolaus Gebhardt
// This file is part of the "Irrlicht Engine".
// For conditions of distribution and use, see copyright notice in irrlicht.h
//
// This file was originally written by ZDimitor.
// I (Nikolaus Gebhardt) did some few changes to this:
// - replaced logging calls to their os:: counterparts
// - removed some logging calls
// - removed setTexture path and replaced it with the directory of the mesh
// - added EAMT_MY3D file type
// - fixed a memory leak when decompressing RLE data.
// - cleaned multi character constant problems with gcc
// - removed octree child scene node generation because irrlicht is now able to draw
// scene nodes with transparent and sold materials in them at the same time. (see changes.txt)
// Thanks a lot to ZDimitor for his work on this and that he gave me
// his permission to add it into Irrlicht.
//--------------------------------------------------------------------------------
// This tool created by ZDimitor everyone can use it as wants
//--------------------------------------------------------------------------------
#ifndef __CMY3D_MESH_FILE_LOADER_H_INCLUDED__
#define __CMY3D_MESH_FILE_LOADER_H_INCLUDED__
#ifdef _MSC_VER
#pragma once
#endif
#include "IMeshLoader.h"
#include "SMesh.h"
#include "SMeshBufferLightMap.h"
#include "IFileSystem.h"
#include "IVideoDriver.h"
#include "irrString.h"
#include "ISceneManager.h"
namespace irr
{
namespace scene
{
// byte-align structures
#include "irrpack.h"
struct SMyColor
{ SMyColor () {;}
SMyColor (s32 __R, s32 __G, s32 __B, s32 __A)
: R(__R), G(__G), B(__B), A(__A) {}
s32 R, G, B, A;
} PACK_STRUCT;
// material header
struct SMyMaterialHeader
{ c8 Name[256]; // material name
u32 Index;
SMyColor AmbientColor;
SMyColor DiffuseColor;
SMyColor EmissiveColor;
SMyColor SpecularColor;
f32 Shininess;
f32 Transparency;
u32 TextureCount; // texture count
} PACK_STRUCT;
// Default alignment
#include "irrunpack.h"
class CMY3DMeshFileLoader : public IMeshLoader
{
public:
CMY3DMeshFileLoader(ISceneManager *scmgr, io::IFileSystem* fs);
virtual ~CMY3DMeshFileLoader();
virtual bool isALoadableFileExtension(const io::path& filename) const _IRR_OVERRIDE_;
virtual IAnimatedMesh* createMesh(io::IReadFile* file) _IRR_OVERRIDE_;
//! getting access to the nodes (with transparent material), creating
//! while loading .my3d file
const core::array<ISceneNode*>& getChildNodes() const;
private:
video::ITexture* readEmbeddedLightmap(io::IReadFile* file, char* namebuf);
scene::ISceneManager* SceneManager;
io::IFileSystem* FileSystem;
struct SMyMaterialEntry
{
SMyMaterialEntry ()
: Texture1FileName("null"), Texture2FileName("null"),
Texture1(0), Texture2(0), MaterialType(video::EMT_SOLID) {
Header.Name[0] = 0;
}
SMyMaterialHeader Header;
core::stringc Texture1FileName;
core::stringc Texture2FileName;
video::ITexture *Texture1;
video::ITexture *Texture2;
video::E_MATERIAL_TYPE MaterialType;
};
struct SMyMeshBufferEntry
{
SMyMeshBufferEntry() : MaterialIndex(-1), MeshBuffer(0) {}
SMyMeshBufferEntry(s32 mi, SMeshBufferLightMap* mb)
: MaterialIndex(mi), MeshBuffer(mb) {}
s32 MaterialIndex;
SMeshBufferLightMap* MeshBuffer;
};
SMyMaterialEntry* getMaterialEntryByIndex (u32 matInd);
SMeshBufferLightMap* getMeshBufferByMaterialIndex(u32 matInd);
core::array<SMyMaterialEntry> MaterialEntry;
core::array<SMyMeshBufferEntry> MeshBufferEntry;
core::array<ISceneNode*> ChildNodes;
};
} // end namespace scene
} // end namespace irr
#endif // __CMY3D_MESH_FILE_LOADER_H_INCLUDED__

View File

@ -107,32 +107,9 @@ set(link_libs
# Source files
set(IRRMESHLOADER
CBSPMeshFileLoader.cpp
CMD2MeshFileLoader.cpp
CMD3MeshFileLoader.cpp
CMS3DMeshFileLoader.cpp
CB3DMeshFileLoader.cpp
C3DSMeshFileLoader.cpp
COgreMeshFileLoader.cpp
COBJMeshFileLoader.cpp
CCSMLoader.cpp
CDMFLoader.cpp
CLMTSMeshFileLoader.cpp
CMY3DMeshFileLoader.cpp
COCTLoader.cpp
CXMeshFileLoader.cpp
CSTLMeshFileLoader.cpp
CLWOMeshFileLoader.cpp
CPLYMeshFileLoader.cpp
CSMFMeshFileLoader.cpp
CMeshTextureLoader.cpp
)
set(IRRMESHWRITER
CSTLMeshWriter.cpp
COBJMeshWriter.cpp
CPLYMeshWriter.cpp
CB3DMeshWriter.cpp
)
add_library(IRRMESHOBJ OBJECT
@ -140,13 +117,7 @@ add_library(IRRMESHOBJ OBJECT
CBoneSceneNode.cpp
CMeshSceneNode.cpp
CAnimatedMeshSceneNode.cpp
CAnimatedMeshMD2.cpp
CAnimatedMeshMD3.cpp
CQ3LevelMesh.cpp
CQuake3ShaderSceneNode.cpp
CAnimatedMeshHalfLife.cpp
${IRRMESHLOADER}
${IRRMESHWRITER}
)
add_library(IRROBJ OBJECT
@ -154,59 +125,12 @@ add_library(IRROBJ OBJECT
CCameraSceneNode.cpp
CDummyTransformationSceneNode.cpp
CEmptySceneNode.cpp
CGeometryCreator.cpp
CLightSceneNode.cpp
CMeshManipulator.cpp
CMetaTriangleSelector.cpp
COctreeSceneNode.cpp
COctreeTriangleSelector.cpp
CSceneCollisionManager.cpp
CSceneManager.cpp
CShadowVolumeSceneNode.cpp
CSkyBoxSceneNode.cpp
CSkyDomeSceneNode.cpp
CTerrainSceneNode.cpp
CTerrainTriangleSelector.cpp
CVolumeLightSceneNode.cpp
CCubeSceneNode.cpp
CSphereSceneNode.cpp
CTextSceneNode.cpp
CTriangleBBSelector.cpp
CTriangleSelector.cpp
CWaterSurfaceSceneNode.cpp
CMeshCache.cpp
CDefaultSceneNodeAnimatorFactory.cpp
CDefaultSceneNodeFactory.cpp
)
add_library(IRRPARTICLEOBJ OBJECT
CParticleAnimatedMeshSceneNodeEmitter.cpp
CParticleBoxEmitter.cpp
CParticleCylinderEmitter.cpp
CParticleMeshEmitter.cpp
CParticlePointEmitter.cpp
CParticleRingEmitter.cpp
CParticleSphereEmitter.cpp
CParticleAttractionAffector.cpp
CParticleFadeOutAffector.cpp
CParticleGravityAffector.cpp
CParticleRotationAffector.cpp
CParticleSystemSceneNode.cpp
CParticleScaleAffector.cpp
)
add_library(IRRANIMOBJ OBJECT
CSceneNodeAnimatorCameraFPS.cpp
CSceneNodeAnimatorCameraMaya.cpp
CSceneNodeAnimatorCollisionResponse.cpp
CSceneNodeAnimatorDelete.cpp
CSceneNodeAnimatorFlyCircle.cpp
CSceneNodeAnimatorFlyStraight.cpp
CSceneNodeAnimatorFollowSpline.cpp
CSceneNodeAnimatorRotation.cpp
CSceneNodeAnimatorTexture.cpp
)
set(IRRDRVROBJ
CNullDriver.cpp
COpenGLCacheHandler.cpp
@ -216,12 +140,6 @@ set(IRRDRVROBJ
COpenGLShaderMaterialRenderer.cpp
COpenGLSLMaterialRenderer.cpp
COpenGLExtensionHandler.cpp
CD3D9Driver.cpp
CD3D9HLSLMaterialRenderer.cpp
CD3D9NormalMapRenderer.cpp
CD3D9ParallaxMapRenderer.cpp
CD3D9ShaderMaterialRenderer.cpp
CD3D9Texture.cpp
COGLESDriver.cpp
COGLESExtensionHandler.cpp
COGLES2Driver.cpp
@ -241,23 +159,10 @@ set(IRRIMAGEOBJ
CColorConverter.cpp
CImage.cpp
CImageLoaderBMP.cpp
CImageLoaderDDS.cpp
CImageLoaderJPG.cpp
CImageLoaderPCX.cpp
CImageLoaderPNG.cpp
CImageLoaderPSD.cpp
CImageLoaderPVR.cpp
CImageLoaderTGA.cpp
CImageLoaderPPM.cpp
CImageLoaderWAL.cpp
CImageLoaderRGB.cpp
CImageWriterBMP.cpp
CImageWriterJPG.cpp
CImageWriterPCX.cpp
CImageWriterPNG.cpp
CImageWriterPPM.cpp
CImageWriterPSD.cpp
CImageWriterTGA.cpp
)
add_library(IRRVIDEOOBJ OBJECT
@ -267,50 +172,6 @@ add_library(IRRVIDEOOBJ OBJECT
${IRRIMAGEOBJ}
)
add_library(IRRSWRENDEROBJ OBJECT
CSoftwareDriver.cpp
CSoftwareTexture.cpp
CTRFlat.cpp
CTRFlatWire.cpp
CTRGouraud.cpp
CTRGouraudWire.cpp
CTRNormalMap.cpp
CTRStencilShadow.cpp
CTRTextureFlat.cpp
CTRTextureFlatWire.cpp
CTRTextureGouraud.cpp
CTRTextureGouraudAdd.cpp
CTRTextureGouraudNoZ.cpp
CTRTextureGouraudWire.cpp
CZBuffer.cpp
CTRTextureGouraudVertexAlpha2.cpp
CTRTextureGouraudNoZ2.cpp
CTRTextureLightMap2_M2.cpp
CTRTextureLightMap2_M4.cpp
CTRTextureLightMap2_M1.cpp
CSoftwareDriver2.cpp
CSoftwareTexture2.cpp
CTRTextureGouraud2.cpp
CTRGouraud2.cpp
CTRGouraudAlpha2.cpp
CTRGouraudAlphaNoZ2.cpp
CTRTextureDetailMap2.cpp
CTRTextureGouraudAdd2.cpp
CTRTextureGouraudAddNoZ2.cpp
CTRTextureWire2.cpp
CTRTextureLightMap2_Add.cpp
CTRTextureLightMapGouraud2_M4.cpp
IBurningShader.cpp
CTRTextureBlend.cpp
CTRTextureGouraudAlpha.cpp
CTRTextureGouraudAlphaNoZ.cpp
CDepthBuffer.cpp
CBurningShader_Raster_Reference.cpp
CTR_transparent_reflection_2_layer.cpp
CTRGouraudNoZ2.cpp
burning_shader_color.cpp
)
add_library(IRRIOOBJ OBJECT
CFileList.cpp
CFileSystem.cpp
@ -318,11 +179,7 @@ add_library(IRRIOOBJ OBJECT
CMemoryFile.cpp
CReadFile.cpp
CWriteFile.cpp
CWADReader.cpp
CZipReader.cpp
CPakReader.cpp
CNPKReader.cpp
CTarReader.cpp
CMountPointReader.cpp
CAttributes.cpp
)
@ -395,7 +252,7 @@ add_library(IRRGUIOBJ OBJECT
add_library(IrrlichtMt)
foreach(object_lib
IRRMESHOBJ IRROBJ IRRPARTICLEOBJ IRRANIMOBJ IRRVIDEOOBJ IRRSWRENDEROBJ
IRRMESHOBJ IRROBJ IRRVIDEOOBJ
IRRIOOBJ IRROTHEROBJ IRRGUIOBJ)
# Set include directories for object library compilation
target_include_directories(${object_lib} PRIVATE ${link_includes})

View File

@ -11,11 +11,6 @@
#include "IAnimatedMesh.h"
#include "IMaterialRenderer.h"
#include "IFileSystem.h"
#ifdef _IRR_COMPILE_WITH_SHADOW_VOLUME_SCENENODE_
#include "CShadowVolumeSceneNode.h"
#else
#include "IShadowVolumeSceneNode.h"
#endif // _IRR_COMPILE_WITH_SHADOW_VOLUME_SCENENODE_
namespace irr
{
@ -28,7 +23,7 @@ namespace scene
CMeshSceneNode::CMeshSceneNode(IMesh* mesh, ISceneNode* parent, ISceneManager* mgr, s32 id,
const core::vector3df& position, const core::vector3df& rotation,
const core::vector3df& scale)
: IMeshSceneNode(parent, mgr, id, position, rotation, scale), Mesh(0), Shadow(0),
: IMeshSceneNode(parent, mgr, id, position, rotation, scale), Mesh(0),
PassCount(0), ReadOnlyMaterials(false)
{
#ifdef _DEBUG
@ -42,8 +37,6 @@ CMeshSceneNode::CMeshSceneNode(IMesh* mesh, ISceneNode* parent, ISceneManager* m
//! destructor
CMeshSceneNode::~CMeshSceneNode()
{
if (Shadow)
Shadow->drop();
if (Mesh)
Mesh->drop();
}
@ -109,9 +102,6 @@ void CMeshSceneNode::render()
driver->setTransform(video::ETS_WORLD, AbsoluteTransformation);
Box = Mesh->getBoundingBox();
if (Shadow && PassCount==1)
Shadow->updateShadowVolumes();
// for debug purposes only:
bool renderMeshes = true;
@ -210,12 +200,6 @@ void CMeshSceneNode::render()
//! or to remove attached childs.
bool CMeshSceneNode::removeChild(ISceneNode* child)
{
if (child && Shadow == child)
{
Shadow->drop();
Shadow = 0;
}
return ISceneNode::removeChild(child);
}
@ -272,29 +256,6 @@ void CMeshSceneNode::setMesh(IMesh* mesh)
}
//! Creates shadow volume scene node as child of this node
//! and returns a pointer to it.
IShadowVolumeSceneNode* CMeshSceneNode::addShadowVolumeSceneNode(
const IMesh* shadowMesh, s32 id, bool zfailmethod, f32 infinity)
{
#ifdef _IRR_COMPILE_WITH_SHADOW_VOLUME_SCENENODE_
if (!SceneManager->getVideoDriver()->queryFeature(video::EVDF_STENCIL_BUFFER))
return 0;
if (!shadowMesh)
shadowMesh = Mesh; // if null is given, use the mesh of node
if (Shadow)
Shadow->drop();
Shadow = new CShadowVolumeSceneNode(shadowMesh, this, SceneManager, id, zfailmethod, infinity);
return Shadow;
#else
return 0;
#endif
}
void CMeshSceneNode::copyMaterials()
{
Materials.clear();
@ -414,9 +375,6 @@ ISceneNode* CMeshSceneNode::clone(ISceneNode* newParent, ISceneManager* newManag
nb->cloneMembers(this, newManager);
nb->ReadOnlyMaterials = ReadOnlyMaterials;
nb->Materials = Materials;
nb->Shadow = Shadow;
if ( nb->Shadow )
nb->Shadow->grab();
if (newParent)
nb->drop();

View File

@ -60,11 +60,6 @@ namespace scene
//! Returns the current mesh
virtual IMesh* getMesh(void) _IRR_OVERRIDE_ { return Mesh; }
//! Creates shadow volume scene node as child of this node
//! and returns a pointer to it.
virtual IShadowVolumeSceneNode* addShadowVolumeSceneNode(const IMesh* shadowMesh,
s32 id, bool zfailmethod=true, f32 infinity=10000.0f) _IRR_OVERRIDE_;
//! Sets if the scene node should not copy the materials of the mesh but use them in a read only style.
/* In this way it is possible to change the materials a mesh causing all mesh scene nodes
referencing this mesh to change too. */
@ -90,7 +85,6 @@ namespace scene
video::SMaterial ReadOnlyMaterial;
IMesh* Mesh;
IShadowVolumeSceneNode* Shadow;
s32 PassCount;
bool ReadOnlyMaterials;

View File

@ -1,130 +0,0 @@
#include "CMeshTextureLoader.h"
#include "IFileSystem.h"
#include "IVideoDriver.h"
#include "os.h"
namespace irr
{
namespace scene
{
CMeshTextureLoader::CMeshTextureLoader(irr::io::IFileSystem* fs, irr::video::IVideoDriver* driver)
: FileSystem(fs)
, VideoDriver(driver)
, MeshFile(0)
, MaterialFile(0)
{
}
//! Set a custom texture path.
void CMeshTextureLoader::setTexturePath(const irr::io::path& path)
{
TexturePath = path;
preparePath(TexturePath);
}
//! Get the current custom texture path.
const irr::io::path& CMeshTextureLoader::getTexturePath() const
{
return TexturePath;
}
bool CMeshTextureLoader::checkTextureName( const irr::io::path& filename)
{
//os::Printer::log("CheckTextureName:", core::stringc(filename).c_str(), ELL_DEBUG);
if (FileSystem->existFile(filename))
{
//os::Printer::log("file exists", ELL_DEBUG);
TextureName = filename;
return true;
}
return false;
}
//! Get the texture by searching for it in all paths that makes sense for the given textureName.
irr::video::ITexture* CMeshTextureLoader::getTexture(const irr::io::path& textureName)
{
if ( textureName.empty() || !FileSystem || !VideoDriver)
return NULL;
// Pre-process texture filename.
irr::io::path simplifiedTexName(textureName);
simplifiedTexName.replace(_IRR_TEXT('\\'),_IRR_TEXT('/'));
// user defined texture path
if ( !TexturePath.empty() )
{
if ( checkTextureName(TexturePath + simplifiedTexName) )
return VideoDriver->getTexture(TextureName);
if ( checkTextureName(TexturePath + FileSystem->getFileBasename(simplifiedTexName)) )
return VideoDriver->getTexture(TextureName);
}
// just the name itself
if ( checkTextureName(simplifiedTexName) )
return VideoDriver->getTexture(TextureName);
// look in files relative to the folder of the meshfile
if ( MeshFile )
{
if ( MeshPath.empty() )
{
MeshPath = FileSystem->getFileDir(MeshFile->getFileName());
preparePath(MeshPath);
}
if ( !MeshPath.empty() )
{
if ( checkTextureName(MeshPath + simplifiedTexName) )
return VideoDriver->getTexture(TextureName);
if ( checkTextureName(MeshPath + FileSystem->getFileBasename(simplifiedTexName)) )
return VideoDriver->getTexture(TextureName);
}
}
// look in files relative to the folder of the materialfile
if ( MaterialFile )
{
if ( MaterialPath.empty() )
{
MaterialPath = FileSystem->getFileDir(MaterialFile->getFileName());
preparePath(MaterialPath);
}
if ( !MaterialPath.empty() )
{
if ( checkTextureName(MaterialPath + simplifiedTexName) )
return VideoDriver->getTexture(TextureName);
if ( checkTextureName(MaterialPath + FileSystem->getFileBasename(simplifiedTexName)) )
return VideoDriver->getTexture(TextureName);
}
}
// check current working directory
if ( checkTextureName(FileSystem->getFileBasename(simplifiedTexName)) )
return VideoDriver->getTexture(TextureName);
TextureName = _IRR_TEXT("");
return NULL;
}
//! Meshloaders will search paths relative to the meshFile.
void CMeshTextureLoader::setMeshFile(const irr::io::IReadFile* meshFile)
{
// no grab (would need a weak_ptr)
MeshFile = meshFile;
MeshPath = _IRR_TEXT(""); // do a lazy evaluation later
}
//! Meshloaders will try to look relative to the path of the materialFile
void CMeshTextureLoader::setMaterialFile(const irr::io::IReadFile* materialFile)
{
// no grab (would need a weak_ptr)
MaterialFile = materialFile;
MaterialPath = _IRR_TEXT(""); // do a lazy evaluation later
}
} // end namespace scnene
} // end namespace irr

View File

@ -1,81 +0,0 @@
#ifndef IRR_C_MESH_TEXTURE_LOADER_H_INCLUDED
#define IRR_C_MESH_TEXTURE_LOADER_H_INCLUDED
#include "IMeshTextureLoader.h"
namespace irr
{
namespace io
{
class IFileSystem;
} // end namespace io
namespace video
{
class IVideoDriver;
}
namespace scene
{
class CMeshTextureLoader : public IMeshTextureLoader
{
public:
CMeshTextureLoader(irr::io::IFileSystem* fs, irr::video::IVideoDriver* driver);
//! Set a custom texture path.
/** This is the first path the texture-loader should search. */
virtual void setTexturePath(const irr::io::path& path) _IRR_OVERRIDE_;
//! Get the current custom texture path.
virtual const irr::io::path& getTexturePath() const _IRR_OVERRIDE_;
//! Get the texture by searching for it in all paths that makes sense for the given textureName.
/** Usually you do not have to use this method, it is used internally by IMeshLoader's.
\param textureName Texturename as used in the mesh-format
\return Pointer to the texture. Returns 0 if loading failed.*/
virtual irr::video::ITexture* getTexture(const irr::io::path& textureName) _IRR_OVERRIDE_;
//! Meshloaders will search paths relative to the meshFile.
/** Usually you do not have to use this method, it is used internally by IMeshLoader's.
Any values you set here will likely be overwritten internally. */
virtual void setMeshFile(const irr::io::IReadFile* meshFile) _IRR_OVERRIDE_;
//! Meshloaders will try to look relative to the path of the materialFile
/** Usually you do not have to use this method, it is used internally by IMeshLoader's.
Any values you set here will likely be overwritten internally. */
virtual void setMaterialFile(const irr::io::IReadFile* materialFile) _IRR_OVERRIDE_;
protected:
// make certain path's have a certain internal format
void preparePath(irr::io::path& directory)
{
if (!directory.empty())
{
if (directory == _IRR_TEXT("."))
directory = _IRR_TEXT("");
directory.replace(_IRR_TEXT('\\'),_IRR_TEXT('/'));
if (directory.lastChar() != _IRR_TEXT('/'))
directory.append(_IRR_TEXT('/'));
}
}
// Save the texturename when it's a an existing file
bool checkTextureName( const irr::io::path& filename);
private:
irr::io::IFileSystem * FileSystem;
irr::video::IVideoDriver* VideoDriver;
irr::io::path TexturePath;
const irr::io::IReadFile* MeshFile;
irr::io::path MeshPath;
const irr::io::IReadFile* MaterialFile;
irr::io::path MaterialPath;
irr::io::path TextureName;
};
} // end namespace scene
} // end namespace irr
#endif

View File

@ -1,225 +0,0 @@
// Copyright (C) 2002-2012 Nikolaus Gebhardt
// This file is part of the "Irrlicht Engine".
// For conditions of distribution and use, see copyright notice in irrlicht.h
#include "CMetaTriangleSelector.h"
namespace irr
{
namespace scene
{
//! constructor
CMetaTriangleSelector::CMetaTriangleSelector()
{
#ifdef _DEBUG
setDebugName("CMetaTriangleSelector");
#endif
}
//! destructor
CMetaTriangleSelector::~CMetaTriangleSelector()
{
removeAllTriangleSelectors();
}
//! Returns amount of all available triangles in this selector
s32 CMetaTriangleSelector::getTriangleCount() const
{
s32 count = 0;
for (u32 i=0; i<TriangleSelectors.size(); ++i)
count += TriangleSelectors[i]->getTriangleCount();
return count;
}
//! Gets all triangles.
void CMetaTriangleSelector::getTriangles(core::triangle3df* triangles, s32 arraySize,
s32& outTriangleCount, const core::matrix4* transform, bool useNodeTransform,
irr::core::array<SCollisionTriangleRange>* outTriangleInfo) const
{
s32 outWritten = 0;
irr::u32 outTriangleInfoSize = outTriangleInfo ? outTriangleInfo->size() : 0;
for (u32 i=0; i<TriangleSelectors.size(); ++i)
{
s32 t = 0;
TriangleSelectors[i]->getTriangles(triangles + outWritten,
arraySize - outWritten, t, transform, useNodeTransform, outTriangleInfo);
if ( outTriangleInfo )
{
irr::u32 newTriangleInfoSize = outTriangleInfo->size();
for ( u32 ti=outTriangleInfoSize; ti<newTriangleInfoSize; ++ti )
{
(*outTriangleInfo)[ti].RangeStart += outWritten;
}
outTriangleInfoSize = newTriangleInfoSize;
}
outWritten += t;
if (outWritten==arraySize)
break;
}
outTriangleCount = outWritten;
}
//! Gets all triangles which lie within a specific bounding box.
void CMetaTriangleSelector::getTriangles(core::triangle3df* triangles, s32 arraySize,
s32& outTriangleCount, const core::aabbox3d<f32>& box,
const core::matrix4* transform, bool useNodeTransform,
irr::core::array<SCollisionTriangleRange>* outTriangleInfo) const
{
s32 outWritten = 0;
irr::u32 outTriangleInfoSize = outTriangleInfo ? outTriangleInfo->size() : 0;
for (u32 i=0; i<TriangleSelectors.size(); ++i)
{
s32 t = 0;
TriangleSelectors[i]->getTriangles(triangles + outWritten,
arraySize - outWritten, t, box, transform, useNodeTransform, outTriangleInfo);
if ( outTriangleInfo )
{
irr::u32 newTriangleInfoSize = outTriangleInfo->size();
for ( u32 ti=outTriangleInfoSize; ti<newTriangleInfoSize; ++ti )
{
(*outTriangleInfo)[ti].RangeStart += outWritten;
}
outTriangleInfoSize = newTriangleInfoSize;
}
outWritten += t;
if (outWritten==arraySize)
break;
}
outTriangleCount = outWritten;
}
//! Gets all triangles which have or may have contact with a 3d line.
void CMetaTriangleSelector::getTriangles(core::triangle3df* triangles, s32 arraySize,
s32& outTriangleCount, const core::line3d<f32>& line,
const core::matrix4* transform, bool useNodeTransform,
irr::core::array<SCollisionTriangleRange>* outTriangleInfo) const
{
s32 outWritten = 0;
irr::u32 outTriangleInfoSize = outTriangleInfo ? outTriangleInfo->size() : 0;
for (u32 i=0; i<TriangleSelectors.size(); ++i)
{
s32 t = 0;
TriangleSelectors[i]->getTriangles(triangles + outWritten,
arraySize - outWritten, t, line, transform, useNodeTransform, outTriangleInfo);
if ( outTriangleInfo )
{
irr::u32 newTriangleInfoSize = outTriangleInfo->size();
for ( u32 ti=outTriangleInfoSize; ti<newTriangleInfoSize; ++ti )
{
(*outTriangleInfo)[ti].RangeStart += outWritten;
}
outTriangleInfoSize = newTriangleInfoSize;
}
outWritten += t;
if (outWritten==arraySize)
break;
}
outTriangleCount = outWritten;
}
//! Adds a triangle selector to the collection of triangle selectors
//! in this metaTriangleSelector.
void CMetaTriangleSelector::addTriangleSelector(ITriangleSelector* toAdd)
{
if (!toAdd)
return;
TriangleSelectors.push_back(toAdd);
toAdd->grab();
}
//! Removes a specific triangle selector which was added before from the collection.
bool CMetaTriangleSelector::removeTriangleSelector(ITriangleSelector* toRemove)
{
for (u32 i=0; i<TriangleSelectors.size(); ++i)
{
if (toRemove == TriangleSelectors[i])
{
TriangleSelectors[i]->drop();
TriangleSelectors.erase(i);
return true;
}
}
return false;
}
//! Removes all triangle selectors from the collection.
void CMetaTriangleSelector::removeAllTriangleSelectors()
{
for (u32 i=0; i<TriangleSelectors.size(); ++i)
TriangleSelectors[i]->drop();
TriangleSelectors.clear();
}
//! Return the scene node associated with a given triangle.
ISceneNode* CMetaTriangleSelector::getSceneNodeForTriangle(u32 triangleIndex) const
{
u32 totalTriangles = 0;
for (u32 i=0; i<TriangleSelectors.size(); ++i)
{
totalTriangles += TriangleSelectors[i]->getTriangleCount();
if(totalTriangles > triangleIndex)
return TriangleSelectors[i]->getSceneNodeForTriangle(0);
}
return 0;
}
/* Return the number of TriangleSelectors that are inside this one,
Only useful for MetaTriangleSelector others return 1
*/
u32 CMetaTriangleSelector::getSelectorCount() const
{
return TriangleSelectors.size();
}
/* Returns the TriangleSelector based on index based on getSelectorCount
Only useful for MetaTriangleSelector others return 'this'
*/
ITriangleSelector* CMetaTriangleSelector::getSelector(u32 index)
{
if (index >= TriangleSelectors.size())
return 0;
return TriangleSelectors[index];
}
/* Returns the TriangleSelector based on index based on getSelectorCount
Only useful for MetaTriangleSelector others return 'this'
*/
const ITriangleSelector* CMetaTriangleSelector::getSelector(u32 index) const
{
if (index >= TriangleSelectors.size())
return 0;
return TriangleSelectors[index];
}
} // end namespace scene
} // end namespace irr

View File

@ -1,79 +0,0 @@
// Copyright (C) 2002-2012 Nikolaus Gebhardt
// This file is part of the "Irrlicht Engine".
// For conditions of distribution and use, see copyright notice in irrlicht.h
#ifndef __C_META_TRIANGLE_SELECTOR_H_INCLUDED__
#define __C_META_TRIANGLE_SELECTOR_H_INCLUDED__
#include "IMetaTriangleSelector.h"
#include "irrArray.h"
namespace irr
{
namespace scene
{
//! Interface for making multiple triangle selectors work as one big selector.
class CMetaTriangleSelector : public IMetaTriangleSelector
{
public:
//! constructor
CMetaTriangleSelector();
//! destructor
virtual ~CMetaTriangleSelector();
//! Get amount of all available triangles in this selector
virtual s32 getTriangleCount() const _IRR_OVERRIDE_;
//! Gets all triangles.
virtual void getTriangles(core::triangle3df* triangles, s32 arraySize,
s32& outTriangleCount, const core::matrix4* transform, bool useNodeTransform,
irr::core::array<SCollisionTriangleRange>* outTriangleInfo) const _IRR_OVERRIDE_;
//! Gets all triangles which lie within a specific bounding box.
virtual void getTriangles(core::triangle3df* triangles, s32 arraySize,
s32& outTriangleCount, const core::aabbox3d<f32>& box,
const core::matrix4* transform, bool useNodeTransform,
irr::core::array<SCollisionTriangleRange>* outTriangleInfo) const _IRR_OVERRIDE_;
//! Gets all triangles which have or may have contact with a 3d line.
virtual void getTriangles(core::triangle3df* triangles, s32 arraySize,
s32& outTriangleCount, const core::line3d<f32>& line,
const core::matrix4* transform, bool useNodeTransform,
irr::core::array<SCollisionTriangleRange>* outTriangleInfo) const _IRR_OVERRIDE_;
//! Adds a triangle selector to the collection of triangle selectors
//! in this metaTriangleSelector.
virtual void addTriangleSelector(ITriangleSelector* toAdd) _IRR_OVERRIDE_;
//! Removes a specific triangle selector which was added before from the collection.
virtual bool removeTriangleSelector(ITriangleSelector* toRemove) _IRR_OVERRIDE_;
//! Removes all triangle selectors from the collection.
virtual void removeAllTriangleSelectors() _IRR_OVERRIDE_;
//! Get the scene node associated with a given triangle.
virtual ISceneNode* getSceneNodeForTriangle(u32 triangleIndex) const _IRR_OVERRIDE_;
// Get the number of TriangleSelectors that are part of this one
virtual u32 getSelectorCount() const _IRR_OVERRIDE_;
// Get the TriangleSelector based on index based on getSelectorCount
virtual ITriangleSelector* getSelector(u32 index) _IRR_OVERRIDE_;
// Get the TriangleSelector based on index based on getSelectorCount
virtual const ITriangleSelector* getSelector(u32 index) const _IRR_OVERRIDE_;
private:
core::array<ITriangleSelector*> TriangleSelectors;
};
} // end namespace scene
} // end namespace irr
#endif

View File

@ -1,277 +0,0 @@
// Copyright (C) 2002-2012 Nikolaus Gebhardt
// Copyright (C) 2009-2012 Christian Stehno
// This file is part of the "Irrlicht Engine".
// For conditions of distribution and use, see copyright notice in irrlicht.h
// Based on the NPK reader from Irrlicht
#include "CNPKReader.h"
#ifdef __IRR_COMPILE_WITH_NPK_ARCHIVE_LOADER_
#include "os.h"
#include "coreutil.h"
#ifdef _DEBUG
#define IRR_DEBUG_NPK_READER
#endif
namespace irr
{
namespace io
{
namespace
{
bool isHeaderValid(const SNPKHeader& header)
{
const c8* const tag = header.Tag;
return tag[0] == '0' &&
tag[1] == 'K' &&
tag[2] == 'P' &&
tag[3] == 'N';
}
} // end namespace
//! Constructor
CArchiveLoaderNPK::CArchiveLoaderNPK( io::IFileSystem* fs)
: FileSystem(fs)
{
#ifdef _DEBUG
setDebugName("CArchiveLoaderNPK");
#endif
}
//! returns true if the file maybe is able to be loaded by this class
bool CArchiveLoaderNPK::isALoadableFileFormat(const io::path& filename) const
{
return core::hasFileExtension(filename, "npk");
}
//! Check to see if the loader can create archives of this type.
bool CArchiveLoaderNPK::isALoadableFileFormat(E_FILE_ARCHIVE_TYPE fileType) const
{
return fileType == EFAT_NPK;
}
//! Creates an archive from the filename
/** \param file File handle to check.
\return Pointer to newly created archive, or 0 upon error. */
IFileArchive* CArchiveLoaderNPK::createArchive(const io::path& filename, bool ignoreCase, bool ignorePaths) const
{
IFileArchive *archive = 0;
io::IReadFile* file = FileSystem->createAndOpenFile(filename);
if (file)
{
archive = createArchive(file, ignoreCase, ignorePaths);
file->drop ();
}
return archive;
}
//! creates/loads an archive from the file.
//! \return Pointer to the created archive. Returns 0 if loading failed.
IFileArchive* CArchiveLoaderNPK::createArchive(io::IReadFile* file, bool ignoreCase, bool ignorePaths) const
{
IFileArchive *archive = 0;
if ( file )
{
file->seek ( 0 );
archive = new CNPKReader(file, ignoreCase, ignorePaths);
}
return archive;
}
//! Check if the file might be loaded by this class
/** Check might look into the file.
\param file File handle to check.
\return True if file seems to be loadable. */
bool CArchiveLoaderNPK::isALoadableFileFormat(io::IReadFile* file) const
{
SNPKHeader header;
file->read(&header, sizeof(header));
return isHeaderValid(header);
}
/*!
NPK Reader
*/
CNPKReader::CNPKReader(IReadFile* file, bool ignoreCase, bool ignorePaths)
: CFileList((file ? file->getFileName() : io::path("")), ignoreCase, ignorePaths), File(file)
{
#ifdef _DEBUG
setDebugName("CNPKReader");
#endif
if (File)
{
File->grab();
if (scanLocalHeader())
sort();
else
os::Printer::log("Failed to load NPK archive.");
}
}
CNPKReader::~CNPKReader()
{
if (File)
File->drop();
}
const IFileList* CNPKReader::getFileList() const
{
return this;
}
bool CNPKReader::scanLocalHeader()
{
SNPKHeader header;
// Read and validate the header
File->read(&header, sizeof(header));
if (!isHeaderValid(header))
return false;
// Seek to the table of contents
#ifdef __BIG_ENDIAN__
header.Offset = os::Byteswap::byteswap(header.Offset);
header.Length = os::Byteswap::byteswap(header.Length);
#endif
header.Offset += 8;
core::stringc dirName;
bool inTOC=true;
// Loop through each entry in the table of contents
while (inTOC && (File->getPos() < File->getSize()))
{
// read an entry
char tag[4]={0};
SNPKFileEntry entry;
File->read(tag, 4);
const int numTag = MAKE_IRR_ID(tag[3],tag[2],tag[1],tag[0]);
int size;
bool isDir=true;
switch (numTag)
{
case MAKE_IRR_ID('D','I','R','_'):
{
File->read(&size, 4);
readString(entry.Name);
entry.Length=0;
entry.Offset=0;
#ifdef IRR_DEBUG_NPK_READER
os::Printer::log("Dir", entry.Name);
#endif
}
break;
case MAKE_IRR_ID('F','I','L','E'):
{
File->read(&size, 4);
File->read(&entry.Offset, 4);
File->read(&entry.Length, 4);
readString(entry.Name);
isDir=false;
#ifdef IRR_DEBUG_NPK_READER
os::Printer::log("File", entry.Name);
#endif
#ifdef __BIG_ENDIAN__
entry.Offset = os::Byteswap::byteswap(entry.Offset);
entry.Length = os::Byteswap::byteswap(entry.Length);
#endif
}
break;
case MAKE_IRR_ID('D','E','N','D'):
{
File->read(&size, 4);
entry.Name="";
entry.Length=0;
entry.Offset=0;
const s32 pos = dirName.findLast('/', dirName.size()-2);
if (pos==-1)
dirName="";
else
dirName=dirName.subString(0, pos);
#ifdef IRR_DEBUG_NPK_READER
os::Printer::log("Dirend", dirName);
#endif
}
break;
default:
inTOC=false;
}
// skip root dir
if (isDir)
{
if (!entry.Name.size() || (entry.Name==".") || (entry.Name=="<noname>"))
continue;
dirName += entry.Name;
dirName += "/";
}
#ifdef IRR_DEBUG_NPK_READER
os::Printer::log("Name", entry.Name);
#endif
addItem((isDir?dirName:dirName+entry.Name), entry.Offset+header.Offset, entry.Length, isDir);
}
return true;
}
//! opens a file by file name
IReadFile* CNPKReader::createAndOpenFile(const io::path& filename)
{
s32 index = findFile(filename, false);
if (index != -1)
return createAndOpenFile(index);
return 0;
}
//! opens a file by index
IReadFile* CNPKReader::createAndOpenFile(u32 index)
{
if (index >= Files.size() )
return 0;
const SFileListEntry &entry = Files[index];
return createLimitReadFile( entry.FullName, File, entry.Offset, entry.Size );
}
void CNPKReader::readString(core::stringc& name)
{
short stringSize;
char buf[256];
File->read(&stringSize, 2);
#ifdef __BIG_ENDIAN__
stringSize = os::Byteswap::byteswap(stringSize);
#endif
name.reserve(stringSize);
while(stringSize)
{
const short next = core::min_(stringSize, (short)255);
File->read(buf,next);
buf[next]=0;
name.append(buf);
stringSize -= next;
}
}
} // end namespace io
} // end namespace irr
#endif // __IRR_COMPILE_WITH_NPK_ARCHIVE_LOADER_

View File

@ -1,125 +0,0 @@
// Copyright (C) 2002-2012 Nikolaus Gebhardt
// Copyright (C) 2009-2012 Christian Stehno
// This file is part of the "Irrlicht Engine".
// For conditions of distribution and use, see copyright notice in irrlicht.h
#ifndef __C_NPK_READER_H_INCLUDED__
#define __C_NPK_READER_H_INCLUDED__
#include "IrrCompileConfig.h"
#ifdef __IRR_COMPILE_WITH_NPK_ARCHIVE_LOADER_
#include "IReferenceCounted.h"
#include "IReadFile.h"
#include "irrArray.h"
#include "irrString.h"
#include "IFileSystem.h"
#include "CFileList.h"
namespace irr
{
namespace io
{
namespace
{
//! File header containing location and size of the table of contents
struct SNPKHeader
{
// Don't change the order of these fields! They must match the order stored on disk.
c8 Tag[4];
u32 Length;
u32 Offset;
};
//! An entry in the NPK file's table of contents.
struct SNPKFileEntry
{
core::stringc Name;
u32 Offset;
u32 Length;
};
} // end namespace
//! Archiveloader capable of loading Nebula Device 2 NPK Archives
class CArchiveLoaderNPK : public IArchiveLoader
{
public:
//! Constructor
CArchiveLoaderNPK(io::IFileSystem* fs);
//! returns true if the file maybe is able to be loaded by this class
//! based on the file extension (e.g. ".zip")
virtual bool isALoadableFileFormat(const io::path& filename) const _IRR_OVERRIDE_;
//! Check if the file might be loaded by this class
/** Check might look into the file.
\param file File handle to check.
\return True if file seems to be loadable. */
virtual bool isALoadableFileFormat(io::IReadFile* file) const _IRR_OVERRIDE_;
//! Check to see if the loader can create archives of this type.
/** Check based on the archive type.
\param fileType The archive type to check.
\return True if the archile loader supports this type, false if not */
virtual bool isALoadableFileFormat(E_FILE_ARCHIVE_TYPE fileType) const _IRR_OVERRIDE_;
//! Creates an archive from the filename
/** \param file File handle to check.
\return Pointer to newly created archive, or 0 upon error. */
virtual IFileArchive* createArchive(const io::path& filename, bool ignoreCase, bool ignorePaths) const _IRR_OVERRIDE_;
//! creates/loads an archive from the file.
//! \return Pointer to the created archive. Returns 0 if loading failed.
virtual io::IFileArchive* createArchive(io::IReadFile* file, bool ignoreCase, bool ignorePaths) const _IRR_OVERRIDE_;
private:
io::IFileSystem* FileSystem;
};
//! reads from NPK
class CNPKReader : public virtual IFileArchive, virtual CFileList
{
public:
CNPKReader(IReadFile* file, bool ignoreCase, bool ignorePaths);
virtual ~CNPKReader();
// file archive methods
//! return the id of the file Archive
virtual const io::path& getArchiveName() const _IRR_OVERRIDE_
{
return File->getFileName();
}
//! opens a file by file name
virtual IReadFile* createAndOpenFile(const io::path& filename) _IRR_OVERRIDE_;
//! opens a file by index
virtual IReadFile* createAndOpenFile(u32 index) _IRR_OVERRIDE_;
//! returns the list of files
virtual const IFileList* getFileList() const _IRR_OVERRIDE_;
//! get the class Type
virtual E_FILE_ARCHIVE_TYPE getType() const _IRR_OVERRIDE_ { return EFAT_NPK; }
private:
//! scans for a local header, returns false if the header is invalid
bool scanLocalHeader();
void readString(core::stringc& name);
IReadFile* File;
};
} // end namespace io
} // end namespace irr
#endif // __IRR_COMPILE_WITH_NPK_ARCHIVE_LOADER_
#endif // __C_NPK_READER_H_INCLUDED__

View File

@ -6,7 +6,6 @@
#ifdef _IRR_COMPILE_WITH_OBJ_LOADER_
#include "COBJMeshFileLoader.h"
#include "CMeshTextureLoader.h"
#include "IMeshManipulator.h"
#include "IVideoDriver.h"
#include "SMesh.h"
@ -39,8 +38,6 @@ COBJMeshFileLoader::COBJMeshFileLoader(scene::ISceneManager* smgr, io::IFileSyst
if (FileSystem)
FileSystem->grab();
TextureLoader = new CMeshTextureLoader( FileSystem, SceneManager->getVideoDriver() );
}
@ -69,9 +66,6 @@ IAnimatedMesh* COBJMeshFileLoader::createMesh(io::IReadFile* file)
if (!file)
return 0;
if ( getMeshTextureLoader() )
getMeshTextureLoader()->setMeshFile(file);
const long filesize = file->getSize();
if (!filesize)
return 0;
@ -119,7 +113,6 @@ IAnimatedMesh* COBJMeshFileLoader::createMesh(io::IReadFile* file)
#ifdef _IRR_DEBUG_OBJ_LOADER_
os::Printer::log("Reading material file",name);
#endif
readMTL(name, relPath);
}
}
break;
@ -358,352 +351,6 @@ IAnimatedMesh* COBJMeshFileLoader::createMesh(io::IReadFile* file)
return animMesh;
}
const c8* COBJMeshFileLoader::readTextures(const c8* bufPtr, const c8* const bufEnd, SObjMtl* currMaterial, const io::path& relPath)
{
u8 type=0; // map_Kd - diffuse color texture map
// map_Ks - specular color texture map
// map_Ka - ambient color texture map
// map_Ns - shininess texture map
if ((!strncmp(bufPtr,"map_bump",8)) || (!strncmp(bufPtr,"bump",4)))
type=1; // normal map
else if ((!strncmp(bufPtr,"map_d",5)) || (!strncmp(bufPtr,"map_opacity",11)))
type=2; // opacity map
else if (!strncmp(bufPtr,"map_refl",8))
type=3; // reflection map
// extract new material's name
c8 textureNameBuf[WORD_BUFFER_LENGTH];
bufPtr = goAndCopyNextWord(textureNameBuf, bufPtr, WORD_BUFFER_LENGTH, bufEnd);
f32 bumpiness = 6.0f;
bool clamp = false;
core::vector3df tscale(1.f); //For map_Kd texture scaling
core::vector3df tpos(0.f); //For map_Kd texture translation
// handle options
while (textureNameBuf[0]=='-')
{
if (!strncmp(bufPtr,"-bm",3))
{
bufPtr = goAndCopyNextWord(textureNameBuf, bufPtr, WORD_BUFFER_LENGTH, bufEnd);
currMaterial->Meshbuffer->Material.MaterialTypeParam=core::fast_atof(textureNameBuf);
bufPtr = goAndCopyNextWord(textureNameBuf, bufPtr, WORD_BUFFER_LENGTH, bufEnd);
continue;
}
else
if (!strncmp(bufPtr,"-blendu",7))
bufPtr = goAndCopyNextWord(textureNameBuf, bufPtr, WORD_BUFFER_LENGTH, bufEnd);
else
if (!strncmp(bufPtr,"-blendv",7))
bufPtr = goAndCopyNextWord(textureNameBuf, bufPtr, WORD_BUFFER_LENGTH, bufEnd);
else
if (!strncmp(bufPtr,"-cc",3))
bufPtr = goAndCopyNextWord(textureNameBuf, bufPtr, WORD_BUFFER_LENGTH, bufEnd);
else
if (!strncmp(bufPtr,"-clamp",6))
bufPtr = readBool(bufPtr, clamp, bufEnd);
else
if (!strncmp(bufPtr,"-texres",7))
bufPtr = goAndCopyNextWord(textureNameBuf, bufPtr, WORD_BUFFER_LENGTH, bufEnd);
else
if (!strncmp(bufPtr,"-type",5))
bufPtr = goAndCopyNextWord(textureNameBuf, bufPtr, WORD_BUFFER_LENGTH, bufEnd);
else
if (!strncmp(bufPtr,"-mm",3))
{
bufPtr = goAndCopyNextWord(textureNameBuf, bufPtr, WORD_BUFFER_LENGTH, bufEnd);
bufPtr = goAndCopyNextWord(textureNameBuf, bufPtr, WORD_BUFFER_LENGTH, bufEnd);
}
else
if (!strncmp(bufPtr,"-o",2)) // texture coord translation
{
bufPtr = goAndCopyNextWord(textureNameBuf, bufPtr, WORD_BUFFER_LENGTH, bufEnd);
if (core::isdigit(textureNameBuf[0]) || (textureNameBuf[0] == '-' && core::isdigit(textureNameBuf[1])))
tpos.X = core::fast_atof(textureNameBuf);
// next parameters are optional, so skip rest of loop if no number is found
bufPtr = goAndCopyNextWord(textureNameBuf, bufPtr, WORD_BUFFER_LENGTH, bufEnd);
if (!(core::isdigit(textureNameBuf[0]) || (textureNameBuf[0] == '-' && core::isdigit(textureNameBuf[1]))))
continue;
tpos.Y = core::fast_atof(textureNameBuf);
bufPtr = goAndCopyNextWord(textureNameBuf, bufPtr, WORD_BUFFER_LENGTH, bufEnd);
if (!(core::isdigit(textureNameBuf[0]) || (textureNameBuf[0] == '-' && core::isdigit(textureNameBuf[1]))))
continue;
tpos.Z = core::fast_atof(textureNameBuf);
}
else
if (!strncmp(bufPtr,"-s",2)) // texture coord scale
{
bufPtr = goAndCopyNextWord(textureNameBuf, bufPtr, WORD_BUFFER_LENGTH, bufEnd);
if (core::isdigit(textureNameBuf[0]) || (textureNameBuf[0] == '-' && core::isdigit(textureNameBuf[1])))
tscale.X = core::fast_atof(textureNameBuf);
// next parameters are optional, so skip rest of loop if no number is found
bufPtr = goAndCopyNextWord(textureNameBuf, bufPtr, WORD_BUFFER_LENGTH, bufEnd);
if (!(core::isdigit(textureNameBuf[0]) || (textureNameBuf[0] == '-' && core::isdigit(textureNameBuf[1]))))
continue;
tscale.Y = core::fast_atof(textureNameBuf);
bufPtr = goAndCopyNextWord(textureNameBuf, bufPtr, WORD_BUFFER_LENGTH, bufEnd);
if (!(core::isdigit(textureNameBuf[0]) || (textureNameBuf[0] == '-' && core::isdigit(textureNameBuf[1]))))
continue;
tscale.Z = core::fast_atof(textureNameBuf);
}
else
if (!strncmp(bufPtr,"-t",2))
{
bufPtr = goAndCopyNextWord(textureNameBuf, bufPtr, WORD_BUFFER_LENGTH, bufEnd);
// next parameters are optional, so skip rest of loop if no number is found
bufPtr = goAndCopyNextWord(textureNameBuf, bufPtr, WORD_BUFFER_LENGTH, bufEnd);
if (!(core::isdigit(textureNameBuf[0]) || (textureNameBuf[0] == '-' && core::isdigit(textureNameBuf[1]))))
continue;
bufPtr = goAndCopyNextWord(textureNameBuf, bufPtr, WORD_BUFFER_LENGTH, bufEnd);
if (!(core::isdigit(textureNameBuf[0]) || (textureNameBuf[0] == '-' && core::isdigit(textureNameBuf[1]))))
continue;
}
// get next word
bufPtr = goAndCopyNextWord(textureNameBuf, bufPtr, WORD_BUFFER_LENGTH, bufEnd);
}
if ((type==1) && (core::isdigit(textureNameBuf[0])))
{
currMaterial->Meshbuffer->Material.MaterialTypeParam=core::fast_atof(textureNameBuf);
bufPtr = goAndCopyNextWord(textureNameBuf, bufPtr, WORD_BUFFER_LENGTH, bufEnd);
}
if (clamp)
currMaterial->Meshbuffer->Material.setFlag(video::EMF_TEXTURE_WRAP, video::ETC_CLAMP);
io::path texname(textureNameBuf);
if (texname.size() && getMeshTextureLoader())
{
video::ITexture * texture = getMeshTextureLoader()->getTexture(texname);
if ( texture )
{
if (type==0)
{
currMaterial->Meshbuffer->Material.setTexture(0, texture);
bool needsTextureMatrix = tscale != core::vector3df(1.f) || tpos != core::vector3df(0.f);
if (needsTextureMatrix)
{
currMaterial->Meshbuffer->Material.getTextureMatrix(0).setTextureScale(tscale.X, tscale.Y);
currMaterial->Meshbuffer->Material.getTextureMatrix(0).setTextureTranslate(tpos.X, tpos.Y);
}
}
else if (type==1)
{
if ( texture->getSource() == video::ETS_FROM_FILE)
SceneManager->getVideoDriver()->makeNormalMapTexture(texture, bumpiness);
currMaterial->Meshbuffer->Material.setTexture(1, texture);
currMaterial->Meshbuffer->Material.MaterialType=video::EMT_PARALLAX_MAP_SOLID;
currMaterial->Meshbuffer->Material.MaterialTypeParam=0.035f;
}
else if (type==2)
{
currMaterial->Meshbuffer->Material.setTexture(0, texture);
currMaterial->Meshbuffer->Material.MaterialType=video::EMT_TRANSPARENT_ADD_COLOR;
}
else if (type==3)
{
// currMaterial->Meshbuffer->Material.Textures[1] = texture;
// currMaterial->Meshbuffer->Material.MaterialType=video::EMT_REFLECTION_2_LAYER;
}
// Set diffuse material color to white so as not to affect texture color
// Because Maya set diffuse color Kd to black when you use a diffuse color map
// But is this the right thing to do?
currMaterial->Meshbuffer->Material.DiffuseColor.set(
currMaterial->Meshbuffer->Material.DiffuseColor.getAlpha(), 255, 255, 255 );
}
}
return bufPtr;
}
void COBJMeshFileLoader::readMTL(const c8* fileName, const io::path& relPath)
{
const io::path realFile(fileName);
io::IReadFile * mtlReader;
if (FileSystem->existFile(realFile))
mtlReader = FileSystem->createAndOpenFile(realFile);
else if (FileSystem->existFile(relPath + realFile))
mtlReader = FileSystem->createAndOpenFile(relPath + realFile);
else if (FileSystem->existFile(FileSystem->getFileBasename(realFile)))
mtlReader = FileSystem->createAndOpenFile(FileSystem->getFileBasename(realFile));
else
mtlReader = FileSystem->createAndOpenFile(relPath + FileSystem->getFileBasename(realFile));
if (!mtlReader) // fail to open and read file
{
os::Printer::log("Could not open material file", realFile, ELL_WARNING);
return;
}
if ( getMeshTextureLoader() )
{
getMeshTextureLoader()->setMaterialFile(mtlReader);
if ( SceneManager->getParameters()->existsAttribute(OBJ_TEXTURE_PATH) )
getMeshTextureLoader()->setTexturePath(SceneManager->getParameters()->getAttributeAsString(OBJ_TEXTURE_PATH));
}
const long filesize = mtlReader->getSize();
if (!filesize)
{
os::Printer::log("Skipping empty material file", realFile, ELL_WARNING);
mtlReader->drop();
return;
}
c8* buf = new c8[filesize];
mtlReader->read((void*)buf, filesize);
const c8* bufEnd = buf+filesize;
SObjMtl* currMaterial = 0;
const c8* bufPtr = buf;
while(bufPtr != bufEnd)
{
switch(*bufPtr)
{
case 'n': // newmtl
{
// if there's an existing material, store it first
if ( currMaterial )
Materials.push_back( currMaterial );
// extract new material's name
c8 mtlNameBuf[WORD_BUFFER_LENGTH];
bufPtr = goAndCopyNextWord(mtlNameBuf, bufPtr, WORD_BUFFER_LENGTH, bufEnd);
currMaterial = new SObjMtl;
currMaterial->Name = mtlNameBuf;
}
break;
case 'i': // illum - illumination
if ( currMaterial )
{
const u32 COLOR_BUFFER_LENGTH = 16;
c8 illumStr[COLOR_BUFFER_LENGTH];
bufPtr = goAndCopyNextWord(illumStr, bufPtr, COLOR_BUFFER_LENGTH, bufEnd);
currMaterial->Illumination = (c8)atol(illumStr);
}
break;
case 'N':
if ( currMaterial )
{
switch(bufPtr[1])
{
case 's': // Ns - shininess
{
const u32 COLOR_BUFFER_LENGTH = 16;
c8 nsStr[COLOR_BUFFER_LENGTH];
bufPtr = goAndCopyNextWord(nsStr, bufPtr, COLOR_BUFFER_LENGTH, bufEnd);
f32 shininessValue = core::fast_atof(nsStr);
// wavefront shininess is from [0, 1000], so scale for OpenGL
shininessValue *= 0.128f;
currMaterial->Meshbuffer->Material.Shininess = shininessValue;
}
break;
case 'i': // Ni - refraction index
{
c8 tmpbuf[WORD_BUFFER_LENGTH];
bufPtr = goAndCopyNextWord(tmpbuf, bufPtr, WORD_BUFFER_LENGTH, bufEnd);
}
break;
}
}
break;
case 'K':
if ( currMaterial )
{
switch(bufPtr[1])
{
case 'd': // Kd = diffuse
{
bufPtr = readColor(bufPtr, currMaterial->Meshbuffer->Material.DiffuseColor, bufEnd);
}
break;
case 's': // Ks = specular
{
bufPtr = readColor(bufPtr, currMaterial->Meshbuffer->Material.SpecularColor, bufEnd);
}
break;
case 'a': // Ka = ambience
{
bufPtr=readColor(bufPtr, currMaterial->Meshbuffer->Material.AmbientColor, bufEnd);
}
break;
case 'e': // Ke = emissive
{
currMaterial->Meshbuffer->Material.EmissiveColor.setAlpha(255);
bufPtr=readColor(bufPtr, currMaterial->Meshbuffer->Material.EmissiveColor, bufEnd);
}
break;
} // end switch(bufPtr[1])
} // end case 'K': if ( 0 != currMaterial )...
break;
case 'b': // bump
case 'm': // texture maps
if (currMaterial)
{
bufPtr=readTextures(bufPtr, bufEnd, currMaterial, relPath);
}
break;
case 'd': // d - transparency
if ( currMaterial )
{
const u32 COLOR_BUFFER_LENGTH = 16;
c8 dStr[COLOR_BUFFER_LENGTH];
bufPtr = goAndCopyNextWord(dStr, bufPtr, COLOR_BUFFER_LENGTH, bufEnd);
f32 dValue = core::fast_atof(dStr);
currMaterial->Meshbuffer->Material.DiffuseColor.setAlpha( (s32)(dValue * 255) );
if (dValue<1.0f)
currMaterial->Meshbuffer->Material.MaterialType = video::EMT_TRANSPARENT_VERTEX_ALPHA;
}
break;
case 'T':
if ( currMaterial )
{
switch ( bufPtr[1] )
{
case 'f': // Tf - Transmitivity
const u32 COLOR_BUFFER_LENGTH = 16;
c8 redStr[COLOR_BUFFER_LENGTH];
c8 greenStr[COLOR_BUFFER_LENGTH];
c8 blueStr[COLOR_BUFFER_LENGTH];
bufPtr = goAndCopyNextWord(redStr, bufPtr, COLOR_BUFFER_LENGTH, bufEnd);
bufPtr = goAndCopyNextWord(greenStr, bufPtr, COLOR_BUFFER_LENGTH, bufEnd);
bufPtr = goAndCopyNextWord(blueStr, bufPtr, COLOR_BUFFER_LENGTH, bufEnd);
f32 transparency = ( core::fast_atof(redStr) + core::fast_atof(greenStr) + core::fast_atof(blueStr) ) / 3;
currMaterial->Meshbuffer->Material.DiffuseColor.setAlpha( (s32)(transparency * 255) );
if (transparency < 1.0f)
currMaterial->Meshbuffer->Material.MaterialType = video::EMT_TRANSPARENT_VERTEX_ALPHA;
}
}
break;
default: // comments or not recognised
break;
} // end switch(bufPtr[0])
// go to next line
bufPtr = goNextLine(bufPtr, bufEnd);
} // end while (bufPtr)
// end of file. if there's an existing material, store it
if ( currMaterial )
Materials.push_back( currMaterial );
delete [] buf;
mtlReader->drop();
}
//! Read RGB color
const c8* COBJMeshFileLoader::readColor(const c8* bufPtr, video::SColor& color, const c8* const bufEnd)
{

View File

@ -70,9 +70,6 @@ private:
bool RecalculateNormals;
};
// helper method for material reading
const c8* readTextures(const c8* bufPtr, const c8* const bufEnd, SObjMtl* currMaterial, const io::path& relPath);
// returns a pointer to the first printable character available in the buffer
const c8* goFirstWord(const c8* buf, const c8* const bufEnd, bool acrossNewlines=true);
// returns a pointer to the first printable character after the first non-printable
@ -87,9 +84,6 @@ private:
// combination of goNextWord followed by copyWord
const c8* goAndCopyNextWord(c8* outBuf, const c8* inBuf, u32 outBufLength, const c8* const pBufEnd);
//! Read the material from the given file
void readMTL(const c8* fileName, const io::path& relPath);
//! Find and return the material with the given name
SObjMtl* findMtl(const core::stringc& mtlName, const core::stringc& grpName);

View File

@ -1,282 +0,0 @@
// Copyright (C) 2008-2012 Christian Stehno
// This file is part of the "Irrlicht Engine".
// For conditions of distribution and use, see copyright notice in irrlicht.h
#include "IrrCompileConfig.h"
#ifdef _IRR_COMPILE_WITH_OBJ_WRITER_
#include "COBJMeshWriter.h"
#include "os.h"
#include "IMesh.h"
#include "IMeshBuffer.h"
#include "IAttributes.h"
#include "ISceneManager.h"
#include "IMeshCache.h"
#include "IWriteFile.h"
#include "IFileSystem.h"
#include "ITexture.h"
namespace irr
{
namespace scene
{
COBJMeshWriter::COBJMeshWriter(scene::ISceneManager* smgr, io::IFileSystem* fs)
: SceneManager(smgr), FileSystem(fs)
{
#ifdef _DEBUG
setDebugName("COBJMeshWriter");
#endif
if (SceneManager)
SceneManager->grab();
if (FileSystem)
FileSystem->grab();
}
COBJMeshWriter::~COBJMeshWriter()
{
if (SceneManager)
SceneManager->drop();
if (FileSystem)
FileSystem->drop();
}
//! Returns the type of the mesh writer
EMESH_WRITER_TYPE COBJMeshWriter::getType() const
{
return EMWT_OBJ;
}
//! writes a mesh
bool COBJMeshWriter::writeMesh(io::IWriteFile* file, scene::IMesh* mesh, s32 flags)
{
if (!file)
return false;
os::Printer::log("Writing mesh", file->getFileName());
// write OBJ MESH header
io::path name;
core::cutFilenameExtension(name,file->getFileName()) += ".mtl";
file->write("# exported by Irrlicht\n",23);
file->write("mtllib ",7);
file->write(name.c_str(),name.size());
file->write("\n\n",2);
// write mesh buffers
core::array<video::SMaterial*> mat;
u32 allVertexCount=1; // count vertices over the whole file
for (u32 i=0; i<mesh->getMeshBufferCount(); ++i)
{
core::stringc num(i+1);
IMeshBuffer* buffer = mesh->getMeshBuffer(i);
if (buffer && buffer->getVertexCount())
{
file->write("g grp", 5);
file->write(num.c_str(), num.size());
file->write("\n",1);
u32 j;
const u32 vertexCount = buffer->getVertexCount();
for (j=0; j<vertexCount; ++j)
{
file->write("v ",2);
getVectorAsStringLine(buffer->getPosition(j), num);
file->write(num.c_str(), num.size());
}
for (j=0; j<vertexCount; ++j)
{
file->write("vt ",3);
getVectorAsStringLine(buffer->getTCoords(j), num);
file->write(num.c_str(), num.size());
}
for (j=0; j<vertexCount; ++j)
{
file->write("vn ",3);
getVectorAsStringLine(buffer->getNormal(j), num);
file->write(num.c_str(), num.size());
}
file->write("usemtl mat",10);
num = "";
for (j=0; j<mat.size(); ++j)
{
if (*mat[j]==buffer->getMaterial())
{
num = core::stringc(j);
break;
}
}
if (num == "")
{
num = core::stringc(mat.size());
mat.push_back(&buffer->getMaterial());
}
file->write(num.c_str(), num.size());
file->write("\n",1);
const u32 indexCount = buffer->getIndexCount();
for (j=0; j<indexCount; j+=3)
{
file->write("f ",2);
num = core::stringc(buffer->getIndices()[j+2]+allVertexCount);
file->write(num.c_str(), num.size());
file->write("/",1);
file->write(num.c_str(), num.size());
file->write("/",1);
file->write(num.c_str(), num.size());
file->write(" ",1);
num = core::stringc(buffer->getIndices()[j+1]+allVertexCount);
file->write(num.c_str(), num.size());
file->write("/",1);
file->write(num.c_str(), num.size());
file->write("/",1);
file->write(num.c_str(), num.size());
file->write(" ",1);
num = core::stringc(buffer->getIndices()[j+0]+allVertexCount);
file->write(num.c_str(), num.size());
file->write("/",1);
file->write(num.c_str(), num.size());
file->write("/",1);
file->write(num.c_str(), num.size());
file->write(" ",1);
file->write("\n",1);
}
file->write("\n",1);
allVertexCount += vertexCount;
}
}
if (mat.size() == 0)
return true;
file = FileSystem->createAndWriteFile( name );
if (file)
{
os::Printer::log("Writing material", file->getFileName());
file->write("# exported by Irrlicht\n\n",24);
for (u32 i=0; i<mat.size(); ++i)
{
core::stringc num(i);
file->write("newmtl mat",10);
file->write(num.c_str(),num.size());
file->write("\n",1);
getColorAsStringLine(mat[i]->AmbientColor, "Ka", num);
file->write(num.c_str(),num.size());
getColorAsStringLine(mat[i]->DiffuseColor, "Kd", num);
file->write(num.c_str(),num.size());
getColorAsStringLine(mat[i]->SpecularColor, "Ks", num);
file->write(num.c_str(),num.size());
getColorAsStringLine(mat[i]->EmissiveColor, "Ke", num);
file->write(num.c_str(),num.size());
num = core::stringc((double)(mat[i]->Shininess/0.128f));
file->write("Ns ", 3);
file->write(num.c_str(),num.size());
file->write("\n", 1);
if (mat[i]->getTexture(0))
{
file->write("map_Kd ", 7);
f32 tposX, tposY, tscaleX, tscaleY;
const core::matrix4& textureMatrix = mat[i]->getTextureMatrix(0);
textureMatrix.getTextureTranslate(tposX, tposY);
textureMatrix.getTextureScale(tscaleX, tscaleY);
//Write texture translation values
if ( !core::equals(tposX, 0.f) || !core::equals(tposY, 0.f) )
{
file->write("-o ", 3);
core::stringc tx(tposX);
core::stringc ty(tposY);
file->write(tx.c_str(), tx.size());
file->write(" ", 1);
file->write(ty.c_str(), ty.size());
file->write(" ", 1);
}
//Write texture scaling values
if ( !core::equals(tscaleX, 1.f) || !core::equals(tscaleY, 1.f) )
{
file->write("-s ", 3);
core::stringc sx(tscaleX);
core::stringc sy(tscaleY);
file->write(sx.c_str(), sx.size());
file->write(" ", 1);
file->write(sy.c_str(), sy.size());
file->write(" ", 1);
}
io::path tname = FileSystem->getRelativeFilename(mat[i]->getTexture(0)->getName(),
FileSystem->getFileDir(file->getFileName()));
// avoid blanks as .obj cannot handle strings with spaces
if (tname.findFirst(' ') != -1)
tname = FileSystem->getFileBasename(tname);
file->write(tname.c_str(), tname.size());
file->write("\n",1);
}
file->write("\n",1);
}
file->drop();
}
return true;
}
void COBJMeshWriter::getVectorAsStringLine(const core::vector3df& v, core::stringc& s) const
{
s = core::stringc(-v.X);
s += " ";
s += core::stringc(v.Y);
s += " ";
s += core::stringc(v.Z);
s += "\n";
}
void COBJMeshWriter::getVectorAsStringLine(const core::vector2df& v, core::stringc& s) const
{
s = core::stringc(v.X);
s += " ";
s += core::stringc(1-v.Y);
s += "\n";
}
void COBJMeshWriter::getColorAsStringLine(const video::SColor& color, const c8* const prefix, core::stringc& s) const
{
s = prefix;
s += " ";
s += core::stringc((double)(color.getRed()/255.f));
s += " ";
s += core::stringc((double)(color.getGreen()/255.f));
s += " ";
s += core::stringc((double)(color.getBlue()/255.f));
s += "\n";
}
} // end namespace
} // end namespace
#endif

View File

@ -1,58 +0,0 @@
// Copyright (C) 2008-2012 Christian Stehno
// This file is part of the "Irrlicht Engine".
// For conditions of distribution and use, see copyright notice in irrlicht.h
#ifndef __IRR_OBJ_MESH_WRITER_H_INCLUDED__
#define __IRR_OBJ_MESH_WRITER_H_INCLUDED__
#include "IMeshWriter.h"
#include "S3DVertex.h"
#include "irrString.h"
namespace irr
{
namespace io
{
class IFileSystem;
} // end namespace io
namespace scene
{
class IMeshBuffer;
class ISceneManager;
//! class to write meshes, implementing a OBJ writer
class COBJMeshWriter : public IMeshWriter
{
public:
COBJMeshWriter(scene::ISceneManager* smgr, io::IFileSystem* fs);
virtual ~COBJMeshWriter();
//! Returns the type of the mesh writer
virtual EMESH_WRITER_TYPE getType() const _IRR_OVERRIDE_;
//! writes a mesh
virtual bool writeMesh(io::IWriteFile* file, scene::IMesh* mesh, s32 flags=EMWF_NONE) _IRR_OVERRIDE_;
protected:
// create vector output with line end into string
void getVectorAsStringLine(const core::vector3df& v,
core::stringc& s) const;
// create vector output with line end into string
void getVectorAsStringLine(const core::vector2df& v,
core::stringc& s) const;
// create color output with line end into string
void getColorAsStringLine(const video::SColor& color,
const c8* const prefix, core::stringc& s) const;
scene::ISceneManager* SceneManager;
io::IFileSystem* FileSystem;
};
} // end namespace
} // end namespace
#endif

Some files were not shown because too many files have changed in this diff Show More