Subversion Repository Public Repository

Divide-Framework

This repository has no backups
This repository's network speed is throttled to 100KB/sec

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
#include "Headers/DVDConverter.h"

#include <assimp/types.h>
#include <assimp/scene.h>
#include <assimp/Importer.hpp>
#include <assimp/postprocess.h>
#include "Utility/Headers/XMLParser.h"
#include "Core/Headers/ParamHandler.h"
#include "Hardware/Video/Headers/GFXDevice.h"
#include "Core/Resources/Headers/ResourceCache.h"
#include "Geometry/Shapes/Headers/SkinnedMesh.h"
#include "Geometry/Shapes/Headers/SkinnedSubMesh.h"
#include "Geometry/Animations/Headers/AnimationUtils.h"

DVDConverter::DVDConverter() : _loadcount(0), _init(false){
}

DVDConverter::~DVDConverter(){
	SAFE_DELETE(importer);
}

bool DVDConverter::init(){
	if(_init) {
		ERROR_FN(Locale::get("ERROR_DOUBLE_IMPORTER_INIT"));
		return false;
	}

	aiTextureMapModeTable[aiTextureMapMode_Wrap]   = TEXTURE_CLAMP;
	aiTextureMapModeTable[aiTextureMapMode_Clamp]  = TEXTURE_CLAMP_TO_EDGE;
	aiTextureMapModeTable[aiTextureMapMode_Decal]  = TEXTURE_DECAL;
	aiTextureMapModeTable[aiTextureMapMode_Mirror] = TEXTURE_REPEAT;
	aiShadingModeInternalTable[aiShadingMode_Fresnel]      = Material::SHADING_FRESNEL;
	aiShadingModeInternalTable[aiShadingMode_NoShading]    = Material::SHADING_NONE;
	aiShadingModeInternalTable[aiShadingMode_CookTorrance] = Material::SHADING_COOK_TORRANCE;
	aiShadingModeInternalTable[aiShadingMode_Minnaert]     = Material::SHADING_MINNAERT;
	aiShadingModeInternalTable[aiShadingMode_OrenNayar]    = Material::SHADING_OREN_NAYAR;
	aiShadingModeInternalTable[aiShadingMode_Toon]         = Material::SHADING_TOON;
	aiShadingModeInternalTable[aiShadingMode_Blinn]        = Material::SHADING_BLINN;
	aiShadingModeInternalTable[aiShadingMode_Phong]        = Material::SHADING_PHONG;
	aiShadingModeInternalTable[aiShadingMode_Gouraud]      = Material::SHADING_GOURAUD;
	aiShadingModeInternalTable[aiShadingMode_Flat]         = Material::SHADING_FLAT;
	aiTextureOperationTable[aiTextureOp_Multiply]  = Material::TextureOperation_Multiply;
	aiTextureOperationTable[aiTextureOp_Add]       = Material::TextureOperation_Add;
	aiTextureOperationTable[aiTextureOp_Subtract]  = Material::TextureOperation_Subtract;
	aiTextureOperationTable[aiTextureOp_Divide]    = Material::TextureOperation_Divide;
	aiTextureOperationTable[aiTextureOp_SmoothAdd] = Material::TextureOperation_SmoothAdd;
	aiTextureOperationTable[aiTextureOp_SignedAdd] = Material::TextureOperation_SignedAdd;
	aiTextureOperationTable[aiTextureOp_SignedAdd] = Material::TextureOperation_SignedAdd;
	aiTextureOperationTable[/*aiTextureOp_Replace*/7] = Material::TextureOperation_Replace;
	importer = New Assimp::Importer();

	bool removeLinesAndPoints = true;
	importer->SetPropertyInteger(AI_CONFIG_PP_SBP_REMOVE , removeLinesAndPoints ? aiPrimitiveType_LINE | aiPrimitiveType_POINT : 0 );
	importer->SetPropertyInteger(AI_CONFIG_IMPORT_TER_MAKE_UVS , 1);
	importer->SetPropertyFloat(AI_CONFIG_PP_GSN_MAX_SMOOTHING_ANGLE, 80.0f);
	_ppsteps = aiProcess_TransformUVCoords        | // preprocess UV transformations (scaling, translation ...)
			   aiProcess_FindInstances            | // search for instanced meshes and remove them by references to one master
			   aiProcess_OptimizeMeshes	          | // join small meshes, if possible;
			   aiProcess_OptimizeGraph            | // Nodes with no animations, bones, lights or cameras assigned are collapsed and joined.
			   aiProcess_CalcTangentSpace		  |
			   aiProcess_GenSmoothNormals         |
			   aiProcess_JoinIdenticalVertices    |
			   aiProcess_ImproveCacheLocality     |  
			   aiProcess_LimitBoneWeights		  |
			   aiProcess_RemoveRedundantMaterials |
			   aiProcess_Triangulate			  |
			   aiProcess_GenUVCoords              |
		       aiProcess_SortByPType              |
	           aiProcess_FindDegenerates          |
	           aiProcess_FindInvalidData          |
			   0;

	if(GFX_DEVICE.getApi() != OpenGL && GFX_DEVICE.getApi() != OpenGLES){
		_ppsteps |= aiProcess_ConvertToLeftHanded;
	}

	_init = true;
	return _init;
}

