Optimize a file and update it keeping as many information as possible

Question and answer about Polygon Cruncher SDK
Post Reply
Site Admin
Posts: 255
Joined: Thu Jul 05, 2007 11:06 am

Optimize a file and update it keeping as many information as possible

Post by mootools » Thu Apr 13, 2017 3:44 pm

Polygon Cruncher SDK allows to open a file, optimizes its contents then save the results using the original file as template.
Not all the file format allows this options, but you can use it with FBX, Collada, LXO or Cinema4D for example.

The following sample opens a file, optimize it (dynamically) to 50% then update the original content.

Code: Select all


#include "common_cpp_type.h"
#include "ApplicationTools.h"
#include "3DType.h"
#include "3DScene.h"
#include "SceneOptimizer.h"
#include "MultiresolutionObject.h"
#include "3DExtObject.h"
#include "3DSceneNode.h"
#include "Io3dmgr.h"

int Process()
	CSceneImportOptions importOptions;
	importOptions.flags = SCENE_IMPORT_UPDATE_MODE; // This is the better way to keep as many information from your file
	CXString filename = _T("myFBXFile.fbx");
	C3DIo file(filename, FILE_PARSER_LOADING);
	C3DScene *scene = file.Read(&importOptions);
	if (!scene)
		return 1;

	// Very important !
	// Convert scene and use C3DExtObject which are required for optimizing
	C3DPolygonCruncherObjectCreator cruncherCreator(DEFAULT_OPTIMIZATION_OBJECT);
	scene->ConvertToType(NULL, &cruncherCreator);

	// Create the optimizer and attach scene
	CSceneOptimizer *optimizer = xNew(CSceneOptimizer);
	optimizer->SetFlag(SCENEOPTIMIZER_TRACK_CHANGES, true);
	optimizer->SetFlag(SCENEOPTIMIZER_PROGRESSIVE_RATIO, true); // Better results when several meshes
	optimizer->SetScene(*scene, true);


	// Define some optimization settings
	optimizer->SetOptimizeMode(DEFAULT_OPTIMIZATION_MODE, true);

	// Compute the dynamic mesh
	bool cancel;
	optimizer->Optimize(0.0f, cancel);

	// Get the dynamic mesh
	if (optimizer->GetScene(OPTIMIZED_MULTIRESOLUTION_SCENE) == NULL) // Compute the multiresolution scene
		return 1;

	optimizer->SetMultiresolutionRatio(0.5f, 0, OPTIMIZE_TO_POINT|OPTIMIZE_TO_RATIO);

	C3DScene *sceneToSave = optimizer->GetScene(OPTIMIZED_CLEANED_MULTIRESOLUTION_SCENE);

	CXString outputfile = _T("myOutputFBX.fbx");
	CSceneExportOptions exportOptions;
	exportOptions.flags = SCENE_EXPORT_TRY_UPDATE_FILE; // This will create a new file using the information contained in the original file

	C3DIo outputFile(outputfile, FILE_PARSER_SAVING);
	if (!outputFile.Save(sceneToSave, &exportOptions))
		_tprintf(FormatString(_T("%s was not saved. An error occured\n"), outputfile));
		_tprintf(FormatString(_T("%s was saved (using default options"), outputfile));

	// optimizer deletes the scene

#ifdef __WINDOWS__
int wmain()
#elif defined(__APPLE__) || defined(__LINUX__)
int main()
	InitMootoolsApplication(MOOTOOLS_LICENSE_KEY); // Init mootools application with default settings

	int result = Process();

	CloseMootoolsApplication(); // Close mootools application properly

	return result;

Posts: 2
Joined: Tue Dec 22, 2020 7:58 am

Re: Optimize a file and update it keeping as many information as possible

Post by siajewellery » Tue Dec 22, 2020 8:03 am

Sia Art Jewellery Launched in 1995, SIA, the flagship brand in Fashion jewellery of the company owns 100+ retail touchpoints which include our exclusive stores & MBOs at Central & Pantaloons along with our presence on e-tail platforms like Amazon, Myntra, Nykaa, Ajio and Flipkart & have churned out the heart of people with our own portal siajewellery

Sia specialises in a niche category of designs from bridal jewellery to western wear to office wear to daily wear jewellery that too affordable & fashionable.

Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests