Ejemplo n.º 1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="mDagPath">DAG path to the transform above light</param>
        /// <param name="babylonScene"></param>
        /// <returns></returns>
        private BabylonNode ExportLight(MDagPath mDagPath, BabylonScene babylonScene)
        {
            RaiseMessage(mDagPath.partialPathName, 1);

            // Transform above light
            MFnTransform mFnTransform = new MFnTransform(mDagPath);

            // Light direct child of the transform
            MFnLight mFnLight = null;

            for (uint i = 0; i < mFnTransform.childCount; i++)
            {
                MObject childObject = mFnTransform.child(i);
                if (childObject.hasFn(MFn.Type.kLight))
                {
                    var _mFnLight = new MFnLight(childObject);
                    if (!_mFnLight.isIntermediateObject)
                    {
                        mFnLight = _mFnLight;
                    }
                }
            }
            if (mFnLight == null)
            {
                RaiseError("No light found has child of " + mDagPath.fullPathName);
                return(null);
            }

            RaiseMessage("mFnLight.fullPathName=" + mFnLight.fullPathName, 2);

            // --- prints ---
            #region prints

            // MFnLight
            RaiseVerbose("BabylonExporter.Light | mFnLight data", 2);
            RaiseVerbose("BabylonExporter.Light | mFnLight.color.toString()=" + mFnLight.color.toString(), 3);
            RaiseVerbose("BabylonExporter.Light | mFnLight.intensity=" + mFnLight.intensity, 3);
            RaiseVerbose("BabylonExporter.Light | mFnLight.useRayTraceShadows=" + mFnLight.useRayTraceShadows, 3);
            RaiseVerbose("BabylonExporter.Light | mFnLight.shadowColor.toString()=" + mFnLight.shadowColor.toString(), 3);
            RaiseVerbose("BabylonExporter.Light | mFnLight.centerOfIllumination=" + mFnLight.centerOfIllumination, 3);
            RaiseVerbose("BabylonExporter.Light | mFnLight.numShadowSamples=" + mFnLight.numShadowSamples, 3);
            RaiseVerbose("BabylonExporter.Light | mFnLight.rayDepthLimit=" + mFnLight.rayDepthLimit, 3);
            RaiseVerbose("BabylonExporter.Light | mFnLight.opticalFXvisibility.toString()=" + mFnLight.opticalFXvisibility.toString(), 3);
            RaiseVerbose("BabylonExporter.Light | mFnLight.lightIntensity.toString()=" + mFnLight.lightIntensity.toString(), 3);
            RaiseVerbose("BabylonExporter.Light | mFnLight.instanceCount(true)=" + mFnLight.instanceCount(true), 3);
            RaiseVerbose("BabylonExporter.Light | mFnLight.lightDirection(0).toString()=" + mFnLight.lightDirection(0).toString(), 3);
            RaiseVerbose("BabylonExporter.Light | mFnLight.lightAmbient=" + mFnLight.lightAmbient, 3);
            RaiseVerbose("BabylonExporter.Light | mFnLight.lightDiffuse=" + mFnLight.lightDiffuse, 3);
            RaiseVerbose("BabylonExporter.Light | mFnLight.lightSpecular=" + mFnLight.lightSpecular, 3);

            switch (mFnLight.objectProperty.apiType)
            {
            case MFn.Type.kSpotLight:
                MFnSpotLight mFnSpotLight = new MFnSpotLight(mFnLight.objectProperty);
                // MFnNonAmbientLight
                RaiseVerbose("BabylonExporter.Light | mFnSpotLight.decayRate=" + mFnSpotLight.decayRate, 3);     // dropdown enum value
                // MFnNonExtendedLight
                RaiseVerbose("BabylonExporter.Light | mFnSpotLight.shadowRadius=" + mFnSpotLight.shadowRadius, 3);
                RaiseVerbose("BabylonExporter.Light | mFnSpotLight.castSoftShadows=" + mFnSpotLight.castSoftShadows, 3);
                RaiseVerbose("BabylonExporter.Light | mFnSpotLight.useDepthMapShadows=" + mFnSpotLight.useDepthMapShadows, 3);
                RaiseVerbose("BabylonExporter.Light | mFnSpotLight.depthMapFilterSize()=" + mFnSpotLight.depthMapFilterSize(), 3);
                RaiseVerbose("BabylonExporter.Light | mFnSpotLight.depthMapResolution()=" + mFnSpotLight.depthMapResolution(), 3);
                RaiseVerbose("BabylonExporter.Light | mFnSpotLight.depthMapBias()=" + mFnSpotLight.depthMapBias(), 3);
                // MFnSpotLight
                RaiseVerbose("BabylonExporter.Light | mFnSpotLight.coneAngle=" + mFnSpotLight.coneAngle, 3);
                RaiseVerbose("BabylonExporter.Light | mFnSpotLight.penumbraAngle=" + mFnSpotLight.penumbraAngle, 3);
                RaiseVerbose("BabylonExporter.Light | mFnSpotLight.dropOff=" + mFnSpotLight.dropOff, 3);
                RaiseVerbose("BabylonExporter.Light | mFnSpotLight.barnDoors=" + mFnSpotLight.barnDoors, 3);
                RaiseVerbose("BabylonExporter.Light | mFnSpotLight.useDecayRegions=" + mFnSpotLight.useDecayRegions, 3);
                RaiseVerbose("BabylonExporter.Light | mFnSpotLight.startDistance(MFnSpotLight.MDecayRegion.kFirst)=" + mFnSpotLight.startDistance(MFnSpotLight.MDecayRegion.kFirst), 3);
                RaiseVerbose("BabylonExporter.Light | mFnSpotLight.endDistance(MFnSpotLight.MDecayRegion.kFirst)=" + mFnSpotLight.endDistance(MFnSpotLight.MDecayRegion.kFirst), 3);
                RaiseVerbose("BabylonExporter.Light | mFnSpotLight.startDistance(MFnSpotLight.MDecayRegion.kSecond)=" + mFnSpotLight.startDistance(MFnSpotLight.MDecayRegion.kSecond), 3);
                RaiseVerbose("BabylonExporter.Light | mFnSpotLight.endDistance(MFnSpotLight.MDecayRegion.kSecond)=" + mFnSpotLight.endDistance(MFnSpotLight.MDecayRegion.kSecond), 3);
                RaiseVerbose("BabylonExporter.Light | mFnSpotLight.startDistance(MFnSpotLight.MDecayRegion.kThird)=" + mFnSpotLight.startDistance(MFnSpotLight.MDecayRegion.kThird), 3);
                RaiseVerbose("BabylonExporter.Light | mFnSpotLight.endDistance(MFnSpotLight.MDecayRegion.kThird)=" + mFnSpotLight.endDistance(MFnSpotLight.MDecayRegion.kThird), 3);
                break;
            }

            Print(mFnTransform, 2, "Print ExportLight mFnTransform");

            Print(mFnLight, 2, "Print ExportLight mFnLight");

            #endregion

            if (IsLightExportable(mFnLight, mDagPath) == false)
            {
                return(null);
            }

            var babylonLight = new BabylonLight {
                name = mFnTransform.name, id = mFnTransform.uuid().asString()
            };

            // Hierarchy
            ExportHierarchy(babylonLight, mFnTransform);

            // User custom attributes
            babylonLight.metadata = ExportCustomAttributeFromTransform(mFnTransform);

            // Position
            //RaiseVerbose("BabylonExporter.Light | ExportTransform", 2);
            float[] position = null;
            GetTransform(mFnTransform, ref position);
            babylonLight.position = position;

            // Direction
            var vDir = new MVector(0, 0, -1);
            var transformationMatrix = new MTransformationMatrix(mFnTransform.transformationMatrix);
            vDir = vDir.multiply(transformationMatrix.asMatrixProperty);
            vDir.normalize();
            babylonLight.direction = new[] { (float)vDir.x, (float)vDir.y, -(float)vDir.z };

            // Common fields
            babylonLight.intensity = mFnLight.intensity;
            babylonLight.diffuse   = mFnLight.lightDiffuse ? mFnLight.color.toArrayRGB() : new float[] { 0, 0, 0 };
            babylonLight.specular  = mFnLight.lightSpecular ? mFnLight.color.toArrayRGB() : new float[] { 0, 0, 0 };

            // Type
            switch (mFnLight.objectProperty.apiType)
            {
            case MFn.Type.kPointLight:
                babylonLight.type = 0;
                break;

            case MFn.Type.kSpotLight:
                MFnSpotLight mFnSpotLight = new MFnSpotLight(mFnLight.objectProperty);
                babylonLight.type     = 2;
                babylonLight.angle    = (float)mFnSpotLight.coneAngle;
                babylonLight.exponent = 1;

                if (mFnSpotLight.useDecayRegions)
                {
                    babylonLight.range = mFnSpotLight.endDistance(MFnSpotLight.MDecayRegion.kThird);     // Max distance
                }
                break;

            case MFn.Type.kDirectionalLight:
                babylonLight.type = 1;
                break;

            case MFn.Type.kAmbientLight:
                babylonLight.type        = 3;
                babylonLight.groundColor = new float[] { 0, 0, 0 };

                // No emit diffuse /specular checkbox for ambient light
                babylonLight.diffuse  = mFnLight.color.toArrayRGB();
                babylonLight.specular = babylonLight.diffuse;

                // Direction
                vDir = new MVector(0, 1, 0);
                transformationMatrix = new MTransformationMatrix(mFnTransform.transformationMatrix);
                vDir = vDir.multiply(transformationMatrix.asMatrixProperty);
                vDir.normalize();
                babylonLight.direction = new[] { (float)vDir.x, (float)vDir.y, -(float)vDir.z };
                break;

            case MFn.Type.kAreaLight:
            case MFn.Type.kVolumeLight:
                RaiseError("Unsupported light type '" + mFnLight.objectProperty.apiType + "' for DAG path '" + mFnLight.fullPathName + "'. Light is ignored. Supported light types are: ambient, directional, point and spot.", 1);
                return(null);

            default:
                RaiseWarning("Unknown light type '" + mFnLight.objectProperty.apiType + "' for DAG path '" + mFnLight.fullPathName + "'. Light is ignored.", 1);
                return(null);
            }

            // TODO - Shadows

            //Variable declaration
            MStringArray  enlightedMeshesFullPathNames = new MStringArray();
            List <string> includeMeshesIds             = new List <string>();
            MStringArray  kTransMesh = new MStringArray();
            String        typeMesh   = null;
            MStringArray  UUIDMesh   = new MStringArray();

            //MEL Command that get the enlighted mesh for a given light
            MGlobal.executeCommand($@"lightlink -query -light {mFnTransform.fullPathName};", enlightedMeshesFullPathNames);

            //For each enlighted mesh
            foreach (String Mesh in enlightedMeshesFullPathNames)
            {
                //MEL Command use to get the type of each mesh
                typeMesh = MGlobal.executeCommandStringResult($@"nodeType -api {Mesh};");

                //We are targeting the type kMesh and not kTransform (for parenting)
                if (typeMesh == "kMesh")
                {
                    MGlobal.executeCommand($@"listRelatives -parent -fullPath {Mesh};", kTransMesh);

                    //And finally the MEL Command for the uuid of each mesh
                    MGlobal.executeCommand($@"ls -uuid {kTransMesh[0]};", UUIDMesh);
                    includeMeshesIds.Add(UUIDMesh[0]);
                }
            }

            babylonLight.includedOnlyMeshesIds = includeMeshesIds.ToArray();

            // Animations
            if (exportParameters.bakeAnimationFrames)
            {
                ExportNodeAnimationFrameByFrame(babylonLight, mFnTransform);
            }
            else
            {
                ExportNodeAnimation(babylonLight, mFnTransform);
            }

            babylonScene.LightsList.Add(babylonLight);

            return(babylonLight);
        }