#pragma message("ToDo: Fix skipping points and lines on geometry import -Ionut")
Mesh* DVDConverter::load(const std::string& file){
	if(!_init){
		ERROR_FN(Locale::get("ERROR_NO_INIT_IMPORTER_LOAD"));
		return NULL;
	}

	_fileLocation = file;
	_modelName = _fileLocation.substr( _fileLocation.find_last_of( '/' ) + 1 );
	U32 start = GETMSTIME();
	_aiScenePointer = importer->ReadFile( file, _ppsteps );
	U32 elapsed = GETMSTIME() - start;

	D_PRINT_FN(Locale::get("LOAD_MESH_TIME"),_modelName.c_str(),getMsToSec(elapsed));

	if( !_aiScenePointer){
		ERROR_FN(Locale::get("ERROR_IMPORTER_FILE"), file.c_str(), importer->GetErrorString());
		return NULL;
	}
	start = GETMSTIME();
	Mesh* tempMesh = NULL;
	for(U16 n = 0; n < _aiScenePointer->mNumMeshes; n++){
		//Skip points and lines ... for now -Ionut
		if(_aiScenePointer->mMeshes[n]->mPrimitiveTypes == aiPrimitiveType_LINE ||
			_aiScenePointer->mMeshes[n]->mPrimitiveTypes == aiPrimitiveType_POINT ||
			_aiScenePointer->mMeshes[n]->mNumVertices == 0)
				continue;

		if(SubMesh* s = loadSubMeshGeometry(_aiScenePointer->mMeshes[n], n)){
            if(!s) continue;
			bool skinnedSubMesh = (s->getFlag() == Object3D::OBJECT_FLAG_SKINNED);

			if(!tempMesh){
				tempMesh = (skinnedSubMesh ? New SkinnedMesh() : New Mesh());
                tempMesh->setState(RES_LOADING);
				tempMesh->setName(_modelName);
				tempMesh->setResourceLocation(_fileLocation);
			}

			if(s->getRefCount() == 1){
				Material* m = loadSubMeshMaterial(_aiScenePointer->mMaterials[_aiScenePointer->mMeshes[n]->mMaterialIndex],
												   std::string(s->getName()+ "_material"));
				s->setMaterial(m);
				m->setHardwareSkinning(skinnedSubMesh);
				m->setTriangleStripInput(true);
			}//else the Resource manager created a copy of the material
			tempMesh->addSubMesh(s->getName());
		}
	}
	assert(tempMesh != NULL);
	tempMesh->getSceneNodeRenderState().setDrawState(true);
	elapsed = GETMSTIME() - start;
	D_PRINT_FN(Locale::get("PARSE_MESH_TIME"),_modelName.c_str(),getMsToSec(elapsed));
	_loadcount++; //< increment counter
	return tempMesh;
}

