示例#1
0
 /// <summary>
 /// Read a transformation matrix and attach to the current frame
 /// </summary>
 /// <param name="node"></param>
 /// <param name="depth"></param>
 /// <param name="thisFrame"></param>
 private void ReadTransformationMatrix(XFileData node, int depth, SimFrame thisFrame)
 {
     try
     {
         Debug.WriteLine(Depth(depth) + "Creating Matrix for "+thisFrame.Name);
         GraphicsStream stream = node.Lock();							// access the data stream
         thisFrame.TransformationMatrix = MatrixFromXFile(stream);		// read in the matrix
         node.Unlock();
     }
     catch (Exception e)
     {
         Debug.WriteLine("Error reading transformation matrix: "+e.ToString());
         throw;
     }
 }
示例#2
0
        /// <summary>
        /// Read a mesh and create a Cytoplasm object from it, then attach this to the current frame
        /// </summary>
        /// <param name="node"></param>
        /// <param name="depth"></param>
        /// <param name="thisFrame"></param>
        private void ReadMesh(XFileData node, int depth, SimFrame thisFrame)
        {
            Debug.WriteLine(Depth(depth) + "Creating Mesh "+node.Name+" for "+thisFrame.Name);

            Mesh mesh = null;
            ExtendedMaterial[] materials = null;
            GraphicsStream adjacency = null;
            EffectInstance[] effects = null;

            try
            {
                mesh = Mesh.FromX(node,MeshFlags.Managed,Engine.Device,out adjacency, out materials, out effects);
                Debug.WriteLine(Depth(depth) + "Mesh "+node.Name+" has "+mesh.NumberVertices+" verts and "+materials.Length+" materials");
            }
            catch (Direct3DXException e)
            {
                Debug.WriteLine("Error reading mesh: "+e.ToString());
                throw;
            }

            // Create a Cytoplasm (meshcontainer) object from mesh, materials, etc.
            // Give it the right name (node.Name)
            // Link it into the tree of Cytoplasm objects
            // Link it to this mesh
            // TODO: thisFrame.MeshContainer = CreateCytoplasm( ---stuff---);

            MeshData md = new MeshData();									// Cytoplasm currently expects a MeshData
            md.Mesh = mesh;													// rather than a simple mesh

            thisFrame.MeshContainer = new Cytoplasm(node.Name,md,materials,effects,adjacency,null);
        }
示例#3
0
 private void ReadAnimationSet(XFileData node, int depth, SimFrame thisFrame)
 {
     Debug.WriteLine(Depth(depth) + "AnimationSet " + node.Name);
 }
示例#4
0
 /// <summary>
 /// Create a new frame from this node
 /// </summary>
 /// <param name="node">the XFileData node</param>
 /// <param name="depth">depth in hierarchy</param>
 /// <param name="thisFrame">the previous / new current frame</param>
 private void ReadFrame(XFileData node, int depth, ref SimFrame thisFrame)
 {
     SimFrame newFrame = new SimFrame(node.Name);					// Create a new frame
     if (thisFrame==null)											// if there's no current frame
     {																// the new frame is the root
         Debug.WriteLine(Depth(depth) + "Creating frame "+newFrame.Name+" as root");
         thisFrame = newFrame;
         rootFrame = thisFrame;
     }
     else if (thisFrame.FirstChild==null)							// or, if we're in a new level
     {
         Debug.WriteLine(Depth(depth) + "Creating frame "+newFrame.Name+" as child of "+thisFrame.Name);
         thisFrame.FirstChild = newFrame;							// attach as first child of parent
         thisFrame = newFrame;										// and move down a generation
     }
     else															// else we're a sibling
     {
         SimFrame bigSister = thisFrame.FirstChild;
         while (bigSister.Sibling!=null)								// so scan to the end of this row
             bigSister = bigSister.Sibling;
         Debug.WriteLine(Depth(depth) + "Creating frame "+newFrame.Name+" as sibling of "+bigSister.Name);
         bigSister.Sibling = newFrame;								// attach as a sibling
         thisFrame = newFrame;										// and start work on the new one
     }
 }
示例#5
0
        /// <summary>
        /// Recursively create frames and their contents from an XFileData object
        /// </summary>
        /// <param name="node"></param>
        /// <param name="depth"></param>
        /// <param name="parentFrame"></param>
        /// <param name="thisFrame"></param>
        private void LoadDataObject(XFileData node, int depth, SimFrame parentFrame, SimFrame thisFrame)
        {
            // --------- handle the instance nodes (references are handled later) ------------
            if (node.IsReference==false)
            {
                // **** Frame
                if (node.Type==XFileGuid.Frame)
                {
                    ReadFrame(node, depth, ref thisFrame);
                }

                    // **** FrameTransformationMatrix
                else if (node.Type==XFileGuid.FrameTransformMatrix)
                {
                    ReadTransformationMatrix(node, depth, thisFrame);
                }

                    // **** Mesh
                else if (node.Type==XFileGuid.Mesh)
                {
                    ReadMesh(node, depth, thisFrame);
                }
                    // Ignore mesh subset members (materials, normals, etc.) - they're already handled by ReadMesh()

                    // **** Animation set
                else if (node.Type==XFileGuid.AnimationSet)
                {
                    ReadAnimationSet(node, depth, thisFrame);
                }
                    // **** Animation
                else if (node.Type==XFileGuid.Animation)
                {

                }
                    // **** AnimationKey
                else if (node.Type==XFileGuid.AnimationKey)
                {

                }
                    // **** AnimationOptions
                else if (node.Type==XFileGuid.AnimationOptions)
                {

                }

                // --------- Recurse through this node's children ----------
                // Note: we mustn't touch the children of a REFERENCE node or we'll create a duplicate
                // set of frames, etc. So only run this loop if we've just handled an INSTANCE node
                for (int i=0; i<node.NumberChildren; i++)
                {
                    using (XFileData child = node.GetChild(i))
                    {
                        LoadDataObject(child, depth++, parentFrame, thisFrame);
                    }
                }

            }

                // --------- deal with REFERENCES to existing instances (e.g inside animation nodes) ----------
            else
            {
                // **** Frame reference
                if (node.Type==XFileGuid.Frame)
                {
                    SimFrame refFrame = null; /////rootFrame.Find(node.Name);
                }

            }
        }