Exemplo n.º 1
0
        private byte[] ProcessBallJoint(RigidBodyJoint ballJoint)
        {
            try
            {
                List <byte> ballJointBytes = new List <byte>();

                //Adds ID to signify that it's a rotational joint
                ushort ID          = 4;
                byte[] ballJointID = BitConverter.GetBytes(ID);
                ballJointBytes.AddRange(ballJointID);

                foreach (AssemblyJoint joint in ballJoint.Joints)
                {
                    //Adds the ID of the parent STL to the output array
                    STLData parentSTL = new STLData();
                    STLDictionary.TryGetValue(NameFilter(joint.OccurrenceOne.Name), out parentSTL);
                    byte[] parentIDBytes = BitConverter.GetBytes((uint)(parentSTL.getID()));
                    ballJointBytes.AddRange(parentIDBytes);
                    //Adds the ID of the child STL to the output array
                    STLData childSTL = new STLData();
                    STLDictionary.TryGetValue(NameFilter(joint.OccurrenceTwo.Name), out childSTL);
                    byte[] childIDBytes = BitConverter.GetBytes((uint)(childSTL.getID()));
                    ballJointBytes.AddRange(childIDBytes);
                    //Adds the vector parallel to the movement onto the array of bytes
                    ballJoint.GetJointData(out object GeometryOne, out object GeometryTwo, out NameValueMap nameMap);
                    Circle vectorCircle    = (Circle)GeometryTwo;
                    byte[] vectorJointData = new byte[12];
                    BitConverter.GetBytes((float)vectorCircle.Center.X).CopyTo(vectorJointData, 0);
                    BitConverter.GetBytes((float)vectorCircle.Center.Y).CopyTo(vectorJointData, 4);
                    BitConverter.GetBytes((float)vectorCircle.Center.Z).CopyTo(vectorJointData, 8);
                    ballJointBytes.AddRange(vectorJointData);
                    //Adds the point of connection relative to the parent part
                    byte[] transJointData             = new byte[12];
                    AssemblyJointDefinition jointData = joint.Definition;
                    BitConverter.GetBytes((float)jointData.OriginTwo.Point.X).CopyTo(transJointData, 0);
                    BitConverter.GetBytes((float)jointData.OriginTwo.Point.Y).CopyTo(transJointData, 4);
                    BitConverter.GetBytes((float)jointData.OriginTwo.Point.Z).CopyTo(transJointData, 8);
                    ballJointBytes.AddRange(transJointData);
                    //Adds the degrees of freedom
                    byte[]         freedomData       = new byte[8];
                    ModelParameter positionData      = (ModelParameter)jointData.AngularPosition;
                    double         relataivePosition = positionData._Value;
                    if (jointData.HasLinearPositionEndLimit)
                    {
                        positionData = (ModelParameter)jointData.AngularPositionEndLimit;
                        BitConverter.GetBytes((float)(Math.Abs(relataivePosition) - Math.Abs(positionData._Value))).CopyTo(freedomData, 0);
                    }
                    positionData = (ModelParameter)jointData.AngularPositionStartLimit;
                    BitConverter.GetBytes((float)(Math.Abs(relataivePosition) - Math.Abs(positionData._Value))).CopyTo(freedomData, 4);
                    ballJointBytes.AddRange(freedomData);
                }
                return(ballJointBytes.ToArray());
            }
            catch (Exception e)
            {
                //catches problems
                MessageBox.Show(e.Message + "\n\n\n" + e.StackTrace);
                return(null);
            }
        }
