Esempio n. 1
0
bool ElMaxPlugin::ExportMesh(LPCTSTR filename)
{
	// Open the stream
	outfile.open(filename);
	if (!outfile.good())
		return false;

	// Set format of the stream
	outfile << setprecision(4) << setiosflags(ios::fixed);

	// Add bones to out bone list, in case some bone be
	// exported as GeomObject
	boneList.Clear();
	PreProcess(ip->GetRootNode());

	// Add the nodes material to out material list
	mtlList.Clear();
	FindMaterials(ip->GetRootNode());

	// Export global info
	ExportGlobalInfo();

	// Export list of material definitions
	ExportMaterialList();

	// Export each object found in the scene
	nodeEnum(ip->GetRootNode());

	// Close the stream
	outfile.close();

	return true;
}
Esempio n. 2
0
BOOL AscOut::nodeEnum(INode* node, int indentLevel) 
{
	nCurNode++;
	ip->ProgressUpdate((int)((float)nCurNode/nTotalNodeCount*100.0f)); 

	// Stop recursing if the user pressed Cancel 
	if (ip->GetCancel())
		return FALSE;
	
	TSTR indent = GetIndent(indentLevel);
	
	// Only export if exporting everything or it's selected
	if(!exportSelected || node->Selected()) {

		// The ObjectState is a 'thing' that flows down the pipeline containing
		// all information about the object. By calling EvalWorldState() we tell
		// max to eveluate the object at end of the pipeline.
		ObjectState os = node->EvalWorldState(0); 

		// The obj member of ObjectState is the actual object we will export.
		if (os.obj) {

			// We look at the super class ID to determine the type of the object.
			switch(os.obj->SuperClassID()) {
			case GEOMOBJECT_CLASS_ID: 
				ExportGeomObject(node, indentLevel); 
				break;
			case CAMERA_CLASS_ID:
				ExportCameraObject(node, indentLevel); 
				break;
			case LIGHT_CLASS_ID:
				ExportLightObject(node, indentLevel); 
				break;
			case SHAPE_CLASS_ID:
				ExportShapeObject(node, indentLevel); 
				break;
			case HELPER_CLASS_ID:
				ExportHelperObject(node, indentLevel); 
				break;
			}
		}
	}

	// For each child of this node, we recurse into ourselves 
	// until no more children are found.
	for (int c = 0; c < node->NumberOfChildren(); c++) {
		if (!nodeEnum(node->GetChildNode(c), indentLevel))
			return FALSE;
	}

	return TRUE;
}
Esempio n. 3
0
int FaceDataExport::DoExport(const TCHAR *name,ExpInterface *ei,Interface *i, BOOL suppressPrompts, DWORD options) {
	exportSelected = (options & SCENE_EXPORT_SELECTED) ? true : false;
	Interface14 *iface = GetCOREInterface14();
	UINT codepage  = iface-> DefaultTextSaveCodePage(true);
	if(!fileStream.Open(name, false, MaxSDK::Util::TextFile::Writer::WRITE_BOM | codepage )) return 0;
	fileStream.Printf(_T("FaceFloats Export 1.1\n\n"));
	int numChildren = i->GetRootNode()->NumberOfChildren();
	for (int idx=0; idx<numChildren; idx++) {
		nodeEnum(i->GetRootNode()->GetChildNode(idx), i);
	}
	fileStream.Close();

	return TRUE;
}
Esempio n. 4
0
//------------------------------------------------------------------------
// Name: BOOL nodeEnum()
//
// Desc: This method is the main object exporter.
//       It is called once of every node in the scene.
//       The objects are exported as they are encoutered.
//
//       Before recursing into the children of node,we will export it.
//       The benefit of this is that a nodes parent is always before
//       the children in the resulting file. This is desired since a
//       child's transformation matrix is optionally relative to the
//       parent.
//------------------------------------------------------------------------
BOOL SMDExporter::nodeEnum( INode* node )
{
    // If user press cancel then break recurse
    if( m_ip->GetCancel() )
        return FALSE;

    // Only export if exporting everything or it's selected
    if( !exportSelected || node->Selected() )
    {
        // The ObjectState is a 'thing' that flows down the pipeline containing
        // all information about the object. By calling EvalWorldState() we tell
        // max to evaluate the object at the end of pipeline
        ObjectState os = node->EvalWorldState(0);

        // The obj member of ObjectState is the actual
        // object we will export
        if( os.obj )
        {
            // We look at the superclassID to determin the type of the object
            switch( os.obj->SuperClassID() )
            {
            case GEOMOBJECT_CLASS_ID:
                ExportGeomObject( node );
                break;
            }
        }
    }

    // Update the processBar
    m_nCurNode++;
    m_ip->ProgressUpdate( int((float)m_nCurNode/m_nTotalNodeCount * 100.0f) );

    // For each child of this node, we recurse into ourselves
    // until no more children is found
    for( int c=0;c<node->NumberOfChildren();c++ )
    {
        if( !nodeEnum(node->GetChildNode(c)) )
            return FALSE;
    }

    return TRUE;
}
Esempio n. 5
0
BOOL FaceDataExport::nodeEnum(INode* node,Interface *ip) {	
	if(!exportSelected || node->Selected()) {
		ObjectState os = node->EvalWorldState(ip->GetTime());

		IFaceDataMgr *pFDMgr = NULL;
		if (os.obj->IsSubClassOf(triObjectClassID)) {
			TriObject *tobj = (TriObject *)os.obj;
			Mesh* mesh = &tobj->GetMesh();
			pFDMgr = static_cast<IFaceDataMgr*>(mesh->GetInterface( FACEDATAMGR_INTERFACE ));
		} else if (os.obj->IsSubClassOf (polyObjectClassID)) {
			PolyObject *pobj = (PolyObject *)os.obj;
			MNMesh *mesh = &pobj->GetMesh();
			pFDMgr = static_cast<IFaceDataMgr*>(mesh->GetInterface( FACEDATAMGR_INTERFACE ));
		}
		if (pFDMgr == NULL) return FALSE;

		SampleFaceData* SampleDataChan = NULL; 
		IFaceDataChannel* fdc = pFDMgr->GetFaceDataChan( FACE_MAXSAMPLEUSE_CLSID );
		if ( fdc != NULL ) SampleDataChan = dynamic_cast<SampleFaceData*>(fdc);
		if ( SampleDataChan == NULL) {
			fileStream.Printf(_T("Node %s does not have our Face Data\n"),node->GetName());
			return false;
		}

		//OK so We have Face data lets dump it out..
		fileStream.Printf(_T("\nNode %s has %d faces with FaceFloats\n"),node->GetName(), SampleDataChan->Count());
		for(ULONG i=0;i<SampleDataChan->Count();i++) {
			float data = SampleDataChan->data[i];
			fileStream.Printf(_T("Face %d, float %f\n"),i,data);
		}
	}

	// Recurse through this node's children, if any
	for (int c = 0; c < node->NumberOfChildren(); c++) {
		if (!nodeEnum(node->GetChildNode(c), ip)) return FALSE;
	}

	return TRUE;
}
Esempio n. 6
0
/**
 * This method will export the argument node and traverse
 * into its child nodes to export them.
 */
