Esempio n. 1
0
        public override void SaveData(ref AnimatTools.DataObjects.Simulation dsSim, ref AnimatTools.DataObjects.Physical.PhysicalStructure doStructure, ref AnimatTools.Interfaces.StdXml oXml)
        {
            base.SaveData (ref dsSim, ref doStructure, ref oXml);

            oXml.IntoElem();

            oXml.AddChildElement("LowerRadius", m_fLowerRadius);
            oXml.AddChildElement("UpperRadius", m_fUpperRadius);
            oXml.AddChildElement("Height", m_fHeight);
            oXml.AddChildElement("CollisionLowerRadius", m_fLowerRadius);
            oXml.AddChildElement("CollisionUpperRadius", m_fUpperRadius);
            oXml.AddChildElement("CollisionHeight", m_fHeight);

            oXml.OutOfElem(); //out of body
        }
        public override void SaveData(ref AnimatTools.DataObjects.Simulation dsSim, ref AnimatTools.DataObjects.Physical.PhysicalStructure doStructure, ref AnimatTools.Interfaces.StdXml oXml)
        {
            base.SaveData (ref dsSim, ref doStructure, ref oXml);
            Vector3 v3Rot = Util_DX.DecomposeXYZRotationMatrix(this.CombinedTransformationMatrix);

            Vector3 rot = m_v3Rotation;
            rot.Normalize();
            AnimatTools.Framework.Vec3d v = new Vec3d(null, rot.X, rot.Y, rot.Z);

            oXml.IntoElem();
                //oXml.AddChildElement("Stiffness", this.Stiffness.ActualValue);
                //oXml.AddChildElement("Damping", this.Damping.ActualValue);
                oXml.AddChildElement("ConstraintHalfAngle",m_fHalfAngle);

                m_v3Axis.TransformCoordinate(Matrix.RotationX(Geometry.DegreeToRadian(180)) * Matrix.RotationY(Geometry.DegreeToRadian(180)) * Matrix.RotationZ(Geometry.DegreeToRadian(180)) * Matrix.RotationX(v3Rot.X)* Matrix.RotationY(v3Rot.Y) * Matrix.RotationZ(v3Rot.Z));

                Vec3d vRotationAxis = new Vec3d(null,m_v3Axis.X, m_v3Axis.Y, m_v3Axis.Z);
                Util.SaveVector(ref oXml, "ConstraintAxis", vRotationAxis);
            oXml.OutOfElem();

            m_v3Axis = new Vector3(0,0,1);
        }
        public override void SaveData(ref AnimatTools.DataObjects.Simulation dsSim, ref AnimatTools.DataObjects.Physical.PhysicalStructure doStructure, ref AnimatTools.Interfaces.StdXml oXml)
        {
            oXml.AddChildElement(this.BodyPartType);

            oXml.IntoElem(); //Into RigidBody Element

            oXml.AddChildElement("Name", m_strName);
            oXml.AddChildElement("ID", m_strID);
            oXml.AddChildElement("Type", this.Type);
            oXml.AddChildElement("PartType", this.PartType.ToString());
            oXml.AddChildElement("ModuleName", this.ModuleName);

            Util.SaveColor(ref oXml, "Color", m_d3dMaterial.Diffuse);

            if(m_thPrimaryAttachment != null && m_thPrimaryAttachment.BodyPart != null)
                oXml.AddChildElement("PrimaryAttachmentID", m_thPrimaryAttachment.BodyPart.ID);

            if(m_thSecondaryAttachment != null && m_thSecondaryAttachment.BodyPart != null)
                oXml.AddChildElement("SecondaryAttachmentID", m_thSecondaryAttachment.BodyPart.ID);

            m_snNaturalLength.SaveData(ref oXml, "NaturalLength");
            m_snStiffness.SaveData(ref oXml, "Stiffness");
            m_snDamping.SaveData(ref oXml, "Damping");

            oXml.AddChildElement("Enabled", m_bEnabled);
            oXml.AddChildElement("IsVisible", m_bVisible);

            oXml.OutOfElem(); //Outof RigidBody Element
        }
        public override void SaveData(ref AnimatTools.DataObjects.Simulation dsSim, ref AnimatTools.DataObjects.Physical.PhysicalStructure doStructure, ref AnimatTools.Interfaces.StdXml oXml)
        {
            base.SaveData (ref dsSim, ref doStructure, ref oXml);

            oXml.IntoElem();

            if(!oXml.FindChildElement("Constraint", false))
                oXml.AddChildElement("Constraint");
            oXml.IntoElem();
            oXml.SetAttrib("Low",this.m_fltMinMovement);
            oXml.SetAttrib("High", this.m_fltMaxMovement);
            oXml.OutOfElem();

            oXml.AddChildElement("Length", m_fltLength);
            oXml.AddChildElement("EnableMotor",this.m_bEnableMotor);
            oXml.AddChildElement("ServoMotor",this.m_bServoMotor);
            oXml.AddChildElement("ServoGain",this.m_fltServoGain);
            m_snMaxForce.SaveData(ref oXml, "MaxForce");
            m_snMaxVelocity.SaveData(ref oXml, "MaxVelocity");

            RigidBodies.RigidBody_DX rbParent = (RigidBodies.RigidBody_DX)this.Parent;
            Vector3 v3Rot = Util_DX.DecomposeXYZRotationMatrix(this.CombinedTransformationMatrix);;
            float x = Geometry.DegreeToRadian(180);
            m_v3Axis.TransformCoordinate(Matrix.RotationX(Geometry.DegreeToRadian(180)) * Matrix.RotationY(Geometry.DegreeToRadian(180)) * Matrix.RotationZ(Geometry.DegreeToRadian(180)) * Matrix.RotationX(v3Rot.X)* Matrix.RotationY(v3Rot.Y) * Matrix.RotationZ(v3Rot.Z));
            Vec3d vRotationAxis = new Vec3d(null,m_v3Axis.X, m_v3Axis.Y, m_v3Axis.Z);
            Util.SaveVector(ref oXml, "RotationAxis", vRotationAxis);
            m_v3Axis = new Vector3(0,0,1);

            oXml.OutOfElem();
        }
        public static void SaveMatrix(ref AnimatTools.Interfaces.StdXml oXml, string strName,  Matrix mtxM)
        {
            string str = mtxM.M11.ToString() +"," + mtxM.M12.ToString() +"," + mtxM.M13.ToString() +"," + mtxM.M14.ToString() +",";
            str += mtxM.M21.ToString() +"," + mtxM.M22.ToString() +"," + mtxM.M23.ToString() +"," + mtxM.M24.ToString() +",";
            str += mtxM.M31.ToString() +"," + mtxM.M32.ToString() +"," + mtxM.M33.ToString() +"," + mtxM.M34.ToString() +",";
            str += mtxM.M41.ToString() +"," + mtxM.M42.ToString() +"," + mtxM.M43.ToString() +"," + mtxM.M44.ToString();

            oXml.AddChildElement(strName,str);
        }
        public override void LoadData(ref AnimatTools.DataObjects.Simulation dsSim, ref AnimatTools.DataObjects.Physical.PhysicalStructure doStructure, ref AnimatTools.Interfaces.StdXml oXml)
        {
            m_aryChildBodies.Clear();

            oXml.IntoElem(); //'Into RigidBody Element

            m_strID = oXml.GetChildString("ID");
            m_strName = oXml.GetChildString("Name", m_strID);
            m_strDescription = oXml.GetChildString("Description", "");

            if(m_strName.Trim().Length == 0)
                m_strName = m_strID;

            if(oXml.FindChildElement("Color", false))
            {
                System.Drawing.Color oColor = Util.LoadColor(ref oXml, "Color");
                this.Alpha = oColor.A;
                this.Color = oColor;
            }

            if(oXml.FindChildElement("MuscleAttachments", false))
            {
                oXml.IntoElem();

                oXml.AddChildElement("Description", m_strDescription);

                if(oXml.NumberOfChildren() > 2)
                    throw new System.Exception("The standard spring can not have more than 2 attachment points.");
                else if(oXml.NumberOfChildren() == 2)
                {
                    oXml.FindChildByIndex(0);
                    m_strPrimaryAttachID = oXml.GetChildString();
                    oXml.FindChildByIndex(1);
                    m_strSecondaryAttachID = oXml.GetChildString();
                }
                else if(oXml.NumberOfChildren() == 1)
                {
                    oXml.FindChildByIndex(0);
                    m_strPrimaryAttachID = oXml.GetChildString();
                }
                else
                {
                    m_strPrimaryAttachID = "";
                    m_strSecondaryAttachID = "";
                }

                oXml.OutOfElem();
            }
            else
            {
                if(oXml.FindChildElement("PrimaryAttachmentID", false))
                    m_strPrimaryAttachID = oXml.GetChildString("PrimaryAttachmentID");

                if(oXml.FindChildElement("SecondaryAttachmentID", false))
                    m_strSecondaryAttachID = oXml.GetChildString("SecondaryAttachmentID");
            }

            m_snNaturalLength.LoadData(ref oXml, "NaturalLength");
            m_snStiffness.LoadData(ref oXml, "Stiffness");
            m_snDamping.LoadData(ref oXml, "Damping");

            m_bEnabled = oXml.GetChildBool("Enabled", m_bEnabled);
            m_bVisible = oXml.GetChildBool("IsVisible", m_bVisible);

            oXml.OutOfElem(); //Outof RigidBody Element
        }
        public override void SaveData(ref AnimatTools.DataObjects.Simulation dsSim, ref AnimatTools.DataObjects.Physical.PhysicalStructure doStructure, ref AnimatTools.Interfaces.StdXml oXml)
        {
            base.SaveData(ref dsSim, ref doStructure, ref oXml);

            oXml.IntoElem(); //'Into RigidBody Element

            oXml.AddChildElement("ApplyTension", m_bApplyTension);
            m_snIaDischargeConstant.SaveData(ref oXml, "IaDischarge");
            m_snIIDischargeConstant.SaveData(ref oXml, "IIDischarge");

            oXml.OutOfElem(); //Outof RigidBody Element
        }
        public override void SaveXml(ref AnimatTools.Interfaces.StdXml oXml)
        {
            if(m_doOrganism == null)
                throw new System.Exception("No organism was defined for the stimulus '" + m_strName + "'.");

            if(m_doNode == null)
                throw new System.Exception("No node was defined for the stimulus '" + m_strName + "'.");

            //I have no idea why, but unders some conditions the object link we have to the node does not point to the
            //actual node. We need to re-get the link to make sure that the node index is actually valid.
            m_doNode = m_doOrganism.FindBehavioralNode(m_doNode.ID, true);

            if(m_doNode != null && m_thMuscle != null && m_thMuscle.BodyPart != null && m_strMuscleLengthData != null && m_strMuscleLengthData.Length > 0)
            {
                oXml.AddChildElement("Stimulus");

                oXml.IntoElem();
                oXml.AddChildElement("ID", m_strID);
                oXml.AddChildElement("Name", m_strName);

                //The module name needs to be blank so it is created from the physics class factory.
                //But we still need to know which neural module to load the neuron from.
                oXml.AddChildElement("ModuleName", this.StimulusModuleName);
                oXml.AddChildElement("NeuralModuleName", m_doNode.DataColumnModuleName);
                oXml.AddChildElement("Type", this.StimulusClassType);

                oXml.AddChildElement("OrganismID", m_doOrganism.ID);
                oXml.AddChildElement("TargetNodeID", m_doNode.NodeIndex);

                oXml.AddChildElement("MuscleID", m_thMuscle.BodyPart.ID);
                oXml.AddChildElement("LengthData", m_strMuscleLengthData);
                oXml.AddChildElement("Conductance", m_snConductance.ActualValue);
                oXml.AddChildElement("RestPotential", m_snRestPotential.ActualValue);

                oXml.OutOfElem();
            }
        }
        public override void SaveData(ref AnimatTools.DataObjects.Simulation dsSim, ref AnimatTools.DataObjects.Physical.PhysicalStructure doStructure, ref AnimatTools.Interfaces.StdXml oXml)
        {
            base.SaveData (ref dsSim, ref doStructure, ref oXml);

            oXml.IntoElem();
            oXml.AddChildElement("Height", m_fltHeight);
            oXml.AddChildElement("HeightFieldImage", m_strHeightFieldImage);
            Util.SaveVector(ref oXml, "MapLocation", m_vMapLocation);
            Util.SaveVector(ref oXml, "MapSize", m_vMapSize);
            oXml.AddChildElement("MapScale", m_fltMapScale);
            oXml.OutOfElem(); //out of body
        }
        public override void SaveData(ref AnimatTools.Interfaces.StdXml oXml)
        {
            Vector3 v3Rot = Util_DX.DecomposeXYZRotationMatrix(m_mtxOrientation);
            m_fltRotateX = v3Rot.X;
            m_fltRotateY = v3Rot.Y;
            m_fltRotateZ = v3Rot.Z;

            oXml.AddChildElement("PanX", m_fltPanX);
            oXml.AddChildElement("PanY", m_fltPanY);
            oXml.AddChildElement("Zoom", m_fltZoom);
            oXml.AddChildElement("RotateX", m_fltRotateX);
            oXml.AddChildElement("RotateY", m_fltRotateY);
            oXml.AddChildElement("RotateZ", m_fltRotateZ);
            Util.SaveColor(ref oXml, "BackColor", m_clBackColor);
        }
        public override void SaveData(ref AnimatTools.DataObjects.Simulation dsSim, ref AnimatTools.DataObjects.Physical.PhysicalStructure doStructure, ref AnimatTools.Interfaces.StdXml oXml)
        {
            base.SaveData(ref dsSim, ref doStructure, ref oXml);

            oXml.IntoElem(); //Into RigidBody Element

            m_snNaturalLength.SaveData(ref oXml, "NaturalLength");
            m_snStiffness.SaveData(ref oXml, "Stiffness");
            m_snDamping.SaveData(ref oXml, "Damping");
            oXml.AddChildElement("ForceType", m_eForceType.ToString());

            oXml.OutOfElem(); //Outof RigidBody Element
        }
        public override void SaveData(ref AnimatTools.DataObjects.Simulation dsSim, ref AnimatTools.DataObjects.Physical.PhysicalStructure doStructure, ref AnimatTools.Interfaces.StdXml oXml)
        {
            base.SaveData (ref dsSim, ref doStructure, ref oXml);

            oXml.IntoElem();

            if(m_thOdorType != null && m_thOdorType.OdorType != null)
                oXml.AddChildElement("OdorTypeID", m_thOdorType.OdorType.ID);

            oXml.OutOfElem(); //out of body
        }
        public static void SaveMeshVertices(ref AnimatTools.Interfaces.StdXml oXml, string strName, Mesh myMesh, bool bSaveIndices)
        {
            CustomVertex.PositionNormalTextured[] cvVerts = new CustomVertex.PositionNormalTextured[myMesh.NumberVertices];

            oXml.AddChildElement(strName);
            oXml.IntoElem();  //Into the mesh

            GraphicsStream buffer = myMesh.LockVertexBuffer(LockFlags.ReadOnly);
            AnimatTools.Framework.Vec3d vVertex = new AnimatTools.Framework.Vec3d(null);

            for(int i=0; i<myMesh.NumberVertices; i++)
            {
                buffer.Position = i * myMesh.NumberBytesPerVertex;
                cvVerts[i] = (CustomVertex.PositionNormalTextured)buffer.Read(typeof(CustomVertex.PositionNormalTextured));
                //System.Diagnostics.Debug.WriteLine("v " + cvVerts[i].X + " " + cvVerts[i].Y + " " + cvVerts[i].Z);

                vVertex.X = cvVerts[i].X;// - this.AbsoluteLocation.X;
                vVertex.Y = cvVerts[i].Y;// - this.AbsoluteLocation.Y;
                vVertex.Z = cvVerts[i].Z;// - this.AbsoluteLocation.Z;

                Util.SaveVector(ref oXml, "Vector", vVertex);

                //Debug.WriteLine("data.Write(new CustomVertex.PositionTextured(" + vVertex.X + "f, " + vVertex.Y + "f, " + vVertex.Z + "f, 0f, 0f));");
                //if(i%3 == 0) Debug.WriteLine("");
                //Debug.WriteLine("V: " + i + "  (" + cvVerts[i].X + ", " + cvVerts[i].Y + ", " + cvVerts[i].Z + ", " + cvVerts[i].Nx + ", " + cvVerts[i].Ny + ", " + cvVerts[i].Nz + ")");
            }
            myMesh.UnlockVertexBuffer();

            if(bSaveIndices)
            {
                using (IndexBuffer ib = myMesh.IndexBuffer)
                {
                    GraphicsStream gs = ib.Lock(0, myMesh.NumberFaces*3*2, LockFlags.ReadOnly);

                    string strIndex = "";
                    short iIndex;
                    for(int i=0; i<myMesh.NumberFaces*3; i++)
                    {
                        gs.Position = i * 2;
                        iIndex = (short) gs.Read(typeof(short));

                        strIndex += iIndex.ToString();
                        if(i<gs.Length-1) strIndex += ",";
                    }

                    oXml.AddChildElement("IndexBuffer", strIndex);

                    ib.Unlock();
                }
            }

            oXml.OutOfElem();  //Out of the mesh
        }
        public override void SaveData(ref AnimatTools.Interfaces.StdXml oXml)
        {
            base.SaveData(ref oXml);

            oXml.IntoElem();

            if(m_thMuscle != null && m_thMuscle.BodyPart != null)
                oXml.AddChildElement("MuscleID", m_thMuscle.BodyPart.ID);

            oXml.AddChildElement("MuscleLengthData", m_strMuscleLengthData);
            m_snConductance.SaveData(ref oXml, "Conductance");
            m_snRestPotential.SaveData(ref oXml, "RestPotential");

            oXml.OutOfElem();
        }
        public override void SaveData(ref AnimatTools.Interfaces.StdXml oXml)
        {
            base.SaveData(ref oXml);

            oXml.IntoElem();

            if(m_thPrimaryAttachment != null && m_thPrimaryAttachment.BodyPart != null)
                oXml.AddChildElement("PrimaryAttachmentID", m_thPrimaryAttachment.BodyPart.ID);

            if(m_thSecondaryAttachment != null && m_thSecondaryAttachment.BodyPart != null)
                oXml.AddChildElement("SecondaryAttachmentID", m_thSecondaryAttachment.BodyPart.ID);

            oXml.AddChildElement("PGain", m_fltProportionalGain);
            oXml.AddChildElement("DGain", m_fltDerivativeGain);
            oXml.AddChildElement("IGain", m_fltIntegratorGain);
            oXml.AddChildElement("MaxIValue", m_fltMaxIntegratorValue);
            m_snVelocity.SaveData(ref oXml, "Velocity");
            m_snMaxForce.SaveData(ref oXml, "MaxForce");

            oXml.OutOfElem();
        }
 public override void SaveDataColumnToXml(ref AnimatTools.Interfaces.StdXml oXml)
 {
     oXml.IntoElem();
     oXml.AddChildElement("StimulusID", this.ID);
     oXml.OutOfElem();
 }
        public override void SaveXml(ref AnimatTools.Interfaces.StdXml oXml)
        {
            if(m_doStructure == null)
                throw new System.Exception("No structure was defined for the stimulus '" + m_strName + "'.");

            if(m_doBodyPart == null)
                throw new System.Exception("No bodypart was defined for the stimulus '" + m_strName + "'.");

            if(m_thPrimaryAttachment != null && m_thPrimaryAttachment.BodyPart != null &&
                m_thSecondaryAttachment != null && m_thSecondaryAttachment.BodyPart != null)
            {
                oXml.AddChildElement("Stimulus");

                oXml.IntoElem();
                oXml.AddChildElement("ID", m_strID);
                oXml.AddChildElement("Name", m_strName);
                oXml.AddChildElement("AlwaysActive", m_bAlwaysActive);

                oXml.AddChildElement("ModuleName", this.StimulusModuleName);
                oXml.AddChildElement("Type", this.StimulusClassType);

                oXml.AddChildElement("StartTime", m_snStartTime.ActualValue);
                oXml.AddChildElement("EndTime", m_snEndTime.ActualValue);

                oXml.AddChildElement("StructureID", m_doStructure.ID);
                oXml.AddChildElement("BodyID", m_doBodyPart.ID);

                oXml.AddChildElement("PrimaryAttachID", m_thPrimaryAttachment.BodyPart.ID);
                oXml.AddChildElement("SecondaryAttachID", m_thSecondaryAttachment.BodyPart.ID);
                oXml.AddChildElement("UsePosition", false);
                oXml.AddChildElement("Velocity", m_snVelocity.ActualValue);
                oXml.AddChildElement("MaxForce", m_snMaxForce.ActualValue);
                oXml.AddChildElement("PGain", m_fltProportionalGain);
                oXml.AddChildElement("DGain", m_fltDerivativeGain);
                oXml.AddChildElement("IGain", m_fltIntegratorGain);
                oXml.AddChildElement("MaxIVal", m_fltMaxIntegratorValue);

                oXml.OutOfElem();
            }
        }
        public override void SaveData(ref AnimatTools.DataObjects.Simulation dsSim, ref AnimatTools.DataObjects.Physical.PhysicalStructure doStructure, ref AnimatTools.Interfaces.StdXml oXml)
        {
            base.SaveData (ref dsSim, ref doStructure, ref oXml);

            oXml.IntoElem();

            RigidBodies.RigidBody_DX rbParent = (RigidBodies.RigidBody_DX)this.Parent;
            Vector3 v3Rot = Util_DX.DecomposeXYZRotationMatrix(this.CombinedTransformationMatrix);;
            float x = Geometry.DegreeToRadian(180);

            if(!oXml.FindChildElement("Constraint", false))
                oXml.AddChildElement("Constraint");
            oXml.IntoElem();
            oXml.SetAttrib("Low",this.m_fltMinAngle);
            oXml.SetAttrib("High", this.m_fltMaxAngle);
            oXml.OutOfElem();

            oXml.AddChildElement("EnableMotor",this.m_bEnableMotor);
            oXml.AddChildElement("ServoMotor",this.m_bServoMotor);
            oXml.AddChildElement("ServoGain",this.m_fltServoGain);

            m_snMaxTorque.SaveData(ref oXml, "MaxTorque");
            m_snMaxVelocity.SaveData(ref oXml, "MaxVelocity");

            //			if(v3Rot.Y >= 180)
            //				m_v3Axis.TransformCoordinate(/*Matrix.RotationX(Geometry.DegreeToRadian(180))*  Matrix.RotationY(Geometry.DegreeToRadian(180)) * Matrix.RotationZ(Geometry.DegreeToRadian(180)) **/ Matrix.RotationX(v3Rot.X)* Matrix.RotationY(v3Rot.Y) * Matrix.RotationZ(v3Rot.Z));
            //			else
                //m_v3Axis.TransformCoordinate(Matrix.RotationX(Geometry.DegreeToRadian(180)) * Matrix.RotationY(Geometry.DegreeToRadian(180)) * Matrix.RotationZ(Geometry.DegreeToRadian(180)) * Matrix.RotationX(v3Rot.X)* Matrix.RotationY(v3Rot.Y) * Matrix.RotationZ(v3Rot.Z));
            Matrix m = this.CombinedTransformationMatrix;
            m.M41 = 0;
            m.M42 = 0;
            m.M43 = 0;
            //Quaternion q = Quaternion.RotationYawPitchRoll(v3Rot.Y, v3Rot.X, v3Rot.Z);
            //m_v3Axis.TransformCoordinate(Matrix.RotationQuaternion(q));
            m_v3Axis.TransformCoordinate(m);

            //Vec3d vRotationAxis = new Vec3d(null,1, 0, 0);
            Vec3d vRotationAxis = new Vec3d(null,m_v3Axis.X, m_v3Axis.Y, m_v3Axis.Z);
            Util.SaveVector(ref oXml, "RotationAxis", vRotationAxis);

            oXml.OutOfElem();
            m_v3Axis = new Vector3(0,0,1);
        }
        public override void SaveData(ref AnimatTools.DataObjects.Simulation dsSim, ref AnimatTools.DataObjects.Physical.PhysicalStructure doStructure, ref AnimatTools.Interfaces.StdXml oXml)
        {
            base.SaveData (ref dsSim, ref doStructure, ref oXml);

            oXml.IntoElem();

            oXml.AddChildElement("KillOrganism", m_bKillOrganism);
            m_snMaxEnergyLevel.SaveData(ref oXml, "MaxEnergyLevel");
            m_snEnergyLevel.SaveData(ref oXml, "EnergyLevel");
            m_snBaseConsumptionRate.SaveData(ref oXml, "BaseConsumptionRate");

            oXml.OutOfElem(); //out of body
        }