Ejemplo n.º 2
0
        private void doScan(MItDag.TraversalType traversalType, MFn.Type filter, bool quiet)
        {
            MItDag dagIterator = new MItDag(traversalType, filter);

            //	Scan the entire DAG and output the name and depth of each node

            if (traversalType == MItDag.TraversalType.kBreadthFirst)
            {
                if (!quiet)
                {
                    MGlobal.displayInfo(Environment.NewLine + "Starting Breadth First scan of the Dag");
                }
                else
                if (!quiet)
                {
                    MGlobal.displayInfo(Environment.NewLine + "Starting Depth First scan of the Dag");
                }
            }

            switch (filter)
            {
            case MFn.Type.kCamera:
                if (!quiet)
                {
                    MGlobal.displayInfo(": Filtering for Cameras\n");
                }
                break;

            case MFn.Type.kLight:
                if (!quiet)
                {
                    MGlobal.displayInfo(": Filtering for Lights\n");
                }
                break;

            case MFn.Type.kNurbsSurface:
                if (!quiet)
                {
                    MGlobal.displayInfo(": Filtering for Nurbs Surfaces\n");
                }
                break;

            default:
                MGlobal.displayInfo(Environment.NewLine);
                break;
            }


            int objectCount = 0;

            for ( ; !dagIterator.isDone; dagIterator.next())
            {
                MDagPath dagPath = new MDagPath();

                try
                {
                    dagIterator.getPath(dagPath);
                }
                catch (System.Exception)
                {
                    continue;
                }

                MFnDagNode dagNode = null;
                try
                {
                    dagNode = new MFnDagNode(dagPath);
                }
                catch (System.Exception)
                {
                    continue;
                }

                if (!quiet)
                {
                    MGlobal.displayInfo(dagNode.name + ": " + dagNode.typeName + Environment.NewLine);
                }

                if (!quiet)
                {
                    MGlobal.displayInfo("  dagPath: " + dagPath.fullPathName + Environment.NewLine);
                }

                objectCount += 1;
                if (dagPath.hasFn(MFn.Type.kCamera))
                {
                    MFnCamera camera = null;
                    try
                    {
                        camera = new MFnCamera(dagPath);
                    }
                    catch (System.Exception)
                    {
                        continue;
                    }

                    // Get the translation/rotation/scale data
                    //
                    printTransformData(dagPath, quiet);

                    // Extract some interesting Camera data
                    //
                    if (!quiet)
                    {
                        MGlobal.displayInfo("  eyePoint: " + MPointToString(camera.eyePoint(MSpace.Space.kWorld)) + Environment.NewLine);

                        MGlobal.displayInfo("  upDirection: " + MVectorToString(camera.upDirection(MSpace.Space.kWorld)) + Environment.NewLine);

                        MGlobal.displayInfo("  viewDirection: " + MVectorToString(camera.viewDirection(MSpace.Space.kWorld)) + Environment.NewLine);

                        MGlobal.displayInfo("  aspectRatio: " + Convert.ToString(camera.aspectRatio) + Environment.NewLine);

                        MGlobal.displayInfo("  horizontalFilmAperture: " + Convert.ToString(camera.horizontalFilmAperture) + Environment.NewLine);

                        MGlobal.displayInfo("  verticalFilmAperture: " + Convert.ToString(camera.verticalFilmAperture) + Environment.NewLine);
                    }
                }
                else if (dagPath.hasFn(MFn.Type.kLight))
                {
                    MFnLight light = null;
                    try
                    {
                        light = new MFnLight(dagPath);
                    }
                    catch (System.Exception)
                    {
                        continue;
                    }

                    // Get the translation/rotation/scale data
                    //
                    printTransformData(dagPath, quiet);

                    // Extract some interesting Light data
                    //
                    MColor color = light.color;
                    if (!quiet)
                    {
                        MGlobal.displayInfo(string.Format("  color: [%f, %f, %f]\n", color.r, color.g, color.b));
                    }
                    color = light.shadowColor;
                    if (!quiet)
                    {
                        MGlobal.displayInfo(string.Format("  shadowColor: [%f, %f, %f]\n", color.r, color.g, color.b));
                        MGlobal.displayInfo("  intensity: " + Convert.ToString(light.intensity) + Environment.NewLine);
                    }
                }
                else if (dagPath.hasFn(MFn.Type.kNurbsSurface))
                {
                    MFnNurbsSurface surface = null;
                    try
                    {
                        surface = new MFnNurbsSurface(dagPath);
                    }
                    catch (System.Exception)
                    {
                        continue;
                    }

                    // Get the translation/rotation/scale data
                    //
                    printTransformData(dagPath, quiet);

                    // Extract some interesting Surface data
                    //
                    if (!quiet)
                    {
                        MGlobal.displayInfo(string.Format("  numCVs: %d * %s", surface.numCVsInU, surface.numCVsInV) + Environment.NewLine);
                        MGlobal.displayInfo(string.Format("  numKnots: %d * %s\n", surface.numKnotsInU, surface.numKnotsInV) + Environment.NewLine);
                        MGlobal.displayInfo(string.Format("  numSpans: %d * %s\n", surface.numSpansInU, surface.numSpansInV) + Environment.NewLine);
                    }
                }
                else
                {
                    // Get the translation/rotation/scale data
                    //
                    printTransformData(dagPath, quiet);
                }
            }

            setResult(objectCount);
        }