///If we are loading a LOD variant of a submesh, find it first, append LOD geometry,
///but do not return the mesh again as it will be duplicated in the Mesh parent object
///instead, return NULL and mesh and material creation for this instance will be skipped.
SubMesh* DVDConverter::loadSubMeshGeometry(const aiMesh* source,U8 count){
	///VERY IMPORTANT: default submesh, LOD0 should always be created first!!
	///an assert is added in the LODn, where n >= 1, loading code to make sure the LOD0 submesh exists first
	bool baseMeshLoading = false;

	std::string temp(source->mName.C_Str());

	if(temp.empty()){
		std::stringstream ss;
		ss << _fileLocation.substr(_fileLocation.rfind("/")+1,_fileLocation.length());
		ss << "-submesh-";
		ss << (U32)count;
		temp = ss.str();
	}

	SubMesh* tempSubMesh = NULL;
	bool skinned = source->HasBones();
	if(temp.find(".LOD1") != std::string::npos ||
		temp.find(".LOD2") != std::string::npos/* ||
		temp.find(".LODn") != std::string::npos*/){ ///Add as many LOD levels as you please
		tempSubMesh = FindResource<SubMesh>(_fileLocation.substr(0,_fileLocation.rfind(".LOD")));
		assert(tempSubMesh != NULL);
		tempSubMesh->incLODcount();
	}else{
		//Submesh is created as a resource when added to the scenegraph
		ResourceDescriptor submeshdesc(temp);
		submeshdesc.setFlag(true);
		submeshdesc.setId(count);
        if(skinned) submeshdesc.setEnumValue(Object3D::OBJECT_FLAG_SKINNED);
		tempSubMesh = CreateResource<SubMesh>(submeshdesc);
        if(!tempSubMesh) return NULL;
		///it may be already loaded
		if(!tempSubMesh->getGeometryVBO()->getPosition().empty()){
			return tempSubMesh;
		}
		baseMeshLoading = true;
	}

	tempSubMesh->getGeometryVBO()->reservePositionCount(source->mNumVertices);
	tempSubMesh->getGeometryVBO()->reserveNormalCount(source->mNumVertices);
	vectorImpl< vectorImpl<vertexWeight> >   weightsPerVertex(source->mNumVertices);

	if(skinned){
		tempSubMesh->getGeometryVBO()->getBoneIndices().reserve(source->mNumVertices);
		tempSubMesh->getGeometryVBO()->getBoneWeights().reserve(source->mNumVertices);
		assert(source->mNumBones < 256); ///<Fit in U8
		for(U8 a = 0; a < source->mNumBones; a++){
			const aiBone* bone = source->mBones[a];
			for( U32 b = 0; b < bone->mNumWeights; b++){
				weightsPerVertex[bone->mWeights[b].mVertexId].push_back(vertexWeight( a, bone->mWeights[b].mWeight));
			}
		}
	}

	bool processTangents = true;
	if(!source->mTangents){
        processTangents = false;
		D_PRINT_FN(Locale::get("SUBMESH_NO_TANGENT"), tempSubMesh->getName().c_str());
	}else{
		tempSubMesh->getGeometryVBO()->reserveTangentCount(source->mNumVertices);
		tempSubMesh->getGeometryVBO()->reserveBiTangentCount(source->mNumVertices);
	}

	vec3<F32> position, normal, tangent, bitangent;
	vec4<U8>  boneIndices;
	vec4<F32> boneWeights;

	for(U32 j = 0; j < source->mNumVertices; j++){
		position.set(source->mVertices[j].x, source->mVertices[j].y, source->mVertices[j].z);
		normal.set(source->mNormals[j].x, source->mNormals[j].y, source->mNormals[j].z);

		tempSubMesh->getGeometryVBO()->addPosition(position);
		tempSubMesh->getGeometryVBO()->addNormal(normal);

		if(processTangents){
			tangent.set(source->mTangents[j].x, source->mTangents[j].y, source->mTangents[j].z);
		    bitangent.set(source->mBitangents[j].x, source->mBitangents[j].y, source->mBitangents[j].z);
			tempSubMesh->getGeometryVBO()->addTangent(tangent);
			tempSubMesh->getGeometryVBO()->addBiTangent(bitangent);
		}

		if( skinned )	{
			boneIndices.reset();
			boneWeights.reset();

			assert( weightsPerVertex[j].size() <= 4);

			for( U8 a = 0; a < weightsPerVertex[j].size(); a++){
				boneIndices[a] = weightsPerVertex[j][a]._boneId;
				boneWeights[a] = weightsPerVertex[j][a]._boneWeight;
			}

			tempSubMesh->getGeometryVBO()->getBoneIndices().push_back(boneIndices);
			tempSubMesh->getGeometryVBO()->getBoneWeights().push_back(boneWeights);
		}

	}//endfor

	if(_aiScenePointer->HasAnimations() && skinned){
		// create animator from current scene and current submesh pointer in that scene
		dynamic_cast<SkinnedSubMesh*>(tempSubMesh)->createAnimatorFromScene(_aiScenePointer,count);
	}

	if(source->mTextureCoords[0] != NULL){
		tempSubMesh->getGeometryVBO()->getTexcoord().reserve(source->mNumVertices);
		vec2<F32> texCoord;
		for(U32 j = 0; j < source->mNumVertices; j++){
			texCoord.set(source->mTextureCoords[0][j].x, source->mTextureCoords[0][j].y);
			tempSubMesh->getGeometryVBO()->getTexcoord().push_back(texCoord);
		}//endfor
	}//endif

	U32 currentIndice  = 0;
	U32 lowestInd = 0;
	U32 highestInd = 0;
	vec3<U32> triangleTemp;

	tempSubMesh->getGeometryVBO()->useLargeIndices((source->mNumFaces * 3)+1 > std::numeric_limits<U16>::max());

	for(U32 k = 0; k < source->mNumFaces; k++){
		assert(source->mFaces[k].mNumIndices == 3);

		for(U32 m = 0; m < 3; m++){
			currentIndice = source->mFaces[k].mIndices[m];
			tempSubMesh->getGeometryVBO()->addIndex(currentIndice);
			triangleTemp[m] = currentIndice;

			if(currentIndice < lowestInd)  lowestInd  = currentIndice;
			if(currentIndice > highestInd) highestInd = currentIndice;
		}

		tempSubMesh->getGeometryVBO()->getTriangles().push_back(triangleTemp);
	}

	tempSubMesh->getGeometryVBO()->setIndiceLimits(vec2<U32>(lowestInd,highestInd), tempSubMesh->getLODcount() - 1);

	if(baseMeshLoading)	return tempSubMesh;
	else  		        return NULL;
}

