void MeshWithoutIndexDataTests::testGenerateLodLevels()
{
    String fileName = "testGenerateLodLevels.mesh";
    createMeshWithMaterial(fileName);
    MeshPtr mesh = mMeshMgr->getByName(fileName);

    Mesh::LodDistanceList lodDistanceList;
    lodDistanceList.push_back(600.0);
    mesh->generateLodLevels(lodDistanceList, ProgressiveMesh::VRQ_CONSTANT, 2);

    CPPUNIT_ASSERT(mesh->getNumLodLevels() == 2);
    for (ushort i = 0; i < mesh->getNumSubMeshes(); ++i)
    {
        SubMesh* subMesh = mesh->getSubMesh(i);
        for (ushort j = 0; j < mesh->getNumLodLevels() - 1; ++j)
        {
            if (subMesh->indexData->indexCount > 0)
            {
                CPPUNIT_ASSERT(subMesh->mLodFaceList[j]->indexCount > 0);
            }
            else
            {
                CPPUNIT_ASSERT(subMesh->mLodFaceList[j]->indexCount == 0);
            }
        }
    }

    MeshSerializer meshWriter;
    meshWriter.exportMesh(mesh.get(), fileName);

    remove(fileName.c_str());

    mMeshMgr->remove( mMeshMgr->getByName(fileName) );
}
Exemple #2
0
int main( int argc, char *argv[] )
{
	int i = 1;
	unsigned int ndistances = 0;
	Real distance = 0;
	char *source = 0;
	char *dest = 0;

	if ( argc < 2 ) help(argv[0]);

	while (i < argc)
	{
		if (argv[i][0] == '-' || argv[i][0] == '/')
		{
			switch (argv[i++][1])
			{
			case 'd':
			case 'D':
				i--;
				flags[GenerateLOD] = true;
				switch (argv[i++][2])
				{
				case 'f':
				case 'F':
					flags[UseFixedMethod] = true;
					break;
				case 'p':
				case 'P':
					flags[UseFixedMethod] = false;
					break;
				default:
					help(argv[0]);
				}
				try
				{
					reduction = atof(argv[i++]);
					ndistances = atoi(argv[i++]);
					while (ndistances > 0)
					{
						if (i < argc && argv[i][0] != '-' && argv[i][0] != '/')
							distanceList.push_back(atof(argv[i++]));									
						else
							ndistances = 0;
						ndistances--;
					}
				}
				catch (Exception *e)
				{
					ndistances = 0;
					distanceList.clear();
					flags[GenerateLOD] = false;
				}
				break;
			case 'g':
			case 'G':
				flags[UseSharedVertexData] = false;
				break;
			case 'i':
			case 'I':
				flags[InfoOnly] = true;
				break;
			case 'l':
			case 'L':
				flags[UseSeparateLayers] = true;
				break;
			case 'm':
			case 'M':
				flags[ExportMaterials] = false;
				break;
			case 'r':
			case 'R':
				flags[RenameMaterials] = true;
				if (strlen(argv[i-1]) > 2) {
					i--;
					switch (argv[i++][2])
					{
					case 'i':
					case 'I':
						flags[UseInteractiveMethod] = true;
						break;
					case 'o':
					case 'O':
						flags[UseObjectMethod] = true; // default
						break;
					case 'p':
					case 'P':
						flags[UsePrefixMethod] = true;
						if (argv[i][0] != '-' && argv[i][0] != '/')
							matPrefix = argv[i++];
						else
							help(argv[0]);
						break;
					default:
						help(argv[0]);
					}
				}
				break;
			case 's':
			case 'S':
				flags[ExportSkeleton] = false;
				break;
			case 'v':
			case 'V':
				flags[PrintVMaps] = true;
				break;
			default:
				help(argv[0]);
			}
		}
		else
		{
			if (!source) source = argv[i];
			else
				if (!dest) dest = argv[i];
			i++;
		}
	}

	if ( !source ) help(argv[0]);

	if (!dest) dest = "\0";

	float t1, t2;
	
	t1 = ( float ) clock() / CLOCKS_PER_SEC;

	if (!flags[InfoOnly])
	{
		logMgr = new LogManager();
		logMgr->createLog("lwo2mesh.log", true);
		resourceGroupMgr = new ResourceGroupManager();
		mth = new Math();
		matMgr = new MaterialManager();
		matMgr->initialise();
		meshMgr  = new MeshManager();
		skelMgr = new SkeletonManager();
		meshSerializer = new MeshSerializer();
		materialSerializer = new MaterialSerializer();
		skeletonSerializer = new SkeletonSerializer();
		bufferMgr = new DefaultHardwareBufferManager(); // needed because we don't have a rendersystem
	}

	if ( strchr(source, '*') ) 
		// On Linux this will only be called if you pass the source argument in
		// quotation marks (e.g. as LightwaveConverter "abc..*" ). Otherwise the
		// shell will expand the arguments. At least, this is how it works with
		// bash.
		readFiles( source, dest );
	else
	{
		lwReader reader;
		lwObject *object = reader.readObjectFromFile(source);
		if ( object )
		{
			if (flags[InfoOnly])
				info(object, source);
			else
			{
				char *destname = (char *)malloc(512);
				if ( !destname ) return 1;

				if (strlen(dest))
					make_destname(dest, dest, destname);
				else
					make_destname(dest, source, destname);

				Lwo2MeshWriter lwo2mesh;
				lwo2mesh.writeLwo2Mesh(object, destname);
				free(destname);
			}
			delete object;
		}
	}

	t2 = ( float ) clock() / CLOCKS_PER_SEC - t1;
	
	if (flags[InfoOnly])
	{
		cout << "Total:" << nl
			<< setw(8) << nobjects << " objects" << nl
			<< setw(8) << nlayers << " layers" << nl
			<< setw(8) << nsurfs << " surfaces" << nl
			<< setw(8) << nclips << " clips" << nl
			<< setw(8) << nenvs << " envelopes" << nl
			<< setw(8) << npoints << " points" << nl
			<< setw(8) << npolygons << " polygons" << nl
			<< setw(8) << t2 << " seconds processing time." << endl;
	}
	else
	{
		delete bufferMgr;
		delete skeletonSerializer;
		delete materialSerializer;
		delete meshSerializer;
		delete meshMgr;
		delete skelMgr;
		delete matMgr;
		delete mth;
		delete resourceGroupMgr;
		delete logMgr;
	}

	return 0;
	
}