示例#1
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 {
                }
            }
        }
示例#2
0
        private void buildLightNodes()
        {
            MItDependencyNodes it = new MItDependencyNodes(MFn.Type.kLight);
            while( !it.isDone )
            {
                MObject mayaObj = it.thisNode;
                if( shouldPruneLight(mayaObj) )
                {
                    it.next();
                    continue;
                }

                // Create a new light and add it to the all lights list.
                MayaLight light = new MayaLight();
                allLights.Add(light);
                light.id = allLights.Count - 1;
                // Get the dag node of the light for its name and parent.
                MFnDagNode dagNode = new MFnDagNode(mayaObj);
                dagNode.getPath(light.mayaObjectPath);
                light.name = dagNode.fullPathName;
                // First parent is the source transform node.
                light.sourceXform = pathXformMap[(new MFnDagNode(dagNode.parent(0))).fullPathName];
                // Add the light to the dictionary to search by name.
                pathLightMap[light.name] = light;

                //
                // NOTE: Parent transforms of light sources in Maya can NOT be frozen,
                //       so accessing them is guaranteed to not be frozen.
                //

                if( mayaObj.hasFn(MFn.Type.kAmbientLight) )
                {
                    MFnAmbientLight mayaLight = new MFnAmbientLight(mayaObj);
                    light.type = MayaLight.Type.kAmbient;
                    light.color = new Color(mayaLight.color.r, mayaLight.color.g, mayaLight.color.b, mayaLight.color.a);
                    light.intensity = mayaLight.intensity;
                }
                else if( mayaObj.hasFn(MFn.Type.kDirectionalLight) )
                {
                    MFnDirectionalLight mayaLight = new MFnDirectionalLight(mayaObj);
                    light.type = MayaLight.Type.kDirectional;
                    light.color = new Color(mayaLight.color.r, mayaLight.color.g, mayaLight.color.b, mayaLight.color.a);
                    light.intensity = mayaLight.intensity;
                }
                else if( mayaObj.hasFn(MFn.Type.kPointLight) )
                {
                    MFnPointLight mayaLight = new MFnPointLight(mayaObj);
                    light.type = MayaLight.Type.kPoint;
                    light.color = new Color(mayaLight.color.r, mayaLight.color.g, mayaLight.color.b, mayaLight.color.a);
                    light.intensity = mayaLight.intensity;
                    light.range = (float)mayaLight.centerOfIllumination;
                }
                else if( mayaObj.hasFn(MFn.Type.kSpotLight) )
                {
                    MFnSpotLight mayaLight = new MFnSpotLight(mayaObj);
                    light.type = MayaLight.Type.kSpot;
                    light.color = new Color(mayaLight.color.r, mayaLight.color.g, mayaLight.color.b, mayaLight.color.a);
                    light.intensity = mayaLight.intensity;
                    light.range = (float)mayaLight.centerOfIllumination;
                    float mayaConeAngle = (float)(mayaLight.coneAngle * 0.5);
                    light.coneInnerAngle = 57.29578f * mayaConeAngle;
                    light.coneOuterAngle = 57.29578f * (mayaConeAngle + Math.Abs((float)mayaLight.penumbraAngle));
                }

                it.next();
            }
        }
示例#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 {
                }
            }
        }
示例#4
0
        private void buildLightNodes()
        {
            MItDependencyNodes it = new MItDependencyNodes(MFn.Type.kLight);

            while (!it.isDone)
            {
                MObject mayaObj = it.thisNode;
                if (shouldPruneLight(mayaObj))
                {
                    it.next();
                    continue;
                }

                // Create a new light and add it to the all lights list.
                MayaLight light = new MayaLight();
                allLights.Add(light);
                light.id = allLights.Count - 1;
                // Get the dag node of the light for its name and parent.
                MFnDagNode dagNode = new MFnDagNode(mayaObj);
                dagNode.getPath(light.mayaObjectPath);
                light.name = dagNode.fullPathName;
                // First parent is the source transform node.
                light.sourceXform = pathXformMap[(new MFnDagNode(dagNode.parent(0))).fullPathName];
                // Add the light to the dictionary to search by name.
                pathLightMap[light.name] = light;

                //
                // NOTE: Parent transforms of light sources in Maya can NOT be frozen,
                //       so accessing them is guaranteed to not be frozen.
                //

                if (mayaObj.hasFn(MFn.Type.kAmbientLight))
                {
                    MFnAmbientLight mayaLight = new MFnAmbientLight(mayaObj);
                    light.type      = MayaLight.Type.kAmbient;
                    light.color     = new Color(mayaLight.color.r, mayaLight.color.g, mayaLight.color.b, mayaLight.color.a);
                    light.intensity = mayaLight.intensity;
                }
                else if (mayaObj.hasFn(MFn.Type.kDirectionalLight))
                {
                    MFnDirectionalLight mayaLight = new MFnDirectionalLight(mayaObj);
                    light.type      = MayaLight.Type.kDirectional;
                    light.color     = new Color(mayaLight.color.r, mayaLight.color.g, mayaLight.color.b, mayaLight.color.a);
                    light.intensity = mayaLight.intensity;
                }
                else if (mayaObj.hasFn(MFn.Type.kPointLight))
                {
                    MFnPointLight mayaLight = new MFnPointLight(mayaObj);
                    light.type      = MayaLight.Type.kPoint;
                    light.color     = new Color(mayaLight.color.r, mayaLight.color.g, mayaLight.color.b, mayaLight.color.a);
                    light.intensity = mayaLight.intensity;
                    light.range     = (float)mayaLight.centerOfIllumination;
                }
                else if (mayaObj.hasFn(MFn.Type.kSpotLight))
                {
                    MFnSpotLight mayaLight = new MFnSpotLight(mayaObj);
                    light.type      = MayaLight.Type.kSpot;
                    light.color     = new Color(mayaLight.color.r, mayaLight.color.g, mayaLight.color.b, mayaLight.color.a);
                    light.intensity = mayaLight.intensity;
                    light.range     = (float)mayaLight.centerOfIllumination;
                    float mayaConeAngle = (float)(mayaLight.coneAngle * 0.5);
                    light.coneInnerAngle = 57.29578f * mayaConeAngle;
                    light.coneOuterAngle = 57.29578f * (mayaConeAngle + Math.Abs((float)mayaLight.penumbraAngle));
                }

                it.next();
            }
        }