/// Load the material for the current SubMesh
Material* DVDConverter::loadSubMeshMaterial(const aiMaterial* source, const std::string& materialName) {
	// See if the material already exists in a cooked state (XML file)
	Material* tempMaterial = XML::loadMaterial(materialName);
	if(tempMaterial) return tempMaterial;
	// If it's not defined in an XML File, see if it was previously loaded by the Resource Cache
	bool skip = false;
	ResourceDescriptor tempMaterialDescriptor(materialName);
	if(FindResource<Material>(materialName)) skip = true;
	// If we found it in the Resource Cache, return a copy of it
	tempMaterial = CreateResource<Material>(tempMaterialDescriptor);
	if(skip) return tempMaterial;

	ParamHandler& par = ParamHandler::getInstance();

	// Compare load results with the standard succes value
	aiReturn result = AI_SUCCESS;

	// default diffuse color
	vec4<F32> tempColorVec4(0.8f, 0.8f, 0.8f,1.0f);

	// Load diffuse color
	aiColor4D diffuse;
	if(AI_SUCCESS == aiGetMaterialColor(source,AI_MATKEY_COLOR_DIFFUSE, &diffuse)){
		tempColorVec4.set(diffuse.r,diffuse.g,diffuse.b,diffuse.a);
	}else{
		D_PRINT_FN(Locale::get("MATERIAL_NO_DIFFUSE"), materialName.c_str());
	}

	tempMaterial->setDiffuse(tempColorVec4);

	// default ambient color
	tempColorVec4.set(0.2f, 0.2f, 0.2f, 1.0f);

	// Load ambient color
	aiColor4D ambient;
	if(AI_SUCCESS == aiGetMaterialColor(source,AI_MATKEY_COLOR_AMBIENT,&ambient)){
		tempColorVec4.set(ambient.r,ambient.g,ambient.b,ambient.a);
	}else{
		D_PRINT_FN(Locale::get("MATERIAL_NO_AMBIENT"), materialName.c_str());
	}
	tempMaterial->setAmbient(tempColorVec4);

	// default specular color
	tempColorVec4.set(1.0f,1.0f,1.0f,1.0f);

	// Load specular color
	aiColor4D specular;
	if(AI_SUCCESS == aiGetMaterialColor(source,AI_MATKEY_COLOR_SPECULAR,&specular)){
		tempColorVec4.set(specular.r,specular.g,specular.b,specular.a);
	}else{
		D_PRINT_FN(Locale::get("MATERIAL_NO_SPECULAR"), materialName.c_str());
	}
	tempMaterial->setSpecular(tempColorVec4);

	// default emissive color
	tempColorVec4.set(0.0f, 0.0f, 0.0f, 1.0f);

	// Load emissive color
	aiColor4D emissive;
	if(AI_SUCCESS == aiGetMaterialColor(source,AI_MATKEY_COLOR_EMISSIVE,&emissive)){
		tempColorVec4.set(emissive.r,emissive.g,emissive.b,emissive.a);
	}
	tempMaterial->setEmissive(tempColorVec4);

	// default opacity value
	F32 opacity = 1.0f;
	// Load material opacity value
	aiGetMaterialFloat(source,AI_MATKEY_OPACITY,&opacity);
	tempMaterial->setOpacity(opacity);

	// default shading model
	I32 shadingModel = Material::SHADING_PHONG;
	// Load shading model
	aiGetMaterialInteger(source,AI_MATKEY_SHADING_MODEL,&shadingModel);
	tempMaterial->setShadingMode(aiShadingModeInternalTable[shadingModel]);

	// Default shininess values
	F32 shininess = 15, strength = 1;
	// Load shininess
	aiGetMaterialFloat(source,AI_MATKEY_SHININESS, &shininess);
	// Load shininess strength
	aiGetMaterialFloat( source, AI_MATKEY_SHININESS_STRENGTH, &strength);
	F32 finalValue = shininess * strength;
	CLAMP<F32>(finalValue,0.0f,127.5f);
	tempMaterial->setShininess(finalValue);

	// check if material is two sided
	I32 two_sided = 0;
	aiGetMaterialInteger(source, AI_MATKEY_TWOSIDED, &two_sided);
	tempMaterial->setDoubleSided(two_sided != 0);

	aiString tName;
	aiTextureMapping mapping;
	U32 uvInd;
	F32 blend;
	aiTextureOp op = aiTextureOp_Multiply;
	aiTextureMapMode mode[3] = {_aiTextureMapMode_Force32Bit,_aiTextureMapMode_Force32Bit,_aiTextureMapMode_Force32Bit};

	SamplerDescriptor textureSampler;
	U8 count = 0;
	// While we still have diffuse textures
	while(result == AI_SUCCESS){
		// Load each one
		result = source->GetTexture(aiTextureType_DIFFUSE, count,
									&tName,
									&mapping,
									&uvInd,
									&blend,
									&op,
									mode);
		if(result != AI_SUCCESS) break;
		// get full path
		std::string path = tName.data;
		// get only image name
		std::string img_name = path.substr( path.find_last_of( '/' ) + 1 );
		// try to find a path name
		std::string pathName = _fileLocation.substr( 0, _fileLocation.rfind("/")+1 );
		// look in default texture folder
		path = par.getParam<std::string>("assetsLocation")+"/"+par.getParam<std::string>("defaultTextureLocation") +"/"+ path;
		// if we have a name and an extension
		if(!img_name.substr(img_name.find_first_of(".")).empty()){
			// Is this the base texture or the secondary?
			U32 item = Material::TEXTURE_UNIT0;
			if(count == 1) item++;
			// Load the texture resource
			if(mode[0] != _aiTextureMapMode_Force32Bit)
				textureSampler.setWrapMode(aiTextureMapModeTable[mode[0]],
										   aiTextureMapModeTable[mode[1]],
										   aiTextureMapModeTable[mode[2]]);
			ResourceDescriptor texture(img_name);
			texture.setResourceLocation(path);
			texture.setFlag(true);
			texture.setPropertyDescriptor<SamplerDescriptor>(textureSampler);
			Texture2D* textureRes = CreateResource<Texture2D>(texture);
			assert(tempMaterial != NULL);
			assert(textureRes != NULL);
			//The first texture is always "Replace"
			tempMaterial->setTexture(item,textureRes, count == 0 ? Material::TextureOperation_Replace : aiTextureOperationTable[op]);
		}//endif

		tName.Clear();
		count++;
		if(count == 2) break;
		#pragma message("ToDo: Use more than 2 textures for each material. Fix This! -Ionut")
	}//endwhile

	result = source->GetTexture(aiTextureType_NORMALS, 0, &tName, &mapping, &uvInd, &blend, &op, mode);
	if(result == AI_SUCCESS){
		std::string path = tName.data;
		std::string img_name = path.substr( path.find_last_of( '/' ) + 1 );
		path = par.getParam<std::string>("assetsLocation")+"/"+par.getParam<std::string>("defaultTextureLocation") +"/"+ path;

		std::string pathName = _fileLocation.substr( 0, _fileLocation.rfind("/")+1 );
		if(img_name.rfind('.') !=  std::string::npos){
			if(mode[0] != _aiTextureMapMode_Force32Bit)
				textureSampler.setWrapMode(aiTextureMapModeTable[mode[0]],
										   aiTextureMapModeTable[mode[1]],
										   aiTextureMapModeTable[mode[2]]);
			ResourceDescriptor texture(img_name);
			texture.setResourceLocation(path);
			texture.setFlag(true);
			texture.setPropertyDescriptor<SamplerDescriptor>(textureSampler);
			Texture2D* textureRes = CreateResource<Texture2D>(texture);
			tempMaterial->setTexture(Material::TEXTURE_NORMALMAP,textureRes,aiTextureOperationTable[op]);
			tempMaterial->setBumpMethod(Material::BUMP_NORMAL);
		}//endif
	}//endif

	result = source->GetTexture(aiTextureType_HEIGHT, 0, &tName, &mapping, &uvInd, &blend, &op, mode);
	if(result == AI_SUCCESS){
		std::string path = tName.data;
		std::string img_name = path.substr( path.find_last_of( '/' ) + 1 );
		path = par.getParam<std::string>("assetsLocation")+"/"+par.getParam<std::string>("defaultTextureLocation") +"/"+ path;
		std::string pathName = _fileLocation.substr( 0, _fileLocation.rfind("/")+1 );
		if(img_name.rfind('.') !=  std::string::npos){
			if(mode[0] != _aiTextureMapMode_Force32Bit)
				textureSampler.setWrapMode(aiTextureMapModeTable[mode[0]],
										   aiTextureMapModeTable[mode[1]],
			 							   aiTextureMapModeTable[mode[2]]);
			ResourceDescriptor texture(img_name);
			texture.setResourceLocation(path);
			texture.setFlag(true);
			texture.setPropertyDescriptor<SamplerDescriptor>(textureSampler);
			Texture2D* textureRes = CreateResource<Texture2D>(texture);
			tempMaterial->setTexture(Material::TEXTURE_NORMALMAP,textureRes,aiTextureOperationTable[op]);
			tempMaterial->setBumpMethod(Material::BUMP_NORMAL);
		}//endif
	}//endif
	result = source->GetTexture(aiTextureType_OPACITY, 0, &tName, &mapping, &uvInd, &blend, &op, mode);
	if(result == AI_SUCCESS){
		std::string path = tName.data;
		std::string img_name = path.substr( path.find_last_of( '/' ) + 1 );
		std::string pathName = _fileLocation.substr( 0, _fileLocation.rfind("/")+1 );

		path = par.getParam<std::string>("assetsLocation")+"/"+par.getParam<std::string>("defaultTextureLocation") +"/"+ path;

		if(img_name.rfind('.') !=  std::string::npos){
			if(mode[0] != _aiTextureMapMode_Force32Bit)
				textureSampler.setWrapMode(aiTextureMapModeTable[mode[0]],
										   aiTextureMapModeTable[mode[1]],
										   aiTextureMapModeTable[mode[2]]);
			ResourceDescriptor texture(img_name);
			texture.setResourceLocation(path);
			texture.setFlag(true);
			texture.setPropertyDescriptor<SamplerDescriptor>(textureSampler);
			Texture2D* textureRes = CreateResource<Texture2D>(texture);
			tempMaterial->setTexture(Material::TEXTURE_OPACITY,textureRes,aiTextureOperationTable[op]);
			tempMaterial->setDoubleSided(true);
		}//endif
	}else{
		I32 flags = 0;
		aiGetMaterialInteger(source,AI_MATKEY_TEXFLAGS_DIFFUSE(0),&flags);

		// try to find out whether the diffuse texture has any
		// non-opaque pixels. If we find a few, use it as opacity texture
		if (tempMaterial->getTexture(Material::TEXTURE_UNIT0)){
			if(!(flags & aiTextureFlags_IgnoreAlpha) &&
				tempMaterial->getTexture(Material::TEXTURE_UNIT0)->hasTransparency()){
					Texture2D* textureRes = CreateResource<Texture2D>(ResourceDescriptor(tempMaterial->getTexture(Material::TEXTURE_UNIT0)->getName()));
					tempMaterial->setTexture(Material::TEXTURE_OPACITY,textureRes);
			}
		}
	}

	result = source->GetTexture(aiTextureType_SPECULAR, 0, &tName, &mapping, &uvInd, &blend, &op, mode);
	if(result == AI_SUCCESS){
		std::string path = tName.data;
		std::string img_name = path.substr( path.find_last_of( '/' ) + 1 );
		std::string pathName = _fileLocation.substr( 0, _fileLocation.rfind("/")+1 );

		path = par.getParam<std::string>("assetsLocation")+"/"+par.getParam<std::string>("defaultTextureLocation") +"/"+ path;

		if(img_name.rfind('.') !=  std::string::npos){
			if(mode[0] != _aiTextureMapMode_Force32Bit)
				textureSampler.setWrapMode(aiTextureMapModeTable[mode[0]],
										   aiTextureMapModeTable[mode[1]],
										   aiTextureMapModeTable[mode[2]]);
			ResourceDescriptor texture(img_name);
			texture.setResourceLocation(path);
			texture.setFlag(true);
			texture.setPropertyDescriptor<SamplerDescriptor>(textureSampler);
			Texture2D* textureRes = CreateResource<Texture2D>(texture);
			tempMaterial->setTexture(Material::TEXTURE_SPECULAR,textureRes,aiTextureOperationTable[op]);
		}//endif
	}//endif

	return tempMaterial;
}