Exemplo n.º 2
0
        private byte[] ProcessLinearJoint(RigidBodyJoint linearJoint, JointData jointDataObject)
        {
            try {
                ArrayList linearJointBytes = new ArrayList();

                //Adds ID to signify that it's a linear joint
                ushort ID            = 1;
                byte[] linearJointID = BitConverter.GetBytes(ID);
                linearJointBytes.Add(linearJointID);

                foreach (AssemblyJoint joint in linearJoint.Joints)
                {
                    //Adds the ID of the parent STL to the output array
                    STLData parentSTL = new STLData();
                    STLDictionary.TryGetValue(NameFilter(joint.OccurrenceOne.Name), out parentSTL);
                    byte[] parentIDBytes = BitConverter.GetBytes((uint)(parentSTL.getID()));
                    linearJointBytes.Add(parentIDBytes);
                    //Adds the ID of the child STL to the output array
                    STLData childSTL = new STLData();
                    STLDictionary.TryGetValue(NameFilter(joint.OccurrenceTwo.Name), out childSTL);
                    byte[] childIDBytes = BitConverter.GetBytes((uint)(childSTL.getID()));
                    linearJointBytes.Add(childIDBytes);
                    //Adds the vector parallel to the movement onto the array of bytes
                    object       GeometryOne, GeometryTwo;
                    NameValueMap nameMap;
                    linearJoint.GetJointData(out GeometryOne, out GeometryTwo, out nameMap);
                    Line   vectorLine      = (Line)GeometryTwo;
                    byte[] vectorJointData = new byte[12];
                    BitConverter.GetBytes(vectorLine.RootPoint.X).CopyTo(vectorJointData, 0);
                    BitConverter.GetBytes(vectorLine.RootPoint.Y).CopyTo(vectorJointData, 4);
                    BitConverter.GetBytes(vectorLine.RootPoint.Z).CopyTo(vectorJointData, 8);
                    linearJointBytes.Add(vectorJointData);
                    //Adds the point of connection relative to the parent part
                    byte[] transJointData             = new byte[12];
                    AssemblyJointDefinition jointData = joint.Definition;
                    BitConverter.GetBytes(jointData.OriginTwo.Point.X).CopyTo(transJointData, 0);
                    BitConverter.GetBytes(jointData.OriginTwo.Point.Y).CopyTo(transJointData, 4);
                    BitConverter.GetBytes(jointData.OriginTwo.Point.Z).CopyTo(transJointData, 8);
                    linearJointBytes.Add(transJointData);
                    //Adds the degrees of freedom
                    byte[]         freedomData       = new byte[8];
                    ModelParameter positionData      = (ModelParameter)jointData.LinearPosition;
                    double         relataivePosition = positionData._Value;
                    positionData = (ModelParameter)jointData.LinearPositionEndLimit;
                    BitConverter.GetBytes((float)(Math.Abs(relataivePosition) - Math.Abs(positionData._Value))).CopyTo(freedomData, 0);
                    positionData = (ModelParameter)jointData.LinearPositionStartLimit;
                    BitConverter.GetBytes((float)(Math.Abs(relataivePosition) - Math.Abs(positionData._Value))).CopyTo(freedomData, 4);
                    linearJointBytes.Add(freedomData);
                    linearJointBytes.Add(processJointAttributes(jointDataObject));
                }
                object[] tempArray     = linearJointBytes.ToArray();
                byte[]   returnedArray = new byte[tempArray.Length];
                tempArray.CopyTo(returnedArray, 0);
                return(returnedArray);
            }
            catch (Exception e) {
                //catches problems
                MessageBox.Show(e.Message + "\n\n\n" + e.StackTrace);
                return(null);
            }
        }
