49 #define ID_3D_EDITOR_CHUNK 0x3D3D 50 #define ID_MAIN_CHUNK 0x4D4D 51 #define ID_3DS_VERSION 0x0002 52 #define ID_OBJECT_BLOCK 0x4000 53 #define ID_MATERIAL_BLOCK 0xAFFF 54 #define ID_COLOR_F 0x0010 55 #define ID_COLOR_24 0x0011 56 #define ID_LIN_COLOR_24 0x0012 57 #define ID_LIN_COLOR_F 0x0013 58 #define ID_INT_PERCENTAGE 0x0030 59 #define ID_FLOAT_PERCENTAGE 0x0031 60 #define ID_MATERIAL_NAME 0xA000 61 #define ID_MAT_AMBIENT 0xA010 62 #define ID_MAT_DIFFUSE 0xA020 63 #define ID_MAT_SPECULAR 0xA030 64 #define ID_MAT_SHININESS_PERCENT 0xA040 65 #define ID_MAT_SHININESS_STRENGTH_PERCENT 0xA041 66 #define ID_MAT_TRANSPARENCY 0xA050 67 #define ID_MAT_TWO_SIDE 0xA081 68 #define ID_MAT_TEXMAP 0xA200 69 #define ID_MAT_TEXMAP2 0xA33A 70 #define ID_MAT_MAPNAME 0xA300 71 #define ID_MAT_MAP_TILING 0xA351 72 #define ID_MAT_USCALE 0xA354 73 #define ID_MAT_VSCALE 0xA356 74 #define ID_MAT_UOFFSET 0xA358 75 #define ID_MAT_VOFFSET 0xA35A 76 #define ID_MAT_MAP_ROTATION 0xA35C 77 #define ID_TRIANGULAR_MESH 0x4100 78 #define ID_LOCAL_COORDS_SYSTEM 0x4160 79 #define ID_MAPPING_COORDS 0x4140 80 #define ID_SMOOTHING_GROUP_LIST 0x4150 81 #define ID_FACE_MATERIAL_LIST 0x4130 82 #define ID_FACE_LIST 0x4120 83 #define ID_VERTEX_LIST 0x4110 84 #define ID_HIERARCHY 0x4F00 85 #define ID_PARENT_OBJECT 0x4F10 86 #define ID_PIVOT_OBJECT 0x4F20 87 #define ID_PIVOT_LIMITS 0x4F30 88 #define ID_PIVOT_ORDER 0x4F40 89 #define ID_XLATE_RANGE 0x4F50 91 #define ID_KEYFRAMER_CHUNK 0xB000 92 #define ID_KEYF_OBJDES 0xB002 // Mesh Information Block 93 #define ID_KEYF_OBJHIERARCH 0xB010 // Object Name And Hierarchy 94 #define ID_KEYF_OBJPIVOT 0xB013 // Object Pivot Point 95 #define ID_KEYF_POSITION_TRACK 0xB020 // Position Track + Pivot 96 #define ID_KEYF_ROTATION_TRACK 0xB021 // Rotation Track 97 #define ID_KEYF_SCALE_TRACK 0xB022 // Scale Track 98 #define ID_KEYF_NODE_ID 0xB030 // Node ID 99 #define ID_KEY_SPOTLIGHT_NODE_TAG 0xB007 // Spot Light Information Block 100 #define ID_KEY_FRAMES_START_END 0xB008 // Frames (Start and End) 138 std::vector<unsigned char> str;
145 return (
char*)&str[0];
390 int bit[10] = { flags&(1<<0), flags&(1<<1), flags&(1<<2), flags&(1<<3),
391 flags&(1<<4), flags&(1<<5), flags&(1<<6), flags&(1<<7),
392 flags&(1<<8), flags&(1<<9) };
393 tex.
mOpt_tile = (!bit[4] && !bit[0]) || (!bit[4] && bit[1]);
394 tex.
mOpt_decal = (bit[4] && bit[0]) || (!bit[4] && bit[1]);
504 mObjects.back().mVertices.resize(vertc);
506 std::vector<fvec3> verts;
509 for(
unsigned short i=0; i<vertc; ++i)
510 mObjects.back().mVertices[i].mPos = verts[i];
512 for(
unsigned short i=0; i<vertc; ++i)
523 mObjects.back().mFaceList.resize(facec);
525 std::vector<unsigned short> faces;
526 faces.resize(facec*4);
528 for(
unsigned short i=0; i<facec; ++i)
530 mObjects.back().mFaceList[i].mA = faces[i*4+0];
531 mObjects.back().mFaceList[i].mB = faces[i*4+1];
532 mObjects.back().mFaceList[i].mC = faces[i*4+2];
533 mObjects.back().mFaceList[i].mFlags = faces[i*4+3];
536 for(
unsigned short i=0; i<facec; ++i)
554 mObjects.back().mMatFaceMap.back().mMaterialName = name;
555 mObjects.back().mMatFaceMap.back().mMappedFace.resize(facec);
559 for(
unsigned short i=0; i<facec; ++i)
562 mObjects.back().mMatFaceMap.back().mMappedFace[i] = face;
571 if (
mObjects.back().mFaceList.empty())
573 std::vector<unsigned int> group;
574 group.resize(
mObjects.back().mFaceList.size());
576 for(
unsigned short i=0; i<
mObjects.back().mFaceList.size(); ++i)
577 mObjects.back().mFaceList[i].mSmoothingGroup = group[i];
579 for(
unsigned short i=0; i<
mObjects.back().mFaceList.size(); ++i)
590 mObjects.back().mVertices.resize(vertc);
592 std::vector<fvec2> tuvs;
595 for(
unsigned short i=0; i<vertc; ++i)
596 mObjects.back().mVertices[i].mUV = tuvs[i];
598 for(
unsigned short i=0; i<vertc; ++i)
603 mObjects.back().mVertices[i].mUV = uv;
714 std::map< String, ref<Effect> > mat_map;
716 for(
unsigned int iobj=0; iobj<loader.
mObjects.size(); ++iobj)
718 if (loader.
mObjects[iobj].mVertices.empty())
721 if (loader.
mObjects[iobj].mFaceList.empty())
725 for(
unsigned imat_map=0; imat_map<loader.
mObjects[iobj].mMatFaceMap.size() || (imat_map==0&&loader.
mObjects[iobj].mMatFaceMap.empty()); ++imat_map)
729 if (!loader.
mObjects[iobj].mMatFaceMap.empty())
731 for(
unsigned imat=0; imat<loader.
mMaterials.size(); ++imat)
733 if (loader.
mObjects[iobj].mMatFaceMap[imat_map].mMaterialName == loader.
mMaterials[imat].mMaterialName)
744 for(
unsigned int iface=0; iface<loader.
mObjects[iobj].mMatFaceMap[imat_map].mMappedFace.size(); iface++)
746 int face_index = loader.
mObjects[iobj].mMatFaceMap[imat_map].mMappedFace[iface];
747 loader.
mObjects[iobj].mFaceList[face_index].mMaterialIndex = mat_index;
758 std::set<A3DSVertex> vertex_set;
759 std::vector<unsigned int> index_buffer;
760 index_buffer.resize( 3 * loader.
mObjects[iobj].mFaceList.size() );
761 int index_counter = 0;
762 for(
unsigned int iface=0; iface<loader.
mObjects[iobj].mFaceList.size(); iface++)
764 if ( loader.
mObjects[iobj].mFaceList[iface].mMaterialIndex != mat_index )
767 unsigned int vertidx[] =
769 loader.
mObjects[iobj].mFaceList[iface].mA,
770 loader.
mObjects[iobj].mFaceList[iface].mB,
771 loader.
mObjects[iobj].mFaceList[iface].mC
774 for(
int iv=0; iv<3; ++iv)
777 if (vertidx[iv]>=loader.
mObjects[iobj].mVertices.size())
779 Log::error(
"index out of range, 3ds file is corrupted.\n");
782 v = loader.
mObjects[iobj].mVertices[ vertidx[iv] ];
784 std::set<A3DSVertex>::iterator it = vertex_set.find(v);
785 if (it == vertex_set.end())
788 vertex_set.insert(v);
793 index_buffer[iface*3+iv] = v.
mIndex;
797 if (index_counter == 0)
811 vert_interf->
resize( index_counter );
812 tuvs_interf->
resize( index_counter );
813 for(std::set<A3DSVertex>::iterator ivert=vertex_set.begin(); ivert!=vertex_set.end(); ++ivert)
815 vert_interf->
at(ivert->mIndex).
x() = ivert->mPos.x();
816 vert_interf->
at(ivert->mIndex).
y() = ivert->mPos.z();
817 vert_interf->
at(ivert->mIndex).
z() =-ivert->mPos.y();
818 tuvs_interf->
at(ivert->mIndex) = ivert->mUV;
835 if ( mat_index != -1 )
838 if (mat_map[mat_name].
get() ==
NULL)
840 mat_map[mat_name] =
new Effect;
841 res_db->
resources().push_back(mat_map[mat_name].
get());
843 mat_map[mat_name]->setObjectName(mat_name.
toStdString().c_str());
845 float alpha = 1.0f - loader.
mMaterials[mat_index].mTransparency;
849 specular *= loader.
mMaterials[mat_index].mShininessStrength;
850 mat_map[mat_name]->shader()->gocMaterial()->setAmbient( ambient );
851 mat_map[mat_name]->shader()->gocMaterial()->setDiffuse( diffuse );
852 mat_map[mat_name]->shader()->gocMaterial()->setSpecular( specular );
853 mat_map[mat_name]->shader()->gocMaterial()->setShininess( loader.
mMaterials[mat_index].mShininess * 128.0f );
858 if (alpha<1.0f || loader.
mMaterials[mat_index].mTexture1.mOpt_use_alpha)
860 mat_map[mat_name]->shader()->enable(
EN_BLEND);
867 if ( !loader.
mMaterials[mat_index].mTexture1.mFileName.empty() )
871 if (loader.
mMaterials[mat_index].mTexture1.mOpt_tile)
883 mat_map[mat_name]->shader()->gocTextureSampler(0)->setTexture( texture.
get() );
887 act->
setEffect( mat_map[mat_name].
get() );
long long read(void *buffer, long long byte_count)
Reads byte_count bytes from a file. Returns the number of bytes actually read.
Associates a Renderable object to an Effect and Transform.
bool parse3DS(VirtualFile *file)
void setEffect(Effect *effect)
Binds an Effect to an Actor.
VLCORE_EXPORT FileSystem * defFileSystem()
Returns the default FileSystem used by VisualizationLibrary.
TexParameter * getTexParameter()
The TexParameter object associated to a Texture.
std::vector< A3DSMaterial > mMaterials
const T_Scalar & t() const
void prepareTexture2D(int width, int height, ETextureFormat format, bool border=false)
Prepares for creation an empty 2D texture.
const T_Scalar & b() const
The A3DSMaterialFaceMapping class represents the material/face mapping in a 3DS file.
An abstract class representing a file.
If enabled, do depth comparisons and update the depth buffer; Note that even if the depth buffer exis...
Matrix4 & setT(const Vector3< T_Scalar > &v)
Matrix4 & setX(const Vector3< T_Scalar > &v)
A simple String formatting class.
void setObjectName(const char *name)
The name of the object, by default set to the object's class name in debug builds.
const T_Scalar & s() const
#define ID_MAT_MAP_ROTATION
The String class implements an advanced UTF16 (Unicode BMP) string manipulation engine.
const T_Scalar & z() const
If enabled, blend the incoming RGBA color values with the values in the color buffers, see also BlendFunc for more information.
bool seekCur(long long offset)
Changes the current read/write position of a file.
The A3DSLoader class loads an Autodesk 3DS file and generates a vector of A3DSObject and A3DSMaterial...
static void error(const String &message)
Use this function to provide information about run-time errors: file not found, out of memory...
void setWrapT(ETexParamWrap texturewrap)
void setVertexArray(ArrayAbstract *data)
Conventional vertex array.
String extractPath() const
If the String contains a file path the function returns the path with trailing slash, without the file name.
Wraps an OpenGL texture object representing and managing all the supported texture types...
virtual ref< VirtualFile > locateFile(const String &full_path, const String &alternate_path=String()) const
Looks for a VirtualFile on the disk and in the currently active FileSystem.
void read_TRIANGULAR_MESH()
void setWrapS(ETexParamWrap texturewrap)
bool endOfFile() const
Returns true if position() >= size()
float readFloat(bool little_endian_data=true)
Reads single entry.
virtual void close()=0
Closes the file.
const T_Scalar & r() const
#define ID_FLOAT_PERCENTAGE
const String & path() const
Returns the path of the file.
A3DSTexture readMapChunk()
The Geometry class is a Renderable that implements a polygonal mesh made of polygons, lines and points.
The A3DSMaterial class represents a material in a 3DS file.
Visualization Library main namespace.
const unsigned char * ptr() const
Returns the pointer to the first element of the local buffer. Equivalent to bufferObject()->ptr() ...
Matrix4 & setZ(const Vector3< T_Scalar > &v)
The A3DSObject class represents an object in a 3DS file.
unsigned int mSmoothingGroup
#define ID_MAT_SHININESS_STRENGTH_PERCENT
const std::vector< ref< Object > > & resources() const
void read_MATERIAL_BLOCK()
bool mOpt_one_channel_tint
static void print(const String &message)
Application message for the user.
unsigned char readUInt8()
Reads single entry.
#define ID_TRIANGULAR_MESH
const T_Scalar & y() const
virtual bool open(EOpenMode mode)=0
Opens the file in the specified mode.
#define ID_MAT_TRANSPARENCY
void setTexCoordArray(int tex_unit, ArrayAbstract *data)
Conventional texture coords arrays.
std::vector< A3DSObject > mObjects
Matrix4 & setY(const Vector3< T_Scalar > &v)
arr_type * indexBuffer()
The BufferObject containing the indices used to render.
Shader * shader(int lodi=0, int pass=0)
Utility function, same as 'lod(lodi)->at(pass);'.
Defines the sequence of Shader objects used to render an Actor.
virtual long long size() const =0
Returns the size of the file in bytes.
#define ID_SMOOTHING_GROUP_LIST
#define ID_INT_PERCENTAGE
T_VectorType & at(size_t i)
#define ID_MATERIAL_BLOCK
#define ID_MAPPING_COORDS
unsigned short readUInt16(bool little_endian_data=true)
Reads single entry.
void setWrapR(ETexParamWrap texturewrap)
const T_Scalar & x() const
unsigned int readUInt32(bool little_endian_data=true)
Reads single entry.
The ref<> class is used to reference-count an Object.
#define ID_3D_EDITOR_CHUNK
std::string toStdString() const
Returns a UTF8 encoded std::string.
#define ID_LOCAL_COORDS_SYSTEM
#define ID_FACE_MATERIAL_LIST
#define ID_MAT_MAP_TILING
The A3DSTexture class represents a texture in a 3DS file.
long long position() const
Returns the current position in the file.
void read_3D_EDITOR_CHUNK()
virtual size_t bytesUsed() const
Returns the amount of memory in bytes used by an array. Equivalent to bufferObject()->bytesUsed().
The A3DSVertex class represents a vertex in a 3DS file.
const T_Scalar & g() const
VLGRAPHICS_EXPORT ref< ResourceDatabase > load3DS(VirtualFile *file)
void enable(EEnable capability)
#define ID_MAT_SHININESS_PERCENT
The ResourceDatabase class contains and manipulates a set of resources.
Collection< DrawCall > & drawCalls()
Returns the list of DrawCall objects bound to a Geometry.