コード例 #1
0
    // ------------------------------------------------------------
    bool EffectTextureExporter::getTextureFileInfos ( 
        const COLLADASW::URI &sourceUri, 
        COLLADASW::URI &fullFileNameURI )
    {
        bool returnValue = true;

        // Check if the file exist!
        String sourceUriString = sourceUri.toNativePath();

        if ( ExportOptions::relativePaths() )
        {
            // Different filename and URI, if we copy the textures to the destination directory!
            if ( ExportOptions::copyTextures() )
            {
                // Get the URI of the COLLADA file.
                String targetColladaFile = mDocumentExporter->getFilename();
                COLLADASW::URI targetColladaUri ( COLLADASW::URI::nativePathToUri ( targetColladaFile ) );
                if ( targetColladaUri.getScheme ().empty () )
                    targetColladaUri.setScheme ( COLLADASW::URI::SCHEME_FILE );

                // Get the URI of the copied texture file.
                COLLADASW::URI textureUri = createTargetURI ( sourceUri );

                // Get the texture URI relative to the COLLADA file URI.
                bool success = false;
                COLLADASW::URI targetUri = textureUri.getRelativeTo ( targetColladaUri, success );
                if ( !success ) 
                {
                    String message = "Not able to generate a relative path from " 
                        + textureUri.getURIString() + " to " + targetColladaUri.getURIString() 
                        + ". An absolute path will be written! ";
                    MGlobal::displayError ( message.c_str() );
                    targetUri = textureUri;
                    returnValue = false;
                }

                // Get the file URI
                fullFileNameURI = targetUri;
            }
            else
            {
                // Get the URI of the COLLADA file.
                String targetColladaFile = mDocumentExporter->getFilename();
                COLLADASW::URI targetColladaUri ( COLLADASW::URI::nativePathToUri ( targetColladaFile ) );
                if ( targetColladaUri.getScheme ().empty () )
                    targetColladaUri.setScheme ( COLLADASW::URI::SCHEME_FILE );

                // Get the texture URI relative to the COLLADA file URI.
                bool success = false;
                COLLADASW::URI targetUri = sourceUri.getRelativeTo ( targetColladaUri, success );
                if ( !success ) 
                {
                    String message = "Not able to generate a relative path from " 
                        + sourceUri.getURIString() + " to " + targetColladaUri.getURIString() 
                        + ". An absolute path will be written! ";
                    MGlobal::displayError ( message.c_str() );
                    targetUri = sourceUri;
                    returnValue = false;
                }

                // Get the file URI
                fullFileNameURI = targetUri;
            }
        }
        else
        {
            // Different filename and URI, if we copy the textures to the destination directory!
            if ( ExportOptions::copyTextures() )
            {
                // Get the texture URI relative to the COLLADA file URI.
                COLLADASW::URI targetUri = createTargetURI ( sourceUri );

                // Get the file URI
                fullFileNameURI = targetUri;
            }
            else
            {
                // Get the file URI
                fullFileNameURI = sourceUri;
            }
        }

        return returnValue;
    }
コード例 #2
0
    //---------------------------------------------------------------
    void DocumentExporter::exportAsset()
    {
        COLLADASW::Asset asset ( &mStreamWriter );

        // Add contributor information
        // Set the author
        String userName = getEnvironmentVariable ( "USERNAME" );

        if ( userName.empty() )
            userName = getEnvironmentVariable ( "USER" );

        if ( !userName.empty() )
            asset.getContributor().mAuthor = String ( userName );

		const COLLADASW::URI maxFileUri = mExportSceneGraph->getMaxFileUri();
		if ( !maxFileUri.getPathFile().empty() )
			asset.getContributor().mSourceData = maxFileUri.getURIString();

        asset.getContributor().mAuthoringTool = AUTHORING_TOOL;


        // set *system* unit information
        int systemUnitType;

        float systemUnitScale;

        GetMasterUnitInfo ( &systemUnitType, &systemUnitScale );

        switch ( systemUnitType )
        {

        case UNITS_INCHES:
            asset.setUnit ( "inch", systemUnitScale * 0.0254f );
            break;

        case UNITS_FEET:
            asset.setUnit ( "feet", systemUnitScale * 0.3048f );
            break;

        case UNITS_MILES:
            asset.setUnit ( "mile", systemUnitScale * 1609.344f );
            break;

        case UNITS_MILLIMETERS:
            asset.setUnit ( "millimeter", systemUnitScale * 0.001f );
            break;

        case UNITS_CENTIMETERS:
            asset.setUnit ( "centimeter", systemUnitScale * 0.01f );
            break;

        case UNITS_METERS:
            asset.setUnit ( "meter", systemUnitScale );
            break;

        case UNITS_KILOMETERS:
            asset.setUnit ( "kilometer", systemUnitScale * 1000.0f );
            break;

        default:
            break;
        }

        asset.setUpAxisType ( COLLADASW::Asset::Z_UP );

        asset.add();
    }