Commits for Divide-Framework/trunk/Source Code/Geometry/Importer/DVDConverter.cpp

Diff revisions: vs.
Revision Author Commited Message
168 Diff Diff k1ngp1n picture k1ngp1n Sat 26 Oct, 2013 19:03:21 +0000

- Reworked the Camera class[[BR]]
— Now fully quaternion based [[BR]]
— Basic camera types added but not used yet (third person, first person, orbit) [[BR]]
- Cleaned up Material and Texture handling [[BR]]
- Added clipping plane support [[BR]]
— Similar to OpenGL fixed-function clip planes but fully shader driven [[BR]]
— Added a new class, “Plane”, that helps define clip planes [[BR]]
- Optimized the Singleton class to allow faster “getInstance” calls without performance penalties [[BR]]
-- “createInstance” must be called for each singleton class before usage. Or “gerOrCreateInstance” can be used, which is basically the former “getInstance” implementation [[BR]]
- Improved console logging by changing some heap allocations to stack and removing dependencies on the std::string class [[BR]]
- Added a lot of performance optimizations related to coding standards and redundant calculations [[BR]]
— e.g. Frustum AABB check didn’t need to recompute the AABB points as they were calculated already [[BR]]
— e.g. A vector did not need to be set to 0 on initialization as that is already it’s default state on creation [[BR]]
— e.g. Faster Framerate and Timing calculations by using less member variables that are not needed outsied of calling functions [[BR]]
- The SceneState now contains the SceneRenderState and is passed on to the SceneGraph’s update calls [[BR]]
- Better material export/import to/from XML format [[BR]]
- More bug fixes and cleanups [[BR]]

