82 std::vector<vert_info> Vertex;
97 std::vector<fvec3> Vert;
99 std::vector<surface_info> Surface;
117 std::vector<material_info> materials;
118 std::vector<mesh_info> meshes;
130 LoaderAC3D::mesh_info::mesh_info()
141 LoaderAC3D::LoaderAC3D()
154 mTokenizer->readString(token);
156 if (token !=
"AC3Db")
163 while( mTokenizer->readString(token) )
165 if (token ==
"MATERIAL")
168 if (token ==
"OBJECT")
182 fvec3 LoaderAC3D::readColor()
185 ok &= mTokenizer->readString(mTmpStr);
float r = mTmpStr.toFloat();
186 ok &= mTokenizer->readString(mTmpStr);
float g = mTmpStr.toFloat();
187 ok &= mTokenizer->readString(mTmpStr);
float b = mTmpStr.toFloat();
190 Log::error(
"LoaderAC3D::readColor() IO error.\n");
194 fvec3 LoaderAC3D::readVector()
197 ok &= mTokenizer->readString(mTmpStr);
float x = mTmpStr.toFloat();
198 ok &= mTokenizer->readString(mTmpStr);
float y = mTmpStr.toFloat();
199 ok &= mTokenizer->readString(mTmpStr);
float z = mTmpStr.toFloat();
202 Log::error(
"LoaderAC3D::readVector() IO error.\n");
206 float LoaderAC3D::readFloat()
209 ok &= mTokenizer->readString(mTmpStr);
float f = mTmpStr.toFloat();
212 Log::error(
"LoaderAC3D::readFloat() IO error.\n");
216 int LoaderAC3D::readInt()
219 ok &= mTokenizer->readString(mTmpStr);
int i = mTmpStr.toInt();
222 Log::error(
"LoaderAC3D::readInt() IO error.\n");
226 int LoaderAC3D::readHex()
229 ok &= mTokenizer->readString(mTmpStr);
240 return mTmpStr.toInt(
true);
244 String LoaderAC3D::readWord()
247 ok &= mTokenizer->readString( mTmpStr );
256 if ( mTmpStr.count(
'"') == 1 )
258 Log::error(
Say(
"The string '%s' contains a single '\"'.\n") << mTmpStr );
266 String LoaderAC3D::readName()
269 ok &= mTokenizer->readQuotedString( mTmpStr );
278 if ( mTmpStr.count(
'"') == 1 )
280 Log::error(
Say(
"The string '%s' contains a single '\"'.\n") << mTmpStr );
288 String LoaderAC3D::readLine()
291 ok &= mTokenizer->readLine( mTmpStr );
303 void LoaderAC3D::readMaterial()
306 material_info material;
308 material.Name = readName();
310 material.Diffuse = readColor();
312 material.Ambient = readColor();
314 material.Emission = readColor();
316 material.Specular = readColor();
318 material.Shininess = readFloat();
320 material.Trans = 1 - readFloat();
322 materials.push_back(material);
325 void LoaderAC3D::readObject()
341 mesh.Name = readName();
347 mTokenizer->readLine(mTmpStr);
348 data_size = mTmpStr.toInt();
351 unsigned char ch = 0;
352 for (
int i=0; i<data_size; i++ )
353 mTokenizer->readToken(&ch);
356 if (block ==
"texture")
358 mesh.Texture = readName();
360 if (block ==
"texrep")
362 mesh.TexRep[0] = readFloat();
363 mesh.TexRep[1] = readFloat();
367 mesh.Matrix.setX( (
dvec3)readVector() );
368 mesh.Matrix.setY( (
dvec3)readVector() );
369 mesh.Matrix.setZ( (
dvec3)readVector() );
373 mesh.Matrix.setT( (
dvec3)readVector() );
377 mesh.Url = readName();
379 if (block ==
"numvert")
381 mesh.NumVert = readInt();
382 for(
int i=0; i<mesh.NumVert; ++i)
384 mesh.Vert.push_back( readVector() );
387 if (block ==
"numsurf")
389 mesh.NumSurf = readInt();
390 for(
int i=0; i<mesh.NumSurf; ++i)
400 surf.Flags = readHex();
404 surf.materials = readInt();
408 surf.VertCount = readInt();
409 for(
int j=0; j<surf.VertCount; ++j)
412 vert.Vert = readInt();
413 vert.U = readFloat();
414 vert.V = readFloat();
415 surf.Vertex.push_back( vert );
419 while (tmp !=
"refs");
420 mesh.Surface.push_back(surf);
426 mesh.NumKids = readInt();
427 meshes.push_back(mesh);
434 mTokenizer->readLine(mTmpStr);
437 while(block !=
"kids");
459 if ( !loader.parseAC3D(file) )
463 std::vector< ref<Effect> > mat_map;
464 for(
unsigned imat=0; imat<loader.materials.size(); imat++)
467 mat_map.push_back(effect.
get());
479 if ( loader.materials[ imat ].Trans < 1.0f )
488 for(
unsigned imesh=0; imesh<loader.meshes.size(); imesh++)
490 if ( loader.meshes[imesh].Surface.empty() )
494 act->
setObjectName( loader.meshes[imesh].Name.toStdString().c_str() );
497 geom->
setObjectName( loader.meshes[imesh].Name.toStdString().c_str() );
508 int mat_index = loader.meshes[imesh].Surface[0].materials;
510 act->
setEffect( mat_map[ mat_index ].
get() );
514 for(
unsigned isurf=0; isurf<loader.meshes[imesh].Surface.size(); isurf++)
516 if ( (loader.meshes[imesh].Surface[isurf].Flags & 0xF) != 0 )
518 for(
int ivert=1; ivert<loader.meshes[imesh].Surface[isurf].VertCount-1; ivert++)
519 for(
int i=0; i<3; ++i)
523 verts->
resize( vert_count );
540 for(
unsigned isurf=0; isurf<loader.meshes[imesh].Surface.size(); isurf++)
542 if ( (loader.meshes[imesh].Surface[isurf].Flags & 0xF) != 0 )
544 VL_CHECK( loader.meshes[imesh].Surface[isurf].VertCount >= 3 )
545 for(
int ivert=1; ivert<loader.meshes[imesh].Surface[isurf].VertCount-1; ivert++)
547 int vert_idx[] = { 0, ivert, ivert+1 };
548 for(
int i=0; i<3; ++i, idx++)
552 int iv = loader.meshes[imesh].Surface[isurf].Vertex[ vert_idx[i] ].Vert;
553 verts->
at( idx ) = loader.meshes[imesh].Vert[ iv ];
554 uv->
at( idx ) =
fvec2(loader.meshes[imesh].Surface[isurf].Vertex[ vert_idx[i] ].U, loader.meshes[imesh].Surface[isurf].Vertex[ vert_idx[i] ].V);
569 if ( loader.meshes[imesh].Texture.length() )
573 String tex_path = loader.meshes[imesh].Texture;
576 tex_path = tex_file->
path();
582 if ( (loader.meshes[imesh].Surface[0].Flags & 0x20) )
Associates a Renderable object to an Effect and Transform.
Simple class to manage flags in a type safe manner.
void setEffect(Effect *effect)
Binds an Effect to an Actor.
VLCORE_EXPORT FileSystem * defFileSystem()
Returns the default FileSystem used by VisualizationLibrary.
void setTexture(Texture *texture)
The texture sampler by a texture unit.
void prepareTexture2D(int width, int height, ETextureFormat format, bool border=false)
Prepares for creation an empty 2D texture.
Vector3< float > fvec3
A 3 components vector with float precision.
An abstract class representing a file.
If enabled, do depth comparisons and update the depth buffer; Note that even if the depth buffer exis...
Vector4< float > fvec4
A 4 components vector with float precision.
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.
static void warning(const String &message)
Use this function to provide information about situations that might lead to errors or loss of data...
TextureSampler * gocTextureSampler(int unit_index)
The String class implements an advanced UTF16 (Unicode BMP) string manipulation engine.
If enabled, blend the incoming RGBA color values with the values in the color buffers, see also BlendFunc for more information.
void setTransparency(float alpha)
void setShininess(float shininess)
static void error(const String &message)
Use this function to provide information about run-time errors: file not found, out of memory...
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.
void setSpecular(const fvec4 &color)
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.
Wraps an OpenGL texture object representing and managing all the supported texture types...
void setInputFile(VirtualFile *file)
virtual void close()=0
Closes the file.
const String & path() const
Returns the path of the file.
The Geometry class is a Renderable that implements a polygonal mesh made of polygons, lines and points.
Visualization Library main namespace.
Vector2< float > fvec2
A 2 components vector with float precision.
The TextStream class can be used to conveniently read or parse utf8-encoded text files.
void setDiffuse(const fvec4 &color)
void setEmission(const fvec4 &color)
const std::vector< ref< Object > > & resources() const
LightModel * gocLightModel()
void setTexCoordArray(int tex_unit, ArrayAbstract *data)
Conventional texture coords arrays.
void transform(const mat4 &matr, bool normalize=true)
Transforms vertices and normals belonging to this geometry.
void setAmbient(const fvec4 &color)
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.
T_VectorType & at(size_t i)
Effect * effect()
Returns the Effect bound to an Actor.
void setLod(int lod_index, Renderable *renderable)
Sets the Renderable object representing the LOD level specifed by lod_index.
BlendFunc * gocBlendFunc()
The ref<> class is used to reference-count an Object.
void setTwoSide(bool twoside)
void enable(EEnable capability)
VLGRAPHICS_EXPORT ref< ResourceDatabase > loadAC3D(VirtualFile *file)
Loads and AC3D file (.ac)
void set(EBlendFactor src_rgb, EBlendFactor dst_rgb, EBlendFactor src_alpha, EBlendFactor dst_alpha)
The ResourceDatabase class contains and manipulates a set of resources.
Collection< DrawCall > & drawCalls()
Returns the list of DrawCall objects bound to a Geometry.
If enabled, cull polygons based on their winding in window coordinates, see also CullFace.