コード例 #3
0
    //---------------------------------------------------------------
	void DocumentExporter::exportAsset()
    {
		COLLADASW::Asset asset(&mStreamWriter);

        // Add contributor information
        // Set the author
        char* userName = getenv ( USERNAME );

        if ( !userName || *userName == 0 ) 
		{
			userName = getenv ( USER );
		}
        if ( userName && *userName != 0 ) 
		{
			asset.getContributor().mAuthor = NativeString( userName ).toUtf8String();
		}

        // Source is the scene we have exported from
        String currentScene = MFileIO::currentFile().asChar();
        if ( currentScene.size() > 0 )
        {
            COLLADASW::URI sourceFileUri ( COLLADASW::URI::nativePathToUri ( currentScene ) );
            if ( sourceFileUri.getScheme ().empty () )
                sourceFileUri.setScheme ( COLLADASW::URI::SCHEME_FILE );
            asset.getContributor().mSourceData = sourceFileUri.getURIString();
        }
		
		std::size_t foundLast = COLLADABU::CURRENT_REVISION.find_last_of(".");
		std::size_t foundFirst = COLLADABU::CURRENT_REVISION.find_first_of(".");
		
		String versionMajor = COLLADABU::CURRENT_REVISION.substr(0, foundFirst);
		String versionMinor = COLLADABU::CURRENT_REVISION.substr(foundFirst + 1, foundLast - foundFirst -1 );

		asset.getContributor().mAuthoringTool = AUTHORING_TOOL_NAME + MGlobal::mayaVersion().asChar() +
			(COLLADABU::CURRENT_REVISION.empty() ? "" : String(";  ") + String("Version: ") + versionMajor + "." + versionMinor) +
			(COLLADABU::CURRENT_REVISION.empty() ? "" : String(";  ") + String("Revision: ") + COLLADABU::CURRENT_REVISION.substr(foundLast + 1));
		
        // comments
		MString optstr = MString("\n\t\t\tColladaMaya export options: ")
			+ "\n\t\t\tbakeTransforms=" + ExportOptions::bakeTransforms()
			+ ";relativePaths=" + ExportOptions::relativePaths()
			+ ";preserveSourceTree=" + ExportOptions::preserveSourceTree()
			+ ";copyTextures=" + ExportOptions::copyTextures()
			+ ";exportTriangles=" + ExportOptions::exportTriangles()
			+ ";exportCgfxFileReferences=" + ExportOptions::exportCgfxFileReferences()
			+ ";\n\t\t\tisSampling=" + ExportOptions::isSampling()
			+ ";curveConstrainSampling=" + ExportOptions::curveConstrainSampling()
			+ ";removeStaticCurves=" + ExportOptions::removeStaticCurves()
			+ ";exportPhysics=" + ExportOptions::exportPhysics()
            + ";exportConvexMeshGeometries=" + ExportOptions::exportConvexMeshGeometries()
            + ";exportPolygonMeshes=" + ExportOptions::exportPolygonMeshes() 
            + ";exportLights=" + ExportOptions::exportLights() 
            + ";\n\t\t\texportCameras=" + ExportOptions::exportCameras() 
			+ ";exportAnimationsOnly=" + ExportOptions::exportAnimationsOnly()
			+ ";exportSeparateFile=" + ExportOptions::exportSeparateFile()
			+ ";modelNameDAE=" + ExportOptions::getDAEmodelName()
            + ";exportJoints=" + ExportOptions::exportJoints() 
			+ ";exportSkin=" + ExportOptions::exportSkin()
            + ";exportAnimations=" + ExportOptions::exportAnimations()
            + ";exportOptimizedBezierAnimation=" + ExportOptions::exportOptimizedBezierAnimations()
            + ";exportInvisibleNodes=" + ExportOptions::exportInvisibleNodes()
            + ";exportDefaultCameras=" + ExportOptions::exportDefaultCameras()
            + ";\n\t\t\texportTexCoords=" + ExportOptions::exportTexCoords()
            + ";exportNormals=" + ExportOptions::exportNormals() 
            + ";exportNormalsPerVertex=" + ExportOptions::exportNormalsPerVertex() 
            + ";exportVertexColors=" + ExportOptions::exportVertexColors()
            + ";exportVertexColorsPerVertex=" + ExportOptions::exportVertexColorsPerVertex()
            + ";\n\t\t\texportTexTangents=" + ExportOptions::exportTexTangents() 
            + ";exportTangents=" + ExportOptions::exportTangents() 
            + ";exportReferencedMaterials=" + ExportOptions::exportReferencedMaterials() 
            + ";exportMaterialsOnly=" + ExportOptions::exportMaterialsOnly() 
            + ";\n\t\t\texportXRefs=" + ExportOptions::exportXRefs() 
            + ";dereferenceXRefs=" + ExportOptions::dereferenceXRefs() 
            + ";exportCameraAsLookat=" + ExportOptions::exportCameraAsLookat() 
            + ";cameraXFov=" + ExportOptions::cameraXFov() 
            + ";cameraYFov=" + ExportOptions::cameraYFov() 
            + ";doublePrecision=" + ExportOptions::doublePrecision () + "\n\t\t";
        asset.getContributor().mComments = optstr.asChar();

        // Up axis
        if ( MGlobal::isYAxisUp() ) 
            asset.setUpAxisType ( COLLADASW::Asset::Y_UP );
        else if ( MGlobal::isZAxisUp() ) 
            asset.setUpAxisType ( COLLADASW::Asset::Z_UP );

        // Retrieve the linear unit name
        MString mayaLinearUnitName;
        MGlobal::executeCommand ( "currentUnit -q -linear -fullName;", mayaLinearUnitName );
        String linearUnitName = mayaLinearUnitName.asChar();

        // Get the UI unit type (internal units are centimeter, collada want
        // a number relative to meters).
        // All transform components with units will be in maya's internal units
        // (radians for rotations and centimeters for translations).
        MDistance testDistance ( 1.0f, MDistance::uiUnit() );

        // Get the conversion factor relative to meters for the collada document.
        // For example, 1.0 for the name "meter"; 1000 for the name "kilometer";
        // 0.3048 for the name "foot".
        double colladaConversionFactor = ( float ) testDistance.as ( MDistance::kMeters );
        float colladaUnitFactor = float ( 1.0 / colladaConversionFactor );
        asset.setUnit ( linearUnitName, colladaConversionFactor );

        // Asset heraus schreiben
        asset.add();
    }