163 Diff Diff k1ngp1n picture k1ngp1n Thu 18 Jul, 2013 12:24:26 +0000

[Ionut] [[BR]]
- Fixed a rendering bug with the previous terrain rendering system (number of strips was not calculated correctly. had to add the primitive restart indices to the list as well) [[BR]]
- Fixed a rendering bug with the previous double sided Quad3D patch (water planes should not be double sided. The first parameter of the bool mask of the resource descriptor for water planes now controls whether the Quad will be single or double sided) [[BR]]
- NavMesh debug draw now uses a caching system for rendering instead of re-submitting the same geometry every frame [[BR]]
— Fixed a bug that prevented GLIM primitives to be cached if they had “canZombify” set to false [[BR]]
- Navigation meshes are now saved and loaded from file on creation. Delete the “nm” file from the navMeshes subfolder to recreate a navigation mesh for a scene. [[BR]]
- LightManager is now a FrameListener. ShadowMap generation is called with the “FramePreRenderEnd” event [[BR]]
- Terrain NavMesh uses the lowest LoD possible for now to improve creation times until all bugs are resolved [[BR]]
- Geometry importer now uses the “replace” operation for the base texture of objects [[BR]]
- glUniformBufferObjects are now a little less dependent on the GLM library [[BR]]
- Primitive restart is now toggled on or off at each VAO draw call [[BR]]
- Some GFXDevice inlining [[BR]]