BOOL OSGExp::nodeEnum(osg::Group* rootTransform, INode* node, osg::Group* parent)
{
	osg::ref_ptr<osg::Group> child = NULL;

	_nCurNode++;
	_ip->ProgressUpdate((int)((float)_nCurNode/_nTotalNodeCount*100.0f)); 

	// Stop traversing if the user pressed Cancel.
	if (_ip->GetCancel())
		return TRUE;


	// If node is hidden and we are not exporting hidden nodes then return.
	if(node->IsNodeHidden() && !_options->getExportHiddenNodes()){
		return TRUE;
   }

   // Capture a special group helper if one is returned.
   // Nodes such as LODs and Switches will have to apply
   // special flags to their immediate children and thus
   // cannot be traversed in the normal recursive flow.
//   osg::Group* specialGroup = NULL;


	// Only export if hole scene is to be exported or
	// this node is choosen to be exported.
	if(!_onlyExportSelected || node->Selected())
   {
		// The ObjectState is a 'thing' that flows down the pipeline containing
		// all information about the object. By calling EvalWorldState() we tell
		// max to evaluate the object at the end of the pipeline.
		// An object may start out as an sphere, but could be modified by an modifier
		// object, the EvalWorldState will apply all modifiers to the original object
		// and return the final geometry for the object.
		ObjectState os = node->EvalWorldState(_ip->GetTime());

      // Use temporary variables for cleaner code.
      Object* obj = os.obj;
      TimeValue timeValue = _ip->GetTime();


		// If this a group node then make a OSG group node and add it to
		// the parent node and traverse into the children.
		if(node->IsGroupHead() || obj->ClassID() == Class_ID(DUMMY_CLASS_ID,0))
      {
			// Do not export referenced groups.
			if(Util::isReferencedByHelperObjects(node, _helperIDs))
				return TRUE;
			osg::MatrixTransform* groupNode = new osg::MatrixTransform();
			// Set name of group node.
			groupNode->setName(std::string(node->GetName()));
			// Set static datavariance for better performance
			groupNode->setDataVariance(osg::Object::STATIC);

			// Are we exporting animations.
			if(_options->getExportAnimations()){
				addAnimation(node, timeValue, groupNode);
			}
			
			// Set NodeMask
			if(_options->getUseDefaultNodeMaskValue())
				groupNode->setNodeMask(_options->getDefaultNodeMaskValue());
			groupNode->setMatrix(getNodeTransform(node, timeValue));
			parent->addChild(groupNode);
			parent = groupNode;
			applyNodeMaskValue(node, timeValue, groupNode);
		}

		// If this is not a group node it could be a geomtry object,
		// a camera, a light, or some other class. Switch the class ID
		// to carry out a specific export.
		// Note, it is the obj member of ObjectState which
		// is the actual object we are exporting.
		else if(obj != NULL)
      {
         Class_ID cid = obj->ClassID();

			// We look at the super class ID to determine the type of the object.
			switch(obj->SuperClassID())
         {
				case GEOMOBJECT_CLASS_ID:
					if(!Util::isReferencedByHelperObjects(node, _helperIDs))
               {
						child = createGeomObject(rootTransform, node, obj, timeValue).get();
						parent->addChild(child.get());
					}
					break;
				case CAMERA_CLASS_ID:
					if(_options->getExportCameras())
               {
						child = createCameraObject(rootTransform, node, obj, timeValue).get();
						parent->addChild(child.get());
					}
					break;
				case LIGHT_CLASS_ID:
					if(_options->getExportLights())
               {
						child = createLightObject(rootTransform, node, obj, timeValue).get();
						parent->addChild(child.get());
					}
					break;
				case SHAPE_CLASS_ID:
					if(_options->getExportShapes() && !Util::isReferencedByHelperObject(node, OCCLUDER_CLASS_ID))
               {
						child = createShapeObject(rootTransform, node, obj, timeValue).get();
						parent->addChild(child.get());
					}
					break;
				case HELPER_CLASS_ID:
               {
                  bool notRefByHelpers = Util::isReferencedByHelperObjects(node, _helperIDs) == NULL;
                  bool exportHelpers = _options->getExportHelpers() == TRUE;

                  if(_options->getExportPointHelpers() && cid == Class_ID(POINTHELP_CLASS_ID,0)) 
                  {
                     child = createPointFromHelperObject(rootTransform, node, obj, timeValue).get();
                     parent->addChild(child.get());
                  }
                  if(exportHelpers && notRefByHelpers)
                  {
                     if(cid == OSGGROUP_CLASS_ID)
                     {
                        child = createGroupFromHelper(parent, node, obj, timeValue).get();
                     }
                     else if(cid == LOD_CLASS_ID)
                     {
                        child = createLODFromHelperObject(parent, node, obj, timeValue).get();
                     }
                     else if(cid == SWITCH_CLASS_ID)
                     {
                        child = createSwitchFromHelperObject(parent, node, obj, timeValue).get();
                     }
                     else if(cid == DOFTRANSFORM_CLASS_ID) 
                     {
                        child = createDOFFromHelper(parent, node, obj, timeValue).get();                  
                     }
		               else
                     {
			               rootTransform->addChild(createHelperObject(rootTransform, node, obj, timeValue).get());
		               }
                  }
               }
					break;
            default:
               break;
			}
		}
	}

   for(int c = 0; c < node->NumberOfChildren(); c++)
   {
	   if(_ip->GetCancel() || ! nodeEnum(rootTransform, node->GetChildNode(c),child.valid()?child.get():parent))
      {
		   // If user cancels export we return false.
		   return FALSE;
	   }
   }

	return TRUE;
}
Esempio n. 7
0
/**
 * This method will be called from the max system when the user
 * has choosen to export to the OpenSceneGraph format.
 * This method is the entry point to the exporter plugin.
 */