Ejemplo n.º 3
0
        public void ResetLights()
        {
            //<AmbientLight Color="White" />
            //<DirectionalLight Color="White" Direction="-1,-1,-1" />
            //<PointLight Color="White" ConstantAttenuation="1" LinearAttenuation="1" Position="0,0,0" QuadraticAttenuation="1" Range="0" />
            //<SpotLight Color="White" ConstantAttenuation="1" Direction="-1,-1,-1" InnerConeAngle="10" LinearAttenuation="1" OuterConeAngle="10" Position="0,0,0" QuadraticAttenuation="1" Range="0" />
            lights.Children.Clear();

            MItDag dagIterator = new MItDag(MItDag.TraversalType.kDepthFirst, MFn.Type.kLight);

            for ( ; !dagIterator.isDone; dagIterator.next())
            {
                MDagPath lightPath = new MDagPath();
                dagIterator.getPath(lightPath);

                MFnLight light     = new MFnLight(lightPath);
                bool     isAmbient = light.lightAmbient;
                MColor   mcolor    = light.color;
                Color    color     = Color.FromScRgb(1.0f, mcolor.r, mcolor.g, mcolor.b);
                if (isAmbient)
                {
                    AmbientLight ambient = new AmbientLight(color);
                    lights.Children.Add(ambient);
                    continue;
                }

                MFloatVector lightDirection = light.lightDirection(0, MSpace.Space.kWorld);
                Vector3D     direction      = new Vector3D(lightDirection.x, lightDirection.y, lightDirection.z);
                bool         isDiffuse      = light.lightDiffuse;
                try {
                    MFnDirectionalLight dirLight    = new MFnDirectionalLight(lightPath);
                    DirectionalLight    directional = new DirectionalLight(color, direction);
                    lights.Children.Add(directional);
                    continue;
                } catch {
                }

                MObject               transformNode = lightPath.transform;
                MFnDagNode            transform     = new MFnDagNode(transformNode);
                MTransformationMatrix matrix        = new MTransformationMatrix(transform.transformationMatrix);
                double []             threeDoubles  = new double [3];
                int rOrder = 0;                 //MTransformationMatrix.RotationOrder rOrder ;
                matrix.getRotation(threeDoubles, out rOrder, MSpace.Space.kWorld);
                matrix.getScale(threeDoubles, MSpace.Space.kWorld);
                MVector pos      = matrix.getTranslation(MSpace.Space.kWorld);
                Point3D position = new Point3D(pos.x, pos.y, pos.z);
                try {
                    MFnPointLight pointLight = new MFnPointLight(lightPath);
                    PointLight    point      = new PointLight(color, position);
                    //point.ConstantAttenuation =pointLight. ; // LinearAttenuation / QuadraticAttenuation
                    //point.Range =pointLight.rayDepthLimit ;
                    lights.Children.Add(point);
                    continue;
                } catch {
                }

                try {
                    MFnSpotLight spotLight      = new MFnSpotLight(lightPath);
                    MAngle       InnerConeAngle = new MAngle(spotLight.coneAngle);
                    MAngle       OuterConeAngle = new MAngle(spotLight.penumbraAngle);
                    SpotLight    spot           = new SpotLight(color, position, direction, OuterConeAngle.asDegrees, InnerConeAngle.asDegrees);
                    spot.ConstantAttenuation = spotLight.dropOff;                     // LinearAttenuation / QuadraticAttenuation
                    //spot.Range =spotLight.rayDepthLimit ;
                    lights.Children.Add(spot);
                    continue;
                } catch {
                }
            }
        }