161 Diff Diff k1ngp1n picture k1ngp1n Fri 12 Jul, 2013 19:51:50 +0000

[Ionut] [[BR]]
- Solved Navigation Mesh creation from Object3D nodes [[BR]]

154 Diff Diff k1ngp1n picture k1ngp1n Sun 23 Jun, 2013 23:39:07 +0000

[Ionut] [[BR]]
- Changed math computation for: Matrix multiplication, Normal and Tangent calculation, Quaternion to Matrix conversion and more [[BR]]
- Removed useless UBO classes and extended the functionality of the base UBO class [[BR]]
- Changed lighting shaders to be more streamlined [[BR]]
- Added full shader based fog [[BR]]
— Added per-scene optional fog settings [[BR]]
- Re-enabled sorting by shader program for Mesh Delegate Bin (was set to Front to Back for debugging purposes and forgotten there) [[BR]]

152 Diff Diff k1ngp1n picture k1ngp1n Thu 20 Jun, 2013 14:23:31 +0000

[Ionut] [[BR]]
- New rendering pipeline (experimental and unstable): [[BR]]
— OpenGL 3.x clean context (glLight commands are still used for now, but UBO support is there, but not used yet) [[BR]]
— Custom matrix stacks and UBO based shader data (UBOs cause some link errors on some nVidia cards)[[BR]]
— Multi-threaded texture loading and shader compilation (mt shader compilation disabled for now. needs more tests) [[BR]]
— VAO rendering is self contained (no more enable/disable calls before a draw request) [[BR]]
— Render instance class used for rendering information [[BR]]
[[BR]]
- New unique ID generation base class: GUIDWrapper. Each class that derives from this, gets an application wide unique id on construction [[BR]]
- Added base code for an in-game editor using CEGUI [[BR]]
- Replaced some mutex locks with lockless data structures or atomic data [[BR]]
- CEGUI 0.8.2, FTGL-GL3 and GLIM 0.4 modified to support GLEW_MX if defined [[BR]]
- Dropped VS2008 support [[BR]]
- Networking library, server framework and ReCast files are now projects inside the Divide Framework solution [[BR]]
- New console command “setFov” that modifies the horizontal FoV value in realtime [[BR]]
- New console command “recompileShader” that reparses shader files, recompiles shaders and relinks shader programs who’s names match or contain the argument string [[BR]]
- New debug utility: axis angle drawn in corner of the screen if needed [[BR]]
- More ‘const’-s pasted around the code, more loop performance tweaks (allocations before a loop, tighter loops, etc), more utility member functions added to various classes [[BR]]