Exemplo n.º 3
0
        private byte[] ProcessCylindricalJoint(RigidBodyJoint cylindricalJoint)
        {
            try
            {
                List <byte> cylindricalJointBytes = new List <byte>();

                //Adds ID to signify that it's a cylindrical joint
                cylindricalJointBytes.AddRange(BitConverter.GetBytes((ushort)2));

                foreach (AssemblyJoint joint in cylindricalJoint.Joints)
                {
                    //Adds the ID of the parent STL to the output array
                    STLData parentSTL = new STLData();
                    STLDictionary.TryGetValue(NameFilter(joint.OccurrenceOne.Name), out parentSTL);
                    byte[] parentIDBytes = BitConverter.GetBytes((uint)(parentSTL.getID()));
                    cylindricalJointBytes.AddRange(parentIDBytes);
                    //Adds the ID of the child STL to the output array
                    STLData childSTL = new STLData();
                    STLDictionary.TryGetValue(NameFilter(joint.OccurrenceTwo.Name), out childSTL);
                    byte[] childIDBytes = BitConverter.GetBytes((uint)(childSTL.getID()));
                    cylindricalJointBytes.AddRange(childIDBytes);
                    //Adds the vector normal to the plane of rotation
                    cylindricalJoint.GetJointData(out object GeometryOne, out object GeometryTwo, out NameValueMap nameMap);

                    /* Circle vectorCircle = (Circle)GeometryTwo;
                     * byte[] vectorJointData = new byte[12];
                     * BitConverter.GetBytes((float)vectorCircle.Center.X).CopyTo(vectorJointData, 0);
                     * BitConverter.GetBytes((float)vectorCircle.Center.Y).CopyTo(vectorJointData, 4);
                     * BitConverter.GetBytes((float)vectorCircle.Center.Z).CopyTo(vectorJointData, 8);
                     * cylindricalJointBytes.AddRange(vectorJointData);
                     *///Adds the vector parallel to the movement
                    MessageBox.Show(GeometryTwo.GetType().ToString());
                    //Adds the vector parallel to movement
                    Line   vectorLine      = (Line)GeometryTwo;
                    byte[] vectorJointData = new byte[12];
                    BitConverter.GetBytes((float)vectorLine.RootPoint.X).CopyTo(vectorJointData, 0);
                    BitConverter.GetBytes((float)vectorLine.RootPoint.Y).CopyTo(vectorJointData, 4);
                    BitConverter.GetBytes((float)vectorLine.RootPoint.Z).CopyTo(vectorJointData, 8);
                    cylindricalJointBytes.AddRange(vectorJointData);
                    //Adds the point of connection relative to the parent part
                    byte[] transJointData             = new byte[12];
                    AssemblyJointDefinition jointData = joint.Definition;
                    BitConverter.GetBytes((float)jointData.OriginTwo.Point.X).CopyTo(transJointData, 0);
                    BitConverter.GetBytes((float)jointData.OriginTwo.Point.Y).CopyTo(transJointData, 4);
                    BitConverter.GetBytes((float)jointData.OriginTwo.Point.Z).CopyTo(transJointData, 8);
                    cylindricalJointBytes.AddRange(transJointData);
                    //Adds the degrees of freedom
                    List <byte>    freedomData       = new List <byte>();
                    ModelParameter positionData      = (ModelParameter)jointData.AngularPosition;
                    double         relataivePosition = positionData._Value;
                    if (jointData.HasLinearPositionEndLimit)
                    {
                        positionData = (ModelParameter)jointData.LinearPositionEndLimit;
                        freedomData.AddRange(BitConverter.GetBytes((float)(Math.Abs(relataivePosition) - Math.Abs(positionData._Value))));
                    }
                    if (jointData.HasLinearPositionStartLimit)
                    {
                        positionData = (ModelParameter)jointData.LinearPositionStartLimit;
                        freedomData.AddRange(BitConverter.GetBytes((float)(Math.Abs(relataivePosition) - Math.Abs(positionData._Value))));
                    }
                    if (jointData.HasAngularPositionLimits)
                    {
                        positionData = (ModelParameter)jointData.AngularPositionEndLimit;
                        freedomData.AddRange(BitConverter.GetBytes((float)(Math.Abs(relataivePosition) - Math.Abs(positionData._Value))));
                        positionData = (ModelParameter)jointData.AngularPositionStartLimit;
                        freedomData.AddRange(BitConverter.GetBytes((float)(Math.Abs(relataivePosition) - Math.Abs(positionData._Value))));
                    }
                    if (freedomData != null)
                    {
                        cylindricalJointBytes.AddRange(freedomData);
                    }
                }
                return(cylindricalJointBytes.ToArray());
            }
            catch (Exception e)
            {
                //catches problems
                MessageBox.Show(e.Message + "\n\n\n" + e.StackTrace);
                return(null);
            }
        }