int	OSGExp::DoExport(const TCHAR *name, ExpInterface *ei,
					 Interface *i, BOOL suppressPrompts, DWORD MAXOptions){

	// Only support "one at the time" exporting.
	if(isExporting){
		return FALSE;
	}
	isExporting = TRUE;

	// Grab the interface pointer and save it for later use.
	_ip = i;

	// Set export path in options class
	TCHAR p[300];
	TCHAR f[100];
	TCHAR e[10];
	BMMSplitFilename(name, p, f, e);
	_options->setExportPath(p);
	_options->setExportFilename(f);
	_options->setExportExtension(e);

	// Get filename to config file.
	TSTR cfgfilename = _ip->GetDir(APP_PLUGCFG_DIR);;
	cfgfilename += _T("\\OSGEXP.CFG");

	// Load options from config file
	_options->load(cfgfilename);

	// Should we only export selected nodes?
	_onlyExportSelected = (MAXOptions & SCENE_EXPORT_SELECTED) ? TRUE : FALSE;

	// Show option dialog to user and retrive any possible plugin choices.
	if(!suppressPrompts)
		if(!DialogBoxParam(hInstance, MAKEINTRESOURCE(IDD_EXPORTBOX), 
				           GetActiveWindow(), OptionsDlgProc,
						   (LPARAM)_options)){
			// If user closed or canceled export box then shutdown plugin.
			isExporting = FALSE;
			return TRUE;
		}

	// Write options to config file.
	_options->write(cfgfilename);

	// Create OSG root transform to hold the scene.
{	
	osg::ref_ptr<osg::MatrixTransform> rootTransform = new osg::MatrixTransform();
	//osg::MatrixTransform* rootTransform = new osg::MatrixTransform();
	rootTransform->setName(std::string(_ip->GetRootNode()->GetName()));
	// Set static datavariance for better performance
	rootTransform->setDataVariance(osg::Object::STATIC);
	// Set NodeMask
	if(_options->getUseDefaultNodeMaskValue())
		rootTransform->setNodeMask(_options->getDefaultNodeMaskValue());
	osg::Matrix rootMat = getNodeTransform(_ip->GetRootNode(), _ip->GetTime());
	rootTransform->setMatrix(rootMat);
    // Create root stateset for the lights.
	osg::ref_ptr<osg::StateSet> rootStateSet = new osg::StateSet();
	// Turn of lighting if set by the user.
	if(_options->getTurnOffLighting())
		rootStateSet->setMode(GL_LIGHTING,osg::StateAttribute::OVERRIDE|osg::StateAttribute::OFF);
	else
		rootStateSet->setMode(GL_LIGHTING,osg::StateAttribute::ON);
	//osg::StateSet* rootStateSet = new osg::StateSet();
    rootTransform->setStateSet(rootStateSet.get());


	// We will make two progress bars. The first one will show
	// the exporting of materials, wheras the second one will show
	// the exporting of nodes. To get the total number of nodes in the
	// scene graph we will accumulate the total node count while
	// preprocessing the scenegraph for materials.
	_nTotalNodeCount = 0;
	_nCurNode = 0;
	_nTotalMtlCount = _ip->GetSceneMtls()->Count();
	_nCurMtl = 0;

	// Starting up the material exporting progress bar.
	_ip->ProgressStart(_T("Exporting materials..."), TRUE, fn, NULL);
	// Export materials by preprocessing the scenegraph. 
	if(!preProcess(_ip->GetRootNode(), _ip->GetTime())){
		// If user cancels we stop progress bar and return.
		_ip->ProgressEnd();
		isExporting = FALSE;
		return TRUE;
	}
	// We're done exporting materials. Finish the progress bar.
	_ip->ProgressEnd();

	// Starting up the node exporting progress bar.
	_ip->ProgressStart(_T("Exporting scene..."), TRUE, fn, NULL);

	// Get number of children for the root node in the interface.
	int numChildren = _ip->GetRootNode()->NumberOfChildren();
	
	// Call our node enumerator.
	// The nodeEnum function will recurse into itself and 
	// export each object found in the scene.
	for (int idx=0; idx<numChildren; idx++) {
		if (_ip->GetCancel() || !nodeEnum(rootTransform.get(), _ip->GetRootNode()->GetChildNode(idx), rootTransform.get())){
			// If user cancels we stop progress bar and return
			_ip->ProgressEnd();
			isExporting = FALSE;
			return TRUE;
		}
	}
	// Finish exporting progress bar
	_ip->ProgressEnd();


	// If optimize scene graph
	unsigned int optimizeMask = 0;
	if(_options->getTriStripGeometry())
		optimizeMask |= osgUtil::Optimizer::TRISTRIP_GEOMETRY;
	if(_options->getMergeGeometry())
		optimizeMask |= osgUtil::Optimizer::MERGE_GEOMETRY;
	if(_options->getFlattenStaticTransform())
		optimizeMask |= osgUtil::Optimizer::FLATTEN_STATIC_TRANSFORMS;
	if(_options->getShareDuplicateStates())
		optimizeMask |= osgUtil::Optimizer::SHARE_DUPLICATE_STATE;
	if(_options->getSpatializeGroups())
		optimizeMask |= osgUtil::Optimizer::SPATIALIZE_GROUPS;
	if(optimizeMask){
		_ip->ProgressStart(_T("Optimizing scenegraph..."), FALSE, fn, NULL);
		_ip->ProgressUpdate(0.5f); 
		osgUtil::Optimizer optimizer;
		optimizer.optimize(rootTransform.get(), optimizeMask);
		_ip->ProgressEnd();
	}
	 
	// Save file to disk.
	if(_options->getSaveFile()){
		_ip->ProgressStart(_T("Writing file..."), FALSE, fn, NULL);
		_ip->ProgressUpdate(0.5f); 
		if(_options->getExportExtension().compare(".osg")==0 ||
		   _options->getExportExtension().compare(".OSG")==0 ||
		   _options->getExportExtension().compare(".ive")==0 ||
		   _options->getExportExtension().compare(".IVE")==0   ){

			std::string filename(name);

			// Exclude image data from ive file if this options has been choosen
			if(!_options->getIncludeImageDataInIveFile()){
				osgDB::ReaderWriter::Options* opt = new osgDB::ReaderWriter::Options("noTexturesInIVEFile");
				osgDB::Registry::instance()->setOptions(opt);
			}


#if defined(OPENSCENEGRAPH_MAJOR_VERSION) && OPENSCENEGRAPH_MAJOR_VERSION >= 2 && defined(OPENSCENEGRAPH_MINOR_VERSION) && OPENSCENEGRAPH_MINOR_VERSION >= 4
            osgDB::ReaderWriter::WriteResult res = 
               osgDB::Registry::instance()->writeNode(*rootTransform, filename, NULL);
#else
            osgDB::ReaderWriter::WriteResult res = 
               osgDB::Registry::instance()->writeNode(*rootTransform, filename);
#endif

			if(res.error() && _options->getShowErrMsg()){
				static TCHAR szBuffer[256];
				wsprintf(szBuffer,TEXT("Error writing file %s:\n%s"), 
					     TEXT(filename.c_str()),res.message());
				MessageBox (GetActiveWindow(), szBuffer, TEXT("Warning"),
					        MB_OK | MB_ICONWARNING) ;
			}

			if(!_options->getIncludeImageDataInIveFile()){
                // Turn readerwriter options off again.
				osgDB::ReaderWriter::Options* opt = new osgDB::ReaderWriter::Options();
				osgDB::Registry::instance()->setOptions(opt);
            }
		}
		else{
			if(_options->getShowErrMsg()){
				std::string error("Can not find plugin to save file: ");
				error.append(name);
				MessageBox (GetActiveWindow(), error.c_str() , TEXT("Warning"), MB_OK | MB_ICONWARNING) ;
			}
		}
		_ip->ProgressEnd();
	}

	// Show quick preview
	if(_options->getQuickView()){

		float fNear = 1.0f;
		float fFar = 1000.0f;

		// Get the active viewport and the win32 window within it.
		// The position and size will be retreive from this.
		ViewExp* viewExp = _ip->GetActiveViewport();
		float fov = viewExp->GetFOV();
		HWND hWnd = viewExp->getGW()->getHWnd();
		RECT sRect;
		BOOL ok = GetWindowRect(hWnd, &sRect);
		int width = 100;
		int height = 100;
		int x =100;
		int y =100;
		if(ok){
			x = sRect.left;
			y = sRect.top;
			width = sRect.right - sRect.left;
			height = sRect.bottom - sRect.top;
		}

		// Create previewer window and set size.
		Previewer previewer;
		previewer.setWindowSize(x, y, width, height);


		// The affine TM transforms from world coords to view coords
		// so we need the inverse of this matrix
		Matrix3 aTM, camTM, coordSysTM;
		Point3 viewDir, viewPos, lookAtPos, upVector;
		INode* camera;
		float dist = 100;

		Point3 upperLeft = viewExp->MapScreenToView(IPoint2(0, 0), fFar);
		Point3 lowerRight = viewExp->MapScreenToView(IPoint2(width, height), fFar);
		
		viewExp->GetAffineTM(aTM);
		coordSysTM = Inverse(aTM);	

		viewDir = coordSysTM.VectorTransform(Point3(0.0f, 0.0f, -1.0f));
		viewPos = coordSysTM.GetRow(3);
		lookAtPos = viewPos + viewDir;
		upVector.Set(0.0f, 0.0f, 1.0f);

		switch(viewExp->GetViewType()){
			case VIEW_ISO_USER:
			case VIEW_PERSP_USER:
				previewer.setProjectionMatrixAsFrustum(lowerRight.x, upperLeft.x,  upperLeft.y, lowerRight.y, fFar, -fFar);
				break;
			case VIEW_CAMERA:
				previewer.setProjectionMatrixAsFrustum(upperLeft.x, lowerRight.x, lowerRight.y, upperLeft.y, fFar, -fFar);
				camera = viewExp->GetViewCamera();
				camTM = camera->GetObjTMBeforeWSM(_ip->GetTime());
				viewDir = camTM.VectorTransform(Point3(0.0f, 0.0f, -1.0f));
				viewPos = camTM.GetRow(3);
				lookAtPos = viewPos + viewDir;
				break;
			case VIEW_LEFT:
			case VIEW_RIGHT:
			case VIEW_TOP:
			case VIEW_BOTTOM:
			case VIEW_FRONT:
			case VIEW_BACK:
				previewer.setProjectionMatrixAsOrtho(upperLeft.x, lowerRight.x, lowerRight.y, upperLeft.y, -fFar, fFar);
				//cam->setOrtho(upperLeft.x, lowerRight.x, lowerRight.y, upperLeft.y, -fFar, fFar);
				// Go far away from the viewing point in the negative viewing direction.
				viewPos = coordSysTM.PointTransform(Point3(0.0f, 0.0f, fFar));
				lookAtPos = viewPos + viewDir;
				// In top view the up vector on the camera is the positive y-axis.
				if(viewExp->GetViewType() == VIEW_TOP)
					upVector.Set(0.0f, 1.0f, 0.0f);
				// In bottom view the up vector on the camera is the negative y-axis.
				if(viewExp->GetViewType() == VIEW_BOTTOM)
					upVector.Set(0.0f, -1.0f, 0.0f);
				break;
		}
		// When we are done with the viewport we should release it.
		_ip->ReleaseViewport(viewExp);

		// Set scene data.
		previewer.setSceneData(rootTransform.get());

		// set the view - OpenGL look at
		previewer.setViewMatrixAsLookAt(osg::Vec3( viewPos.x, viewPos.y, viewPos.z),
										 osg::Vec3(lookAtPos.x, lookAtPos.y, lookAtPos.z),
										 osg::Vec3(upVector.x, upVector.y, upVector.z) );
 		previewer.run();

		isExporting = FALSE;
		return TRUE;
	}
}
	isExporting = FALSE;
	return TRUE;
}
Esempio n. 8
0
// Start the exporter!
// This is the real entrypoint to the exporter. After the user has selected
// the filename (and he's prompted for overwrite etc.) this method is called.
int AscOut::DoExport(const TCHAR *name,ExpInterface *ei,Interface *i, BOOL suppressPrompts, DWORD options) 
{
	// Set a global prompt display switch
	showPrompts = suppressPrompts ? FALSE : TRUE;
	exportSelected = (options & SCENE_EXPORT_SELECTED) ? TRUE : FALSE;

	// Grab the interface pointer.
	ip = i;

	// Get the options the user selected the last time
	ReadConfig();

	if(showPrompts) {
		// Prompt the user with our dialogbox, and get all the options.
		if (!DialogBoxParam(hInstance, MAKEINTRESOURCE(IDD_ASCOUT_DLG),
			ip->GetMAXHWnd(), ExportDlgProc, (LPARAM)this)) {
			return 1;
		}
	}
	
	sprintf(szFmtStr, "%%4.%df", nPrecision);

	// Open the stream
	pStream = _tfopen(name,_T("wt"));
	if (!pStream) {
		return 0;
	}
	
	// Startup the progress bar.
	ip->ProgressStart(GetString(IDS_PROGRESS_MSG), TRUE, fn, NULL);

	// Get a total node count by traversing the scene
	// We don't really need to do this, but it doesn't take long, and
	// it is nice to have an accurate progress bar.
	nTotalNodeCount = 0;
	nCurNode = 0;
	PreProcess(ip->GetRootNode(), nTotalNodeCount);
	
	// First we write out a file header with global information. 
	ExportGlobalInfo();

	int numChildren = ip->GetRootNode()->NumberOfChildren();
	
	// Call our node enumerator.
	// The nodeEnum function will recurse into itself and 
	// export each object found in the scene.
	
	for (int idx=0; idx<numChildren; idx++) {
		if (ip->GetCancel())
			break;
		nodeEnum(ip->GetRootNode()->GetChildNode(idx), 0);
	}

	// We're done. Finish the progress bar.
	ip->ProgressEnd();

	// Close the stream
	fclose(pStream);

	// Write the current options to be used next time around.
	WriteConfig();

	return 1;
}
Esempio n. 9
0
int	SkeletonExporter::DoExport(const TCHAR *name,ExpInterface *ei,Interface *i, BOOL suppressPrompts, DWORD options)
{
	// Set local interface pointer
	ip = i;

	// load the configuration from disk
	// so that it can be used in our dialog box
	if(!LoadExporterConfig()) return 0;

	if(!suppressPrompts)
	{

		// Show preferences setup dialog
		int res = DialogBoxParam(
			hInstance,
			MAKEINTRESOURCE(IDD_SKELETON_SCEXP),
			i->GetMAXHWnd(),
			PrefsDlgProc,
			(LPARAM)this);

		// User clicked 'Cancel'
		if(res!=0) return 0;

	}

	exportSelected = (options & SCENE_EXPORT_SELECTED) ? TRUE : FALSE;

	// Open a fA3D for writing out to
	fA3D = fopen (name, "wb+");
	if (!fA3D) return 0;

	strcpy(nomefileTXT, name);  // copio nella variabile della
	int sl=strlen(name); // classe il nome del file .A3D
	                            // (compresa estensione)
    nomefileTXT[sl-4]='.';
    nomefileTXT[sl-3]='T';
    nomefileTXT[sl-2]='X';
    nomefileTXT[sl-1]='T';
    nomefileTXT[sl-0]='\0';
	fTXT = _tfopen(nomefileTXT, _T("wt"));
	if (!fTXT) return 0;

    if (makeRAY)
	{
      strcpy(nomefileRAY, name);
      nomefileRAY[sl-4]='.';
      nomefileRAY[sl-3]='R';
      nomefileRAY[sl-2]='A';
      nomefileRAY[sl-1]='Y';
      nomefileRAY[sl-0]='\0';
	  fRAY = fopen(nomefileRAY, "wb+");
	  if (!fRAY) return 0;
	}

    strcpy(nomefileANI, name);
    nomefileANI[sl-4]='.';
    nomefileANI[sl-3]='A';
    nomefileANI[sl-2]='N';
    nomefileANI[sl-1]='I';
    nomefileANI[sl-0]='\0';
	//fANI = fopen(nomefileANI, "wb+");
	//if (!fANI) return 0;

    if (makeADM)
	{
      strcpy(nomefileADM, name);
      nomefileADM[sl-4]='.';
      nomefileADM[sl-3]='A';
      nomefileADM[sl-2]='D';
      nomefileADM[sl-1]='M';
      nomefileADM[sl-0]='\0';
      fADM=fopen(nomefileADM, "wt");
      fprintf(fADM, "// *** Apocalypse Design Scripting System v1.0 ***\n");
      fprintf(fADM, "// Material script auto-created by Turbo's MAX-plugin\n");
      fprintf(fADM, "// Design is simply all...\n\n");
	}

    if (makeADL)
	{
      strcpy(nomefileADL, name);
      nomefileADL[sl-4]='.';
      nomefileADL[sl-3]='A';
      nomefileADL[sl-2]='D';
      nomefileADL[sl-1]='L';
      nomefileADL[sl-0]='\0';
      fADL=fopen(nomefileADL, "wt");
      fprintf(fADL, "// *** Apocalypse Design Scripting System v1.0 ***\n");
      fprintf(fADL, "// Light script auto-created by Turbo's MAX-plugin\n");
      fprintf(fADL, "// Design is simply all...\n\n");
	}

    if (makeADO)
	{
      strcpy(nomefileADO, name);
      nomefileADO[sl-4]='.';
      nomefileADO[sl-3]='A';
      nomefileADO[sl-2]='D';
      nomefileADO[sl-1]='O';
      nomefileADO[sl-0]='\0';
      fADO=fopen(nomefileADO, "wt");
      fprintf(fADO, "// *** Apocalypse Design Scripting System v1.0 ***\n");
      fprintf(fADO, "// Object script auto-created by Turbo's MAX-plugin\n");
      fprintf(fADO, "// Design is simply all...\n\n");
	}
/*
    if (makeADD)
	{
      strcpy(nomefileADD, name);
      nomefileADD[sl-4]='.';
      nomefileADD[sl-3]='A';
      nomefileADD[sl-2]='D';
      nomefileADD[sl-1]='D';
      nomefileADD[sl-0]='\0';
      fADD=fopen(nomefileADD, "wt");
      fprintf(fADD, "// *** Apocalypse Design Scripting System v1.0 ***\n");
      fprintf(fADD, "// Dummys script auto-created by Turbo's MAX-plugin\n");
      fprintf(fADD, "// Design is simply all...\n\n");
	}
*/
    if (makeADP)
	{
      strcpy(nomefileADP, name);
      nomefileADP[sl-4]='.';
      nomefileADP[sl-3]='A';
      nomefileADP[sl-2]='D';
      nomefileADP[sl-1]='P';
      nomefileADP[sl-0]='\0';
      fADP=fopen(nomefileADP, "wt");
      fprintf(fADP, "// *** Apocalypse Design Scripting System v1.0 ***\n");
      fprintf(fADP, "// Particle systems script auto-created by Turbo's MAX-plugin\n");
      fprintf(fADP, "// Design is simply all...\n\n");
	}

    if (makeADS)
	{
      strcpy(nomefileADS, name);
      nomefileADS[sl-4]='.';
      nomefileADS[sl-3]='A';
      nomefileADS[sl-2]='D';
      nomefileADS[sl-1]='S';
      nomefileADS[sl-0]='\0';
      fADS=fopen(nomefileADS, "wt");
      fprintf(fADS, "// *** Apocalypse Design Scripting System v1.0 ***\n");
      fprintf(fADS, "// Scene script auto-created by Turbo's MAX-plugin\n");
      fprintf(fADS, "// Design is simply all...\n\n");
	}

	export_general_info();
	export_materials();

	// Print out a title for the file header
	fprintf(fTXT, "***Elenco dei nodi***\n\n");

	// Simple root node -> children enumeration
	// This will get the root node, and then cycle through its children (ie, the basic scene nodes)
	// It will then recurse to search their children, and then their children, etc
	int numChildren = i->GetRootNode()->NumberOfChildren();
	
	for (int idx=0; idx<numChildren; idx++) {
//		if (i->GetCancel()) break;
		nodeEnum(i->GetRootNode()->GetChildNode(idx), i);
	}


    // scrittura del chunk di fine scena !!!
	int flag_end=1;
    write_chunk_header(fA3D, END_SCENE_ID, i->GetRootNode()->GetName(), 4);
	fwrite(&flag_end, sizeof(int), 1, fA3D);
    if (makeRAY)
	{
       write_chunk_header(fRAY, END_SCENE_ID, i->GetRootNode()->GetName(), 4);
       fwrite(&flag_end, sizeof(int), 1, fRAY);
	}
	//export_ANI (i->GetRootNode());	

	//fflush(fANI);
	fclose(fTXT);
	fclose(fA3D);
	//fclose(fANI);
    if (makeADM) fclose(fADM);
    if (makeADL) fclose(fADL);
    if (makeADO) fclose(fADO);
    //if (makeADD) fclose(fADD);
    if (makeADP) fclose(fADP);
    if (makeADS) fclose(fADS);
    if (makeRAY) fclose(fRAY);

	// Save the current configuration back out to disk
	// for use next time the exporter is run
	SaveExporterConfig();
	return 1;
}
Esempio n. 10
0
BOOL SkeletonExporter::nodeEnum(INode* node,Interface *ip) 
{
	if(exportSelected && node->Selected() == FALSE)
		return TREE_CONTINUE;

	// Se annullato dall'utente esci
    // if (ip->GetCancel()) return FALSE;

	// The ObjectState is a 'thing' that flows down the pipeline containing
	// all information about the object. By calling EvalWorldState() we tell
	// max to eveluate the object at end of the pipeline.
	ObjectState os = node->EvalWorldState(0);

	fprintf(fTXT, "Name: %s, Father Name: %s\n",
		    node->GetName(), node->GetParentNode()->GetName());
	fflush(fTXT);
	if (os.obj)
	{
	  fprintf(fTXT, "Super Class ID: %X, ClassID: %X, %X\n",
	        os.obj->SuperClassID(),
			os.obj->ClassID().PartA(),
            os.obj->ClassID().PartB());
	}


	// The obj member of ObjectState is the actual object we will export.
	if (os.obj)
	{
	  // We look at the super class ID to determine the type of the object.
	  switch(os.obj->SuperClassID())
	  {
	    case WSM_OBJECT_CLASS_ID:
			 if (os.obj->ClassID()==Class_ID(WINDOBJECT_CLASS_ID, 0))
				export_WSM_wind(node);
			 else
			 if (os.obj->ClassID()==Class_ID(BOMB_OBJECT_CLASS_ID, 0))
				export_WSM_bomb(node);
			 else
			 if (os.obj->ClassID()==Class_ID(GRAVITYOBJECT_CLASS_ID, 0))
				export_WSM_gravity(node);
             break;

		case GEOMOBJECT_CLASS_ID:
			 if (os.obj->ClassID()==Class_ID(0x9125, 0))
			    export_bipedbone(node);   // biped bone
			 else
			 if (os.obj->ClassID()==BONE_OBJ_CLASSID)
			    export_MAXbone(node);     // Max bone
			 else
			 if (os.obj->ClassID()==patchObjectClassID)
			    export_patch(node);       // Bezier patch
			 else 
			 if ((os.obj->ClassID()==Class_ID(RAIN_CLASS_ID, 0)) ||
                 (os.obj->ClassID()==Class_ID(SNOW_CLASS_ID, 0)))
				export_particle_spray(node);  // particle spray
			 else
			 {
                if (makeRAY)
                if (os.obj->ClassID()==Class_ID(BOXOBJ_CLASS_ID, 0))
					export_ray_box(node);
				if (makeRAY)
                if (os.obj->ClassID()==Class_ID(SPHERE_CLASS_ID, 0))
					export_ray_sphere(node);
				if (makeRAY)
                if (os.obj->ClassID()==Class_ID(CYLINDER_CLASS_ID, 0))
					export_ray_cylinder(node);
				if (makeRAY)
                if (os.obj->ClassID()==Class_ID(0x81f1dfc, 0x77566f65))
					export_ray_plane(node);  // plane (grid object)
				export_solid_object(node); 
			 }
		     break;

		case CAMERA_CLASS_ID:
			 export_camera(node); 
			 break;

		case LIGHT_CLASS_ID:
		     export_light(node); 
			 break;

		case SHAPE_CLASS_ID:
//			 ExportShapeObject(node); 
			 break;

		case HELPER_CLASS_ID:
			 // catena cinematica
			 if (os.obj->ClassID()==Class_ID(0x1C706482, 0x3E82994))
				 export_IKChain(node);
			 else
			 // helper(s) standard
			 export_helper_object(node);
			 break;
	  }
	}
	fflush(fA3D);
	fflush(fTXT);
/*
	// inizio bones
	Object *p; IDerivedObject *q; Modifier *m; int n,i;

	p=node->GetObjectRef();
	if(p->SuperClassID()==GEN_DERIVOB_CLASS_ID)
	{
		q=(IDerivedObject *)p;
		n=q->NumModifiers();
		for (i=0; i<n; i++)
		{
			m=q->GetModifier(i);
			Class_ID cidd = m->ClassID();
            fprintf(fTXT,"   modifier : %s Class_ID(%X,%X)\n",m->GetName(),cidd.PartA(),cidd.PartB());
		}
	}

	// fine bones
*/
	// Recurse through this node's children, if any
	for (int c = 0; c < node->NumberOfChildren(); c++) {
		if (!nodeEnum(node->GetChildNode(c), ip))
			return FALSE;
	}
	return TRUE;
}
Esempio n. 11
0
//------------------------------------------------------------------------
// Name: DoExport()
// Desc: Start the exporter!
//------------------------------------------------------------------------
int SMDExporter::DoExport( const TCHAR* name,ExpInterface* ei,Interface* i,
						   BOOL suppressPrompts,DWORD options )
{
	// Set a global prompt display switch
	showPrompts = suppressPrompts ? FALSE : TRUE;
	exportSelected = (options & SCENE_EXPORT_SELECTED) ? TRUE : FALSE;

	// Store the Interface pointer
	m_ip = i;
    m_sFilename = name;

	if( showPrompts )
	{
		// If user click "Cancel" then exit the plug-in
		if( !DialogBoxParam(hInstance,"SMDExporterDlg",m_ip->GetMAXHWnd(),ExporterDlgProc,(LPARAM)this) )
			return TRUE;
	}

	// Open a file to write data
	m_pFile = fopen( name,"wb" );
	if( !m_pFile ) return FALSE;

	// Startup the progress bar.
	m_ip->ProgressStart( GetString(IDS_PROGRESS_MSG),TRUE,fn,NULL );

	// Get the total node count by traversing the scene
	// It's nice to have a accurate progress bar
	m_nTotalNodeCount   = 0;
	m_nCurNode          = 0;
	PreProcess( m_ip->GetRootNode(),m_nTotalNodeCount );

	// Call our node Enumerator.
	// The nodeEnum function will recourse itself and
	// Export each object found in the scene
	int numChildren = m_ip->GetRootNode()->NumberOfChildren();

    fputc( 'S',m_pFile );
    fputc( 'M',m_pFile );
    fputc( 'D',m_pFile );
    fputc( '\0',m_pFile );
    ExportBinaryHeader();

	// Check the count of mesh
	m_nNumMeshes = m_nTotalNodeCount;
	m_pMeshes = new SMDMESH[m_nNumMeshes];
    memset( m_pMeshes,0,sizeof(SMDMESH)*m_nNumMeshes );

	for( int c=0;c<numChildren;c++ )
	{
		if( m_ip->GetCancel() ) break;

		nodeEnum( m_ip->GetRootNode()->GetChildNode(c) );
	}

	// Exported all datas, Close the file
	m_ip->ProgressEnd();
	fclose( m_pFile );

	// Clean up the memory
	CleanUpMem();

	return TRUE;
}