151 Diff Diff k1ngp1n picture k1ngp1n Tue 07 May, 2013 00:00:52 +0000

[Ionut] [[BR]]
- Better ReCast integration [[BR]]
— Any entity can be used as an obstacle in the NavMesh if that’s specified in each scene’s assets.xml file for said entity [[BR]]
— New console command, “createNavMesh”, that passes geometry data to ReCast [[BR]]
-— NavMesh generation is not yet complete [[BR]]
- Better PhysX integration [[BR]]
— Each scene passes data to and gets data from the Physics API better and safer[[BR]]
- Multi-threaded support extended: [[BR]]
— Event class replaced with Task [[BR]]
— Kernel uses a threadpool for scene tasks [[BR]]
— Each task can be added to a different threadpool if needed [[BR]]
— Most critical sections use the new boost::atomic wrapper for thread safety [[BR]]
- Rendering system updated [[BR]]
— VBO’s keep track of the geometry type internally [[BR]]
— Rendering by specific element list is internal to the VBO [[BR]]
— VBO’s can draw a “lite” version that doesn’t send Tangent, BiTangent and TexCoord data for depth rendering (disabled) [[BR]]
- Reflectors now offer a preview of the generated reflective texture if needed [[BR]]
- Buttons are now added and rendered by CEGUI [[BR]]
[[BR]]
Deprecation: [[BR]]
- Removed fixed pipeline material system [[BR]]
- Removed BoundingBox late update system [[BR]]
- Shadow references in the material system are now depth references [[BR]]
[[BR]]
Bug fixes: [[BR]]
- Problematic FBO double bind check removed [[BR]]
- Faster terrain rendering via chunk size selection through each scene’s terrain.xml[[BR]]
- Rendering is paused when the window is minimized [[BR]]
- CEGUI and impostors now render properly in deferred rendering mode [[BR]]
- Fixed various level 4 (VS2008) warnings [[BR]]
- Better state management and cleaning [[BR]]
- Better SceneGraph node management and trasformation/AABB update calls [[BR]]
- AITenisScene has proper collisions now [[BR]]

146 Diff Diff k1ngp1n picture k1ngp1n Wed 10 Apr, 2013 13:20:15 +0000

[Ionut] [[BR]]
*Final LightBranch updates 2/3 : Main trunk merge and build test (VC90, VC100, gDebugger) [[BR]]
-Merged light branch with trunk [[BR]]
-Deleted light branch [[BR]]

135 Diff Diff k1ngp1n picture k1ngp1n Tue 20 Nov, 2012 19:01:27 +0000

[Ionut] [[BR]]

  • (minor merge with LightingUpdate branch, rev. 134) [[BR]]

-Updated ASSIMP to version 3.0.1,CeGUI to 0.7.7 and PhysX to 3.2.2 [[BR]]
-Moved third party libraries to separate repository with appropriate copyright notices [[BR]]
--New library repository: https://xp-dev.com/svn/Divide-Dependencies [[BR]]
--PhysX can’t be legally shared like the rest of the libs, but you can get ver. 3.2.2 (the version the framework is using) by signing up to the nVidia Developer Website ( https://developer.nvidia.com/ ) [[BR]]

121 Diff Diff k1ngp1n picture k1ngp1n Sun 10 Jun, 2012 16:40:45 +0000

[Ionut] [[BR]]
-Added basic localization support [[BR]]
-Added cross-platform INI parsing [[BR]]
-Moved ReCast+Detour to LIBS folder [[BR]]

116 k1ngp1n picture k1ngp1n Mon 04 Jun, 2012 22:27:07 +0000

[Ionut] [[BR]]
-Removed now useless “BaseCache” class as a simple unordered_map in each manager-type class is all that’s needed [[BR]]
-Moved loading responsibility from each Resource implementation to each "ImplResourceLoader<T>" class (defaults via macro’s are available for convenience) [[BR]]
--Resources now have a “setInitialData” method for setting post-load values [[BR]]
--Also added a loader for Particle Emitters [[BR]]
-Added a new class, “HardwareResource” (for textures, shaders, etc) that needs special loading routines to facilitate future multi-threaded asset streaming [[BR]]
--HardwareResource’s have a “generateHWResource” that should be called after threaded loading routines join with main thread [[BR]]
-Renamed “Guardian” class to “Kernel” as that’s what it’s new responsibility will be in future revisions [[BR]]
-Added the “threadpool” library from here: http://threadpool.sourceforge.net/ (not used yet) [[BR]]
-Added some more macro’s and cleanups [[BR]]