Ejemplo n.º 4
0
        public void ResetLights()
        {
            //<AmbientLight Color="White" />
            //<DirectionalLight Color="White" Direction="-1,-1,-1" />
            //<PointLight Color="White" ConstantAttenuation="1" LinearAttenuation="1" Position="0,0,0" QuadraticAttenuation="1" Range="0" />
            //<SpotLight Color="White" ConstantAttenuation="1" Direction="-1,-1,-1" InnerConeAngle="10" LinearAttenuation="1" OuterConeAngle="10" Position="0,0,0" QuadraticAttenuation="1" Range="0" />
            lights.Children.Clear () ;

            MItDag dagIterator =new MItDag (MItDag.TraversalType.kDepthFirst, MFn.Type.kLight) ;
            for ( ; !dagIterator.isDone ; dagIterator.next () ) {
                MDagPath lightPath =new MDagPath () ;
                dagIterator.getPath (lightPath) ;

                MFnLight light =new MFnLight (lightPath) ;
                bool isAmbient =light.lightAmbient ;
                MColor mcolor =light.color ;
                Color color =Color.FromScRgb (1.0f, mcolor.r, mcolor.g, mcolor.b) ;
                if ( isAmbient ) {
                    AmbientLight ambient =new AmbientLight (color) ;
                    lights.Children.Add (ambient) ;
                    continue ;
                }

                MFloatVector lightDirection =light.lightDirection (0, MSpace.Space.kWorld) ;
                Vector3D direction =new Vector3D (lightDirection.x, lightDirection.y, lightDirection.z) ;
                bool isDiffuse =light.lightDiffuse ;
                try {
                    MFnDirectionalLight dirLight =new MFnDirectionalLight (lightPath) ;
                    DirectionalLight directional =new DirectionalLight (color, direction) ;
                    lights.Children.Add (directional) ;
                    continue ;
                } catch {
                }

                MObject transformNode =lightPath.transform ;
                MFnDagNode transform =new MFnDagNode (transformNode) ;
                MTransformationMatrix matrix =new MTransformationMatrix (transform.transformationMatrix) ;
                double [] threeDoubles =new double [3] ;
                int rOrder =0 ; //MTransformationMatrix.RotationOrder rOrder ;
                matrix.getRotation (threeDoubles, out rOrder, MSpace.Space.kWorld) ;
                matrix.getScale (threeDoubles, MSpace.Space.kWorld) ;
                MVector pos =matrix.getTranslation (MSpace.Space.kWorld) ;
                Point3D position =new Point3D (pos.x, pos.y, pos.z) ;
                try {
                    MFnPointLight pointLight =new MFnPointLight (lightPath) ;
                    PointLight point =new PointLight (color, position) ;
                    //point.ConstantAttenuation =pointLight. ; // LinearAttenuation / QuadraticAttenuation
                    //point.Range =pointLight.rayDepthLimit ;
                    lights.Children.Add (point) ;
                    continue ;
                } catch {
                }

                try {
                    MFnSpotLight spotLight =new MFnSpotLight (lightPath) ;
                    MAngle InnerConeAngle =new MAngle (spotLight.coneAngle) ;
                    MAngle OuterConeAngle =new MAngle (spotLight.penumbraAngle) ;
                    SpotLight spot =new SpotLight (color, position, direction, OuterConeAngle.asDegrees, InnerConeAngle.asDegrees) ;
                    spot.ConstantAttenuation =spotLight.dropOff ; // LinearAttenuation / QuadraticAttenuation
                    //spot.Range =spotLight.rayDepthLimit ;
                    lights.Children.Add (spot) ;
                    continue ;
                } catch {
                }
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="mDagPath">DAG path to the transform above light</param>
        /// <param name="babylonScene"></param>
        /// <returns></returns>
        private BabylonNode ExportLight(MDagPath mDagPath, BabylonScene babylonScene)
        {
            RaiseMessage(mDagPath.partialPathName, 1);

            // Transform above light
            MFnTransform mFnTransform = new MFnTransform(mDagPath);

            // Light direct child of the transform
            MFnLight mFnLight = null;

            for (uint i = 0; i < mFnTransform.childCount; i++)
            {
                MObject childObject = mFnTransform.child(i);
                if (childObject.hasFn(MFn.Type.kLight))
                {
                    mFnLight = new MFnLight(childObject);
                }
            }
            if (mFnLight == null)
            {
                RaiseError("No light found has child of " + mDagPath.fullPathName);
                return(null);
            }

            RaiseMessage("mFnLight.fullPathName=" + mFnLight.fullPathName, 2);


            // --- prints ---
            #region prints

            // MFnLight
            RaiseVerbose("BabylonExporter.Light | mFnLight data", 2);
            RaiseVerbose("BabylonExporter.Light | mFnLight.color.toString()=" + mFnLight.color.toString(), 3);
            RaiseVerbose("BabylonExporter.Light | mFnLight.intensity=" + mFnLight.intensity, 3);
            RaiseVerbose("BabylonExporter.Light | mFnLight.useRayTraceShadows=" + mFnLight.useRayTraceShadows, 3);
            RaiseVerbose("BabylonExporter.Light | mFnLight.shadowColor.toString()=" + mFnLight.shadowColor.toString(), 3);
            RaiseVerbose("BabylonExporter.Light | mFnLight.centerOfIllumination=" + mFnLight.centerOfIllumination, 3);
            RaiseVerbose("BabylonExporter.Light | mFnLight.numShadowSamples=" + mFnLight.numShadowSamples, 3);
            RaiseVerbose("BabylonExporter.Light | mFnLight.rayDepthLimit=" + mFnLight.rayDepthLimit, 3);
            RaiseVerbose("BabylonExporter.Light | mFnLight.opticalFXvisibility.toString()=" + mFnLight.opticalFXvisibility.toString(), 3);
            RaiseVerbose("BabylonExporter.Light | mFnLight.lightIntensity.toString()=" + mFnLight.lightIntensity.toString(), 3);
            RaiseVerbose("BabylonExporter.Light | mFnLight.instanceCount(true)=" + mFnLight.instanceCount(true), 3);
            RaiseVerbose("BabylonExporter.Light | mFnLight.lightDirection(0).toString()=" + mFnLight.lightDirection(0).toString(), 3);
            RaiseVerbose("BabylonExporter.Light | mFnLight.lightAmbient=" + mFnLight.lightAmbient, 3);
            RaiseVerbose("BabylonExporter.Light | mFnLight.lightDiffuse=" + mFnLight.lightDiffuse, 3);
            RaiseVerbose("BabylonExporter.Light | mFnLight.lightSpecular=" + mFnLight.lightSpecular, 3);

            switch (mFnLight.objectProperty.apiType)
            {
            case MFn.Type.kSpotLight:
                MFnSpotLight mFnSpotLight = new MFnSpotLight(mFnLight.objectProperty);
                // MFnNonAmbientLight
                RaiseVerbose("BabylonExporter.Light | mFnSpotLight.decayRate=" + mFnSpotLight.decayRate, 3);     // dropdown enum value
                // MFnNonExtendedLight
                RaiseVerbose("BabylonExporter.Light | mFnSpotLight.shadowRadius=" + mFnSpotLight.shadowRadius, 3);
                RaiseVerbose("BabylonExporter.Light | mFnSpotLight.castSoftShadows=" + mFnSpotLight.castSoftShadows, 3);
                RaiseVerbose("BabylonExporter.Light | mFnSpotLight.useDepthMapShadows=" + mFnSpotLight.useDepthMapShadows, 3);
                RaiseVerbose("BabylonExporter.Light | mFnSpotLight.depthMapFilterSize()=" + mFnSpotLight.depthMapFilterSize(), 3);
                RaiseVerbose("BabylonExporter.Light | mFnSpotLight.depthMapResolution()=" + mFnSpotLight.depthMapResolution(), 3);
                RaiseVerbose("BabylonExporter.Light | mFnSpotLight.depthMapBias()=" + mFnSpotLight.depthMapBias(), 3);
                // MFnSpotLight
                RaiseVerbose("BabylonExporter.Light | mFnSpotLight.coneAngle=" + mFnSpotLight.coneAngle, 3);
                RaiseVerbose("BabylonExporter.Light | mFnSpotLight.penumbraAngle=" + mFnSpotLight.penumbraAngle, 3);
                RaiseVerbose("BabylonExporter.Light | mFnSpotLight.dropOff=" + mFnSpotLight.dropOff, 3);
                RaiseVerbose("BabylonExporter.Light | mFnSpotLight.barnDoors=" + mFnSpotLight.barnDoors, 3);
                RaiseVerbose("BabylonExporter.Light | mFnSpotLight.useDecayRegions=" + mFnSpotLight.useDecayRegions, 3);
                RaiseVerbose("BabylonExporter.Light | mFnSpotLight.startDistance(MFnSpotLight.MDecayRegion.kFirst)=" + mFnSpotLight.startDistance(MFnSpotLight.MDecayRegion.kFirst), 3);
                RaiseVerbose("BabylonExporter.Light | mFnSpotLight.endDistance(MFnSpotLight.MDecayRegion.kFirst)=" + mFnSpotLight.endDistance(MFnSpotLight.MDecayRegion.kFirst), 3);
                RaiseVerbose("BabylonExporter.Light | mFnSpotLight.startDistance(MFnSpotLight.MDecayRegion.kSecond)=" + mFnSpotLight.startDistance(MFnSpotLight.MDecayRegion.kSecond), 3);
                RaiseVerbose("BabylonExporter.Light | mFnSpotLight.endDistance(MFnSpotLight.MDecayRegion.kSecond)=" + mFnSpotLight.endDistance(MFnSpotLight.MDecayRegion.kSecond), 3);
                RaiseVerbose("BabylonExporter.Light | mFnSpotLight.startDistance(MFnSpotLight.MDecayRegion.kThird)=" + mFnSpotLight.startDistance(MFnSpotLight.MDecayRegion.kThird), 3);
                RaiseVerbose("BabylonExporter.Light | mFnSpotLight.endDistance(MFnSpotLight.MDecayRegion.kThird)=" + mFnSpotLight.endDistance(MFnSpotLight.MDecayRegion.kThird), 3);
                break;
            }

            #endregion

            if (IsLightExportable(mFnLight, mDagPath) == false)
            {
                return(null);
            }

            var babylonLight = new BabylonLight {
                name = mFnTransform.name, id = mFnTransform.uuid().asString()
            };

            // Hierarchy
            ExportHierarchy(babylonLight, mFnTransform);

            // Position
            RaiseVerbose("BabylonExporter.Light | ExportTransform", 2);
            float[] position = null;
            GetTransform(mFnTransform, ref position);
            babylonLight.position = position;

            // Direction
            var vDir = new MVector(0, 0, -1);
            var transformationMatrix = new MTransformationMatrix(mFnTransform.transformationMatrix);
            vDir = vDir.multiply(transformationMatrix.asMatrixProperty);
            vDir.normalize();
            babylonLight.direction = new[] { (float)vDir.x, (float)vDir.y, -(float)vDir.z };

            // Common fields
            babylonLight.intensity = mFnLight.intensity;

            babylonLight.diffuse  = mFnLight.lightDiffuse ? mFnLight.color.toArrayRGB() : new float[] { 0, 0, 0 };
            babylonLight.specular = mFnLight.lightSpecular ? mFnLight.color.toArrayRGB() : new float[] { 0, 0, 0 };

            // Type
            switch (mFnLight.objectProperty.apiType)
            {
            case MFn.Type.kPointLight:
                babylonLight.type = 0;
                break;

            case MFn.Type.kSpotLight:
                MFnSpotLight mFnSpotLight = new MFnSpotLight(mFnLight.objectProperty);
                babylonLight.type     = 2;
                babylonLight.angle    = (float)mFnSpotLight.coneAngle;
                babylonLight.exponent = 1;

                if (mFnSpotLight.useDecayRegions)
                {
                    babylonLight.range = mFnSpotLight.endDistance(MFnSpotLight.MDecayRegion.kThird);     // Max distance
                }
                break;

            case MFn.Type.kDirectionalLight:
                babylonLight.type = 1;
                break;

            case MFn.Type.kAmbientLight:
                babylonLight.type        = 3;
                babylonLight.groundColor = new float[] { 0, 0, 0 };
                break;

            case MFn.Type.kAreaLight:
            case MFn.Type.kVolumeLight:
                RaiseError("Unsupported light type '" + mFnLight.objectProperty.apiType + "' for DAG path '" + mFnLight.fullPathName + "'. Light is ignored. Supported light types are: ambient, directional, point and spot.");
                return(null);

            default:
                RaiseWarning("Unknown light type '" + mFnLight.objectProperty.apiType + "' for DAG path '" + mFnLight.fullPathName + "'. Light is ignored.");
                return(null);
            }

            // TODO - Shadows

            // TODO - Exclusion

            // TODO - Animations

            babylonScene.LightsList.Add(babylonLight);

            return(babylonLight);
        }
Ejemplo n.º 6
0
        private void doScan(MItDag.TraversalType traversalType, MFn.Type filter, bool quiet)
        {
            MItDag dagIterator = new MItDag(traversalType, filter);

            //	Scan the entire DAG and output the name and depth of each node

            if (traversalType == MItDag.TraversalType.kBreadthFirst)
                if (!quiet)
                    MGlobal.displayInfo(Environment.NewLine + "Starting Breadth First scan of the Dag");
            else
                if (!quiet)
                    MGlobal.displayInfo(Environment.NewLine + "Starting Depth First scan of the Dag");

            switch (filter)
            {
                case MFn.Type.kCamera:
                    if (!quiet)
                        MGlobal.displayInfo( ": Filtering for Cameras\n");
                    break;
                case MFn.Type.kLight:
                    if (!quiet)
                        MGlobal.displayInfo(": Filtering for Lights\n");
                    break;
                case MFn.Type.kNurbsSurface:
                    if (!quiet)
                        MGlobal.displayInfo(": Filtering for Nurbs Surfaces\n");
                    break;
                default:
                    MGlobal.displayInfo(Environment.NewLine);
                    break;
            }

            int objectCount = 0;
            for ( ; !dagIterator.isDone; dagIterator.next() ) {

                MDagPath dagPath = new MDagPath();

                try
                {
                    dagIterator.getPath(dagPath);
                }
                catch (System.Exception )
                {
                    continue;
                }

                MFnDagNode dagNode = null;
                try
                {
                    dagNode = new MFnDagNode(dagPath);
                }
                catch (System.Exception )
                {
                    continue;
                }

                if (!quiet)
                    MGlobal.displayInfo(dagNode.name + ": " + dagNode.typeName + Environment.NewLine);

                if (!quiet)
                    MGlobal.displayInfo( "  dagPath: " + dagPath.fullPathName + Environment.NewLine);

                objectCount += 1;
                if (dagPath.hasFn(MFn.Type.kCamera))
                {
                    MFnCamera camera  =  null;
                    try
                    {
                        camera  = new MFnCamera(dagPath);
                    }
                    catch (System.Exception)
                    {
                        continue;
                    }

                    // Get the translation/rotation/scale data
                    //
                    printTransformData(dagPath, quiet);

                    // Extract some interesting Camera data
                    //
                    if (!quiet)
                    {

                        MGlobal.displayInfo("  eyePoint: " + MPointToString(camera.eyePoint(MSpace.Space.kWorld)) + Environment.NewLine);

                        MGlobal.displayInfo("  upDirection: " + MVectorToString( camera.upDirection(MSpace.Space.kWorld)) + Environment.NewLine);

                        MGlobal.displayInfo("  viewDirection: " + MVectorToString( camera.viewDirection(MSpace.Space.kWorld)) + Environment.NewLine);

                        MGlobal.displayInfo("  aspectRatio: " + Convert.ToString( camera.aspectRatio ) + Environment.NewLine);

                        MGlobal.displayInfo("  horizontalFilmAperture: " + Convert.ToString(camera.horizontalFilmAperture ) + Environment.NewLine);

                        MGlobal.displayInfo("  verticalFilmAperture: " + Convert.ToString(camera.verticalFilmAperture ) + Environment.NewLine);
                    }
                }
                else if (dagPath.hasFn(MFn.Type.kLight))
                {
                    MFnLight light = null;
                    try
                    {
                        light = new MFnLight(dagPath);
                    }
                    catch (System.Exception)
                    {
                        continue;
                    }

                    // Get the translation/rotation/scale data
                    //
                    printTransformData(dagPath, quiet);

                    // Extract some interesting Light data
                    //
                    MColor color = light.color;
                    if (!quiet)
                    {
                        MGlobal.displayInfo(string.Format("  color: [%f, %f, %f]\n", color.r, color.g, color.b));
                    }
                    color = light.shadowColor;
                    if (!quiet)
                    {

                        MGlobal.displayInfo(string.Format("  shadowColor: [%f, %f, %f]\n", color.r, color.g, color.b));
                        MGlobal.displayInfo("  intensity: "+Convert.ToString(light.intensity) + Environment.NewLine);

                    }
                }
                else if (dagPath.hasFn(MFn.Type.kNurbsSurface))
                {
                    MFnNurbsSurface surface= null;
                    try
                    {
                        surface = new MFnNurbsSurface(dagPath);
                    }
                    catch (System.Exception )
                    {
                        continue;
                    }

                    // Get the translation/rotation/scale data
                    //
                    printTransformData(dagPath, quiet);

                    // Extract some interesting Surface data
                    //
                    if (!quiet)
                    {
                        MGlobal.displayInfo(string.Format("  numCVs: %d * %s", surface.numCVsInU, surface.numCVsInV) + Environment.NewLine);
                        MGlobal.displayInfo(string.Format("  numKnots: %d * %s\n", surface.numKnotsInU, surface.numKnotsInV) + Environment.NewLine);
                        MGlobal.displayInfo(string.Format("  numSpans: %d * %s\n", surface.numSpansInU, surface.numSpansInV) + Environment.NewLine);
                    }
                } else
                {
                    // Get the translation/rotation/scale data
                    //
                    printTransformData(dagPath, quiet);
                }
            }

            setResult(objectCount);
        }