--- Irrlicht.org/CSceneManager.cpp 2006-03-22 11:35:15.000000000 +0100 +++ Irrlicht.new/CSceneManager.cpp 2006-03-30 17:40:43.000000000 +0200 @@ -15,6 +15,7 @@ #include "CDefaultMeshFormatLoader.h" #include "C3DSMeshFileLoader.h" +#include "CASEMeshFileLoader.h" #include "CXMeshFileLoader.h" #include "COCTLoader.h" #include "CCSMLoader.h" @@ -100,6 +102,7 @@ MeshLoaderList.push_back(new CDefaultMeshFormatLoader(FileSystem, Driver)); MeshLoaderList.push_back(new C3DSMeshFileLoader(FileSystem, Driver)); + MeshLoaderList.push_back(new CASEMeshFileLoader(FileSystem, Driver)); MeshLoaderList.push_back(new CXMeshFileLoader(MeshManipulator, Driver)); MeshLoaderList.push_back(new COCTLoader(Driver)); MeshLoaderList.push_back(new CCSMLoader(this, FileSystem)); --- Irrlicht.org/CASEMeshFileLoader.h 2006-04-03 13:25:32.897849131 +0200 +++ Irrlicht.new/CASEMeshFileLoader.h 2006-04-03 13:26:05.851761692 +0200 @@ -0,0 +1,49 @@ +// Copyright (C) 2002-2005 Nikolaus Gebhardt +// This file is part of the "Irrlicht Engine". +// For conditions of distribution and use, see copyright notice in irrlicht.h + +#ifndef __C_ASE_MESH_FILE_LOADER_H_INCLUDED__ +#define __C_ASE_MESH_FILE_LOADER_H_INCLUDED__ + +#include "IMeshLoader.h" +#include "IFileSystem.h" +#include "IVideoDriver.h" +#include "SMesh.h" + +namespace irr +{ +namespace scene +{ + +//! Meshloader capable of loading ase meshes. +class CASEMeshFileLoader : public IMeshLoader +{ +public: + + //! Constructor + CASEMeshFileLoader(io::IFileSystem* fs, video::IVideoDriver* driver); + + //! destructor + virtual ~CASEMeshFileLoader(); + + //! 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 c8* 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 IUnknown::drop() for more information. + virtual IAnimatedMesh* createMesh(irr::io::IReadFile* file); + +private: + io::IFileSystem* FileSystem; + video::IVideoDriver* Driver; + SMesh* Mesh; +}; + +} // end namespace scene +} // end namespace irr + +#endif + --- Irrlicht.org/CASEMeshFileLoader.cpp 2006-04-03 13:25:35.135503652 +0200 +++ Irrlicht.new/CASEMeshFileLoader.cpp 2006-04-03 13:26:07.323534500 +0200 @@ -0,0 +1,143 @@ +// Copyright (C) 2002-2005 Nikolaus Gebhardt +// This file is part of the "Irrlicht Engine". +// For conditions of distribution and use, see copyright notice in irrlicht.h + +#include "CASEMeshFileLoader.h" +#include "libASE.h" +#include "os.h" +#include "irrString.h" +#include "SMeshBuffer.h" +#include "SAnimatedMesh.h" + +namespace irr +{ +namespace scene +{ + +//! Constructor +CASEMeshFileLoader::CASEMeshFileLoader(io::IFileSystem* fs, video::IVideoDriver* driver) +: FileSystem(fs), Driver(driver), Mesh(0) +{ + if (FileSystem) + FileSystem->grab(); + + if (Driver) + Driver->grab(); +} + + + +//! destructor +CASEMeshFileLoader::~CASEMeshFileLoader() +{ + if (FileSystem) + FileSystem->drop(); + + if (Driver) + Driver->drop(); + + if (Mesh) + Mesh->drop(); +} + + + +//! returns true if the file maybe is able to be loaded by this class +//! based on the file extension (e.g. ".bsp") +bool CASEMeshFileLoader::isALoadableFileExtension(const c8* filename) +{ + return strstr(filename, ".ase")!=0; +} + + + +//! 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. +IAnimatedMesh* CASEMeshFileLoader::createMesh(io::IReadFile* file) +{ + core::stringc filename(file->getFileName()); + ASE_Scene* scene = ASE_loadFilename(filename.c_str()); + + if (!scene) + return 0; + + if (Mesh) + Mesh->drop(); + Mesh = new SMesh(); + + for (int i=0; iobjectCount; ++i) { + SMeshBuffer* mb = new scene::SMeshBuffer(); + Mesh->addMeshBuffer(mb); + mb->drop(); + mb->Material.MaterialType = video::EMT_SOLID; + ASE_Mesh asemesh = scene->objs[i].mesh; + for (int j=0; jgetVertexCount(); + for (int k=0; k<3; ++k) { + int vertInd = asemesh.faces[j].vertex[k]; + video::S3DVertex vtx; + if (asemesh.colorCount) { + vtx.Color=video::SColorf(asemesh.colors[vertInd].x,asemesh.colors[vertInd].y,asemesh.colors[vertInd].z).toSColor(); + } else { + vtx.Color.set(255,255,255,255); + } + vtx.Pos.X = asemesh.vertices[vertInd].x; + vtx.Pos.Y = asemesh.vertices[vertInd].y; + vtx.Pos.Z = asemesh.vertices[vertInd].z; + vtx.Normal.X = asemesh.vertex_normals[j+k].x; + vtx.Normal.Y = asemesh.vertex_normals[j+k].y; + vtx.Normal.Z = asemesh.vertex_normals[j+k].z; + if (asemesh.texture_coordinates) { + vtx.TCoords.X = asemesh.texture_coordinates[asemesh.faces[j].texture_coordinates[k]].x; + vtx.TCoords.Y = asemesh.texture_coordinates[asemesh.faces[j].texture_coordinates[k]].y; + } + mb->Vertices.push_back(vtx); + } + mb->Indices.push_back(idx); + mb->Indices.push_back(idx+1); + mb->Indices.push_back(idx+2); + } + if (scene->materials) { + ASE_Material mat=scene->materials[scene->objs[i].material]; + mb->Material.AmbientColor=video::SColorf(mat.ambient.r,mat.ambient.g,mat.ambient.b).toSColor(); + mb->Material.DiffuseColor=video::SColorf(mat.diffuse.r,mat.diffuse.g,mat.diffuse.b).toSColor(); + mb->Material.SpecularColor=video::SColorf(mat.specular.r,mat.specular.g,mat.specular.b).toSColor(); + mb->Material.Shininess=mat.shine; + if (mat.transparency>0.0f) { + mb->Material.MaterialTypeParam=mat.transparency; + mb->Material.MaterialType=video::EMT_TRANSPARENT_VERTEX_ALPHA; + } + if (mat.diffuseMaterialMap.image_path) { + video::ITexture* texture = Driver->getTexture(mat.diffuseMaterialMap.image_path); + if (texture) + mb->Material.Texture1=texture; + } + if (mat.bumpMaterialMap.image_path) { + video::ITexture* texture = Driver->getTexture(mat.bumpMaterialMap.image_path); + if (texture) { + mb->Material.Texture2=texture; + mb->Material.MaterialType = video::EMT_PARALLAX_MAP_SOLID; + } + } + } + } + SAnimatedMesh* am = new SAnimatedMesh(); + am->Type = EAMT_3DS; + + for (s32 i=0; igetMeshBufferCount(); ++i) + ((SMeshBuffer*)Mesh->getMeshBuffer(i))->recalculateBoundingBox(); + + Mesh->recalculateBoundingBox(); + + am->addMesh(Mesh); + am->recalculateBoundingBox(); + Mesh->drop(); + Mesh = 0; + return am; +} + +} // end namespace scene +} // end namespace irr +