Ejemplo n.º 1
0
        /// <summary>
        /// Post-processes nodes, attaches light and camera targets, that kind of stuff
        /// </summary>
        /// <param name="_Node"></param>
        protected void  PostProcessNodes(Scene.Nodes.Node _Node)
        {
            if (_Node is Scene.Nodes.Camera)
            {
                (_Node as Scene.Nodes.Camera).TargetNode = m_Scene.FindNode(_Node.Name + ".Target", true);
            }
            else if (_Node is Scene.Nodes.Light)
            {
                (_Node as Scene.Nodes.Light).TargetNode = m_Scene.FindNode(_Node.Name + ".Target", true);
            }

            foreach (Scene.Nodes.Node Child in _Node.Children)
            {
                PostProcessNodes(Child);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Processes a FBX node and converts it into a Cirrus object
        /// </summary>
        /// <param name="_FBXNode"></param>
        /// <param name="_ParentNode"></param>
        protected void  RecurseProcessNode(FBXImporter.Node _FBXNode, Scene.Nodes.Node _ParentNode)
        {
            Scene.Nodes.Node NewNode = _ParentNode;
            if (_FBXNode is FBXImporter.NodeMesh)
            {
                NewNode = CreateMesh(_FBXNode as FBXImporter.NodeMesh, _ParentNode);                    // Create a new mesh
            }
            else if (_FBXNode is FBXImporter.NodeCamera)
            {
                NewNode = CreateCamera(_FBXNode as FBXImporter.NodeCamera, _ParentNode);
            }
            else if (_FBXNode is FBXImporter.NodeLight)
            {
                NewNode = CreateLight(_FBXNode as FBXImporter.NodeLight, _ParentNode);
            }
            else
            {                   // Create a default node that is just here to respect the hierarchy for PRS evaluation
                Matrix4x4 LocalTransform = _FBXNode.LocalTransform;
                if (_ParentNode == null)
                {
                    if (_FBXNode.ParentScene.UpAxis == FBXImporter.Scene.UP_AXIS.Y)
                    {                           // Nothing to change here...
                        LocalTransform.SetRow0(new Vector(1.0f, 0.0f, 0.0f));
                        LocalTransform.SetRow1(new Vector(0.0f, 1.0f, 0.0f));
                        LocalTransform.SetRow2(new Vector(0.0f, 0.0f, 1.0f));
                    }
                    else
                    {                           // Tweak the root node's transform to match DirectX representation
                        LocalTransform.SetRow0(new Vector(1.0f, 0.0f, 0.0f));
                        LocalTransform.SetRow1(new Vector(0.0f, 0.0f, -1.0f));
                        LocalTransform.SetRow2(new Vector(0.0f, 1.0f, 0.0f));
                    }
                }

                NewNode = m_Scene.CreateNode(_FBXNode.Name, _ParentNode, LocalTransform);
            }

            // Recurse through children
            foreach (FBXImporter.Node Child in _FBXNode.Children)
            {
                RecurseProcessNode(Child, NewNode);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Creates a Cirrus light node
        /// </summary>
        /// <param name="_FBXMesh"></param>
        /// <param name="_Parent"></param>
        /// <returns></returns>
        protected Scene.Nodes.Light     CreateLight(FBXImporter.NodeLight _FBXLight, Scene.Nodes.Node _Parent)
        {
            // Create the cirrus mesh and tie it to our temporary mesh
            Scene.Nodes.Light Light = m_Scene.CreateLight(_FBXLight.Name, _Parent, _FBXLight.LocalTransform);

            // Add some properties
            Light.Visible               = _FBXLight.Visible;
            Light.Type                  = (Scene.Nodes.Light.LIGHT_TYPE)_FBXLight.LightType;
            Light.CastShadow            = _FBXLight.CastShadows;
            Light.Color                 = _FBXLight.Color;
            Light.Intensity             = _FBXLight.Intensity;
            Light.EnableNearAttenuation = _FBXLight.EnableNearAttenuation;
            Light.NearAttenuationStart  = _FBXLight.NearAttenuationStart * m_ScaleFactor;
            Light.NearAttenuationEnd    = _FBXLight.NearAttenuationEnd * m_ScaleFactor;
            Light.EnableFarAttenuation  = _FBXLight.EnableFarAttenuation;
            Light.FarAttenuationStart   = _FBXLight.FarAttenuationStart * m_ScaleFactor;
            Light.FarAttenuationEnd     = _FBXLight.FarAttenuationEnd * m_ScaleFactor;
            Light.HotSpot               = _FBXLight.HotSpot;
            Light.ConeAngle             = _FBXLight.ConeAngle;
            Light.DecayType             = (Scene.Nodes.Light.DECAY_TYPE)_FBXLight.DecayType;
            Light.DecayStart            = _FBXLight.DecayStart * m_ScaleFactor;

            return(Light);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Creates a Cirrus camera node
        /// </summary>
        /// <param name="_FBXMesh"></param>
        /// <param name="_Parent"></param>
        /// <returns></returns>
        protected Scene.Nodes.Camera    CreateCamera(FBXImporter.NodeCamera _FBXCamera, Scene.Nodes.Node _Parent)
        {
            // Create the cirrus mesh and tie it to our temporary mesh
            Scene.Nodes.Camera Camera = m_Scene.CreateCamera(_FBXCamera.Name, _Parent, _FBXCamera.LocalTransform);

            // Add some properties
            Camera.Visible     = _FBXCamera.Visible;
            Camera.Type        = (Scene.Nodes.Camera.PROJECTION_TYPE)_FBXCamera.ProjectionType;
            Camera.Target      = m_ScaleFactor * (Vector)_FBXCamera.Target;
            Camera.FOV         = _FBXCamera.FOVY;
            Camera.AspectRatio = _FBXCamera.AspectRatio;
            Camera.ClipNear    = _FBXCamera.NearClipPlane * m_ScaleFactor;
            Camera.ClipFar     = _FBXCamera.FarClipPlane * m_ScaleFactor;
            Camera.Roll        = _FBXCamera.Roll;

            return(Camera);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Creates a Cirrus mesh node
        /// </summary>
        /// <param name="_Scene"></param>
        /// <param name="_FBXMesh"></param>
        /// <returns></returns>
        protected Scene.Nodes.Mesh      CreateMesh(FBXImporter.NodeMesh _FBXMesh, Scene.Nodes.Node _Parent)
        {
            // Create a temporary mesh that will be optimized later, when all meshes have been loaded
            LoaderTempMesh TempMesh = new LoaderTempMesh(this, _FBXMesh.Name);

            if (m_bGenerateBoundingBoxes)
            {
                TempMesh.BoundingBox = new WMath.BoundingBox(m_ScaleFactor * _FBXMesh.BoundingBox.m_Min, m_ScaleFactor * _FBXMesh.BoundingBox.m_Max);
            }

            // Handle pivot & reset X-Form
            if (m_bResetXForm)
            {
                TempMesh.Pivot = _FBXMesh.Pivot;                        // Storing the mesh's pivot will have the effect of composing vertices with that matrix, actually performing the "reset X-Form" operation
            }
//          else
//              Transform.Pivot = _FBXNode.Pivot;	// Storing the mesh's pivot here will simply compose the mesh's transform with its pivot

            // Setup compulsory vertices and triangles
            Point[] SourceVertices = _FBXMesh.Vertices;
            Point[] ScaledVertices = new Point[SourceVertices.Length];
            for (int VertexIndex = 0; VertexIndex < _FBXMesh.VerticesCount; VertexIndex++)
            {
                ScaledVertices[VertexIndex] = m_ScaleFactor * SourceVertices[VertexIndex];
            }

            TempMesh.SetVertices(ScaledVertices);
            TempMesh.SetFaces(_FBXMesh.Triangles);

            // Setup all the possible recognized layers
            foreach (FBXImporter.Layer Layer in _FBXMesh.Layers)
            {
                foreach (FBXImporter.LayerElement LE in Layer.Elements)
                {
                    switch (LE.ElementType)
                    {
                    case FBXImporter.LayerElement.ELEMENT_TYPE.MATERIAL:
                    case FBXImporter.LayerElement.ELEMENT_TYPE.UV:
                    case FBXImporter.LayerElement.ELEMENT_TYPE.NORMAL:
                    case FBXImporter.LayerElement.ELEMENT_TYPE.TANGENT:
                    case FBXImporter.LayerElement.ELEMENT_TYPE.BINORMAL:
                    case FBXImporter.LayerElement.ELEMENT_TYPE.VERTEX_COLOR:
                    case FBXImporter.LayerElement.ELEMENT_TYPE.SMOOTHING:
                        TempMesh.AddLayerElement(LE);
                        break;

                    default:
                        break;                                  // Other types are not supported (or irrelevant)...
                    }
                }
            }

            // Build un-optimized primitives
            TempMesh.BuildPrimitives();

            // Create the final scene mesh and tie it to our temporary mesh
            FBX.Scene.Nodes.Mesh Mesh = m_Scene.CreateMesh(_FBXMesh.Name, _Parent, _FBXMesh.LocalTransform);
            m_TempMesh2FinalMesh[TempMesh] = Mesh;

            // Add some properties
            Mesh.Visible = _FBXMesh.Visible;

//          FBXImporter.ObjectProperty	PropertyCastShadow = _FBXMesh.FindUserProperty( "CastShadow" );
//          Mesh.CastShadow = PropertyCastShadow != null ? (bool) PropertyCastShadow.Value : true;
            Mesh.CastShadow    = true;
            Mesh.ReceiveShadow = true;

            return(Mesh);
        }