Ejemplo n.º 1
0
        /// <summary>
        /// Recursively draw in channel-edit mode
        /// </summary>
        /// <param name="frame"></param>
        /// <param name="lod"></param>
        /// <param name="style"></param>
        private void RecursiveDrawChannelMode(JointFrame frame, float lod, Cytoplasm.DesignStyle style)
        {
            try
            {
                // Render this frame's mesh
                Cytoplasm cytoplasm = (Cytoplasm)frame.MeshContainer;							// get first Cytoplasm mesh in this frame
                while (cytoplasm != null)														// for each mesh...
                {
                    switch (frame.Type)
                    {
                        // If this is a socket, render it in a colour determined by whether it is selected or not
                        case JointFrame.FrameType.Socket:
                            if (frame == Lab.SelectedSocket)
                                cytoplasm.Render(frame, lod, Color.Red, Color.Red);				// selected socket
                            else if (style != Cytoplasm.DesignStyle.Other)
                                cytoplasm.Render(frame, lod, Color.White, Color.White);			// unselected sockets on selected organism
                            break;

                        // If this is a channel, render it in a colour determined by its chemical preference
                        // And flash it if it is being edited
                        case JointFrame.FrameType.Channel:

                            int chem = channel[frame.Index].chemical;							// the chemical number for this channel
                            Color c = Chemistry.Colour[chem];									// the colour of that chemical
                            if ((this == Lab.SelectedCell) && (Lab.SelectedChannel == frame.Index))	// if we are the channel selected for editing
                            {
                                float time = Scene.TotalElapsedTime % 0.3f;						// get current fraction of a second
                                if (time > 0.15f)												// flash 1:1
                                {
                                    //c = Color.DarkGray;
                                    c = Color.FromArgb(c.R / 3, c.G / 3, c.B / 3);				// flash between bright and dark versions
                                }
                            }
                            cytoplasm.Render(frame, lod, Color.FromArgb(1,1,1), c);             // Use only emissive for clarity. Diffuse is dark (mustn't be black - means ignore)
                            break;

                        // If this is a functional block, render it in yellow
                        case JointFrame.FrameType.Function:
                            cytoplasm.Render(frame, lod, Color.Yellow, Color.Yellow);
                            break;

                        // Cell membrane is rendered in wireframe on a selected creature, so that we can see organelles
                        case JointFrame.FrameType.General:
                        case JointFrame.FrameType.Animating:
                            Engine.Device.RenderState.FillMode = FillMode.WireFrame;
                            if (style == Cytoplasm.DesignStyle.Selected)
                                cytoplasm.Render(frame, lod, Color.DarkRed, Color.DarkRed);
                            else
                                cytoplasm.Render(frame, lod, Color.DarkGreen, Color.DarkGreen);
                            Engine.Device.RenderState.FillMode = FillMode.Solid;
                            break;
                    }

                    // and repeat for any other meshes in frame
                    cytoplasm = (Cytoplasm)cytoplasm.NextContainer;
                }
            }
            catch (Exception e)
            {
                throw new SDKException("ERROR: Unable to draw organelle " + frame.Name + " in cell " + name, e);
            }

            // Render any siblings
            if (frame.Sibling != null)
            {
                RecursiveDrawChannelMode(frame.Sibling, lod, style);
            }

            // Render children and their siblings
            if (frame.FirstChild != null)
            {
                RecursiveDrawChannelMode(frame.FirstChild, lod, style);
            }
        }
Ejemplo n.º 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 static void LoadMesh(XFileData node, string name, int depth, JointFrame thisFrame)
        {
            //			Debug.WriteLine(Depth(depth) + "Creating Mesh "+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
            Cytoplasm cyt = new Cytoplasm(folder,name,mesh,materials,effects,adjacency,null);
            thisFrame.MeshContainer = cyt;
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Recursively draw in cell edit mode
        /// </summary>
        /// <param name="frame"></param>
        /// <param name="lod"></param>
        /// <param name="style"></param>
        private void RecursiveDrawCellMode(JointFrame frame, float lod, Cytoplasm.DesignStyle style)
        {
            // Render this frame's mesh
            Cytoplasm cytoplasm = (Cytoplasm)frame.MeshContainer;							// get first Cytoplasm mesh in this frame
            while (cytoplasm != null)														// for each mesh...
            {
                switch (frame.Type)
                {
                    // If this is the cell membrane, render it in a colour determined by whether it is selected or not
                    case JointFrame.FrameType.General:
                    case JointFrame.FrameType.Animating:
                        if (style == Cytoplasm.DesignStyle.Selected)
                            cytoplasm.Render(frame, lod, Color.Blue, Color.Black);
                        else
                            cytoplasm.Render(frame, lod, Color.White, Color.Black);
                        break;

                    // If this is a socket, render it in a colour determined by whether it is selected or not
                    case JointFrame.FrameType.Socket:
                        if (frame == Lab.SelectedSocket)
                            cytoplasm.Render(frame, lod, Color.Red, Color.Red);
                        else
                            cytoplasm.Render(frame, lod, Color.White, Color.White);
                        break;

                    // All other parts are unrendered
                }

                // and repeat for any other meshes in frame
                cytoplasm = (Cytoplasm)cytoplasm.NextContainer;
            }

            // Render any siblings
            if (frame.Sibling != null)
            {
                RecursiveDrawCellMode(frame.Sibling, lod, style);
            }

            // Render children and their siblings
            if (frame.FirstChild != null)
            {
                RecursiveDrawCellMode(frame.FirstChild, lod, style);
            }
        }