Beispiel #1
0
 /// This utility method draws debug lines between the joints as defined in @ref m_debugLines
 protected virtual void DrawDebugLines()
 {
     if (m_debugLines == null)
     {
         return;
     }
     // we simply go over every line and try to draw it.
     for (int i = 0; i < m_debugLines.Count; i++)
     {
         DebugLineDef line = m_debugLines[i];
         if (m_jointsInfo[(int)line.m_source] == null ||
             m_jointsInfo[(int)line.m_target] == null)
         {
             continue; // an illegal joint in one of the sides
         }
         // get the source and target information
         JointInfo sourceData = m_jointsInfo[(int)line.m_source];
         JointInfo targetData = m_jointsInfo[(int)line.m_target];
         if (sourceData.m_jointPos == targetData.m_jointPos)
         {
             continue; // the line is really not there as both ends are the same...
         }
         // we choose the color based on the confidence of the
         DrawSingleLine(sourceData, targetData, i);
     }
 }
Beispiel #2
0
        public override void Undo()
        {
            if (this.backupParentObjA == null)
            {
                throw new InvalidOperationException("Can't undo what hasn't been done yet");
            }
            for (int i = 0; i < this.targetObj.Length; i++)
            {
                JointInfo joint   = this.targetObj[i];
                RigidBody parentA = this.backupParentObjA[i];
                RigidBody parentB = this.backupParentObjB[i];
                if (joint == null)
                {
                    continue;
                }

                if (parentA != null)
                {
                    parentA.AddJoint(joint, parentB);
                }
                else if (parentB != null)
                {
                    parentB.AddJoint(joint, parentA);
                }
            }
            var affectedBodies = this.targetParentObjA
                                 .Concat(this.targetParentObjB)
                                 .Concat(this.backupParentObjA)
                                 .Concat(this.backupParentObjB)
                                 .Distinct();

            DualityEditorApp.NotifyObjPropChanged(this, new ObjectSelection(affectedBodies), ReflectionInfo.Property_RigidBody_Joints);
        }
		protected void UpdateJointEditors(IEnumerable<RigidBody> values)
		{
			RigidBody[] valArray = values.ToArray();
			int visibleElementCount = valArray.NotNull().Min(o => o.Joints == null ? 0 : o.Joints.Count());

			// Add missing editors
			for (int i = 0; i < visibleElementCount; i++)
			{
				JointInfo joint = valArray.NotNull().First().Joints.ElementAtOrDefault(i);
				Type jointType = joint.GetType();
				bool matchesAll = valArray.NotNull().All(r => jointType.IsInstanceOfType(r.Joints.ElementAtOrDefault(i)));
				if (matchesAll)
				{
					RigidBodyJointPropertyEditor elementEditor;
					if (i < this.jointEditors.Count)
					{
						elementEditor = this.jointEditors[i];
						if (elementEditor.EditedType != jointType)
						{
							elementEditor.EditedType = jointType;
							this.ParentGrid.ConfigureEditor(elementEditor);
						}
					}
					else
					{
						elementEditor = new RigidBodyJointPropertyEditor();
						elementEditor.EditedType = jointType;
						this.ParentGrid.ConfigureEditor(elementEditor);
						this.jointEditors.Add(elementEditor);
					}
					elementEditor.PropertyName = string.Format("Joints[{0}]", i);
					elementEditor.Getter = this.CreateJointValueGetter(i);
					elementEditor.Setter = this.CreateJointValueSetter(i);
					elementEditor.ParentGetter = this.GetValue;
					if (!this.HasPropertyEditor(this.jointEditors[i])) this.AddPropertyEditor(this.jointEditors[i], i);
				}
				else if (this.jointEditors.Count > i)
				{
					this.RemovePropertyEditor(this.jointEditors[i]);
				}
			}
			// Remove overflowing editors
			for (int i = this.jointEditors.Count - 1; i >= visibleElementCount; i--)
			{
				this.RemovePropertyEditor(this.jointEditors[i]);
				this.jointEditors.RemoveAt(i);
			}

			// Add "Add joint" editor
			if (this.addJointEditor == null)
			{
				this.addJointEditor = new RigidBodyJointAddNewPropertyEditor();
				this.addJointEditor.Getter = this.CreateAddNewJointValueGetter();
				this.addJointEditor.Setter = v => {};
				this.ParentGrid.ConfigureEditor(this.addJointEditor);
				this.AddPropertyEditor(this.addJointEditor);
			}
		}
Beispiel #4
0
    private void MoveTransformToPosition(JointInfo jointInfo, Vector3 target)
    {
        Transform transform = transforms_[jointInfo.id_];

        if (jointInfo.parent_ != null)
        {
            transform.position = target;
        }
    }
Beispiel #5
0
    private Transform[] transforms_; // transforms associated with our Chain

    void Start()
    {
        int id = 0;

        jointInfo_  = new JointInfo(ikChain, ref id);
        transforms_ = new Transform[id + 1];
        id          = 0;
        InitTransform(ikChain, ref id);
    }
    protected override void DrawSingleLine(JointInfo sourceData, JointInfo targetData, int lineNumber)
    {
        m_LineRenderers[lineNumber].SetColors(GetColor(sourceData, sourceData), GetColor(targetData, targetData));
        // using deltaVec: make the line shorter so the joint position could be clearer
        Vector3 deltaVec = targetData.m_jointPos - sourceData.m_jointPos;

        m_LineRenderers[lineNumber].SetPosition(0, sourceData.m_jointPos + deltaVec / 10);
        m_LineRenderers[lineNumber].SetPosition(1, targetData.m_jointPos - deltaVec / 10);
    }
Beispiel #7
0
        private void DrawJoint(Canvas canvas, JointInfo joint)
        {
            if (joint.ParentBody == null)
            {
                return;
            }
            if (joint.OtherBody == null)
            {
                return;
            }

            if (joint is AngleJointInfo)
            {
                this.DrawJoint(canvas, joint as AngleJointInfo);
            }
            else if (joint is DistanceJointInfo)
            {
                this.DrawJoint(canvas, joint as DistanceJointInfo);
            }
            else if (joint is FrictionJointInfo)
            {
                this.DrawJoint(canvas, joint as FrictionJointInfo);
            }
            else if (joint is RevoluteJointInfo)
            {
                this.DrawJoint(canvas, joint as RevoluteJointInfo);
            }
            else if (joint is PrismaticJointInfo)
            {
                this.DrawJoint(canvas, joint as PrismaticJointInfo);
            }
            else if (joint is WeldJointInfo)
            {
                this.DrawJoint(canvas, joint as WeldJointInfo);
            }
            else if (joint is RopeJointInfo)
            {
                this.DrawJoint(canvas, joint as RopeJointInfo);
            }
            else if (joint is SliderJointInfo)
            {
                this.DrawJoint(canvas, joint as SliderJointInfo);
            }
            else if (joint is LineJointInfo)
            {
                this.DrawJoint(canvas, joint as LineJointInfo);
            }
            else if (joint is PulleyJointInfo)
            {
                this.DrawJoint(canvas, joint as PulleyJointInfo);
            }
            else if (joint is GearJointInfo)
            {
                this.DrawJoint(canvas, joint as GearJointInfo);
            }
        }
Beispiel #8
0
    /// internal initialization (which can be overriden)
    protected virtual void InternalAwake()
    {
        int jointCount = Enum.GetNames(typeof(SkeletonJoint)).Length + 1; // Enum starts at 1

        m_jointsInfo = new JointInfo[jointCount];
        foreach (SkeletonJoint j in Enum.GetValues(typeof(SkeletonJoint)))
        {
            m_jointsInfo[(int)j] = null;
        }
    }
Beispiel #9
0
 /// Calculates a color for the line
 /// @param sourceData the joint info on the source joint
 /// @param targetData the joint info on the target joint
 /// @return a color for the line
 protected virtual Color GetColor(JointInfo sourceData, JointInfo targetData)
 {
     if (sourceData.m_posConfidence < 0.5 || targetData.m_posConfidence < 0.5)
     {
         return(Color.red);
     }
     else if (sourceData.m_posConfidence < 1 || targetData.m_posConfidence < 1)
     {
         return(Color.yellow);
     }
     return(Color.green);
 }
Beispiel #10
0
    void Start()
    {
        Application.runInBackground = true;

        RectTransform rectTransform = GetComponent <RectTransform>();
        Renderer      renderer      = GetComponent <Renderer>();

        if (UseWebcam)
        {
            //ウェブカメラの設定初期化
            WebCamDevice[] devices = WebCamTexture.devices;
            webcamTexture = new WebCamTexture(devices[0].name);
            renderer.material.mainTexture = webcamTexture;
            webcamTexture.Play();

            texture = new Texture2D(webcamTexture.width, webcamTexture.height);
        }
        else
        {
            //動画ファイルの設定初期化
            VideoPlayer videoPlayer = GetComponent <VideoPlayer>();
            int         width       = (int)rectTransform.rect.width;
            int         height      = (int)rectTransform.rect.height;
            videoTexture = new RenderTexture(width, height, 24);
            videoPlayer.targetTexture     = videoTexture;
            renderer.material.mainTexture = videoTexture;
            videoPlayer.Play();

            texture = new Texture2D(videoTexture.width, videoTexture.height);
        }

        //バウンディングボックスの初期値は入力映像の長辺の正方形
        videoWidth  = texture.width;
        videoHeight = texture.height;
        float padWidth  = (videoWidth > videoHeight) ? 0 : (videoHeight - videoWidth) / 2;
        float padHeight = (videoWidth > videoHeight) ? (videoWidth - videoHeight) / 2 : 0;

        //第三、四引数は幅、高さなので(右、上の位置ではないので)パディング分は二倍する
        boundingBox = new Rect(-padWidth, -padHeight, videoWidth + padWidth * 2, videoHeight + padHeight * 2);

        //ジョイント情報の初期化
        JointInfo.Init(jointInfos);

        //VNectのモデルを読み込み
        vnect.Init(jointInfos, Joint2DLerpFramesCount, Joint3DLerpFramesCount, UseMultiScale);

        //推定結果の描画用プレーン
        debugRenderer = GameObject.Find("DebugRenderer").GetComponent <DebugRenderer>();

        //VRoidのモデルを読み込み
        vrm.Init(jointInfos, ModelPositionX, ModelPositionY, LookForwardAngle);
    }
Beispiel #11
0
        private JointInfo(Transform joint, ref int id, JointInfo parent, JointInfo fork)
        {
            id_     = id;
            fork_   = fork;
            parent_ = parent;
            if (parent == null)
            {
                distanceToParent_ = 0;
                distanceToRoot_   = 0;
            }
            else
            {
                distanceToParent_ = Vector3.Distance(joint.parent.position, joint.position);
                distanceToRoot_   = parent.distanceToRoot_ + distanceToParent_;
            }
            int nbChildren = joint.childCount;

            children_ = new JointInfo[nbChildren];
            if (nbChildren == 0) // joint is effector
            {
                effectors_    = new JointInfo[1];
                effectors_[0] = this;
            }
            else
            {
                int       nbEffectors_ = 0;
                JointInfo childFork    = fork_;
                if (nbChildren > 1)
                {
                    childFork = this;
                }
                for (int i = 0; i < nbChildren; ++i)
                {
                    // id is updated with a depth-first iteration
                    ++id;
                    JointInfo jInfo = new JointInfo(joint.GetChild(i), ref id, this, childFork);
                    children_[i]  = jInfo;
                    nbEffectors_ += jInfo.effectors_.Length;
                }
                effectors_ = new JointInfo[nbEffectors_];
                int j = 0;
                foreach (JointInfo jInfo in children_)
                {
                    foreach (JointInfo effector in jInfo.effectors_)
                    {
                        effectors_[j++] = effector;
                    }
                }
            }
        }
        /// <summary>
        ///
        /// Gets the Unity game object by char , to support fromstring where
        /// edges are identify by starting char and ending char
        ///
        /// </summary>
        /// <param name="c"></param>
        /// <returns></returns>
        private GameObject getJointByChar(char c)
        {
            GameObject selected = null;
            int        index    = JointInfo.getNodeIndexByChar(c);

            foreach (GameObject key in jointGraph.Keys)
            {
                if (jointGraph[key].index == index)
                {
                    selected = key;
                }
            }
            return(selected);
        }
Beispiel #13
0
 private void BackwardStep(JointInfo jointInfo)
 {
     if (jointInfo.children_.Length != 0)
     {
         Transform transform = transforms_[jointInfo.id_];
         foreach (JointInfo childInfo in jointInfo.children_)
         {
             Transform childTransform = transforms_[childInfo.id_];
             float     r      = Vector3.Distance(transform.position, childTransform.position);
             float     delta  = childInfo.distanceToParent_ / r;
             Vector3   newPos = (1 - delta) * transform.position + delta * childTransform.position;
             MoveTransformToPosition(childInfo, newPos);
             BackwardStep(childInfo);
         }
     }
 }
Beispiel #14
0
 public override void Undo()
 {
     for (int i = 0; i < this.targetObj.Length; i++)
     {
         JointInfo joint  = this.targetObj[i];
         RigidBody parent = this.targetParentObj[i];
         if (joint == null)
         {
             continue;
         }
         if (parent == null)
         {
             continue;
         }
         parent.RemoveJoint(joint);
     }
     DualityEditorApp.NotifyObjPropChanged(this, new ObjectSelection(this.targetParentObj.Distinct()), ReflectionInfo.Property_RigidBody_Joints);
 }
 // Use this for initialization
 void Start()
 {
     IRobotJoint[] joints = GetComponentsInChildren<IRobotJoint> ();
     List<JointInfo> jList = new List<JointInfo> ();
     //	Root = null;
     foreach (var j in joints) {
         if(Root==null && j.ParentJoint==null)
         {
             Root=j;
         }
         if(j.isFixed)
             continue;
         JointInfo ifo=new JointInfo();
         ifo.Joint=j;
         ifo.Value=0;
         jList.Add(ifo);
     }
     Joints = jList.ToArray ();
 }
Beispiel #16
0
    private Vector3 ForwardStepJoint(JointInfo jointInfo)
    {
        if (jointInfo.parent_ != null)
        {
            Transform transform       = transforms_[jointInfo.id_];
            Transform parentTransform = transforms_[jointInfo.parent_.id_];
            float     r      = Vector3.Distance(transform.position, parentTransform.position);
            float     delta  = jointInfo.distanceToParent_ / r;
            Vector3   newPos = (1 - delta) * transform.position + delta * parentTransform.position;
            if (jointInfo.parent_.Equals(jointInfo.fork_)) // parent is fork don't modify position, we'll take centroid
            {
                return(newPos);
            }

            MoveTransformToPosition(jointInfo.parent_, newPos);
            return(ForwardStepJoint(jointInfo.parent_));
        }

        return(ikChain.position);
    }
Beispiel #17
0
    private void OnDrawGizmos()
    {
        for (int i = 0; i < targets.Length; ++i)
        {
            if (i >= 0 && i + 1 < targets.Length)
            {
                Gizmos.DrawLine(targets[i].transform.position, targets[i + 1].transform.position);
            }
        }

        for (int i = 0; i < jointInfo_.effectors_.Length; ++i)
        {
            if (i >= 0 && i + 1 < jointInfo_.effectors_.Length)
            {
                JointInfo effector1 = jointInfo_.effectors_[i];
                JointInfo effector2 = jointInfo_.effectors_[i + 1];
                Gizmos.DrawLine(transforms_[effector1.id_].position, transforms_[effector2.id_].position);
            }
        }
    }
Beispiel #18
0
        public override void Do()
        {
            if (this.backupParentObjA == null)
            {
                this.backupParentObjA = new RigidBody[this.targetObj.Length];
                this.backupParentObjB = new RigidBody[this.targetObj.Length];
                for (int i = 0; i < this.backupParentObjA.Length; i++)
                {
                    this.backupParentObjA[i] = this.targetObj[i].BodyA;
                    this.backupParentObjB[i] = this.targetObj[i].BodyB;
                }
            }

            for (int i = 0; i < this.targetObj.Length; i++)
            {
                JointInfo joint   = this.targetObj[i];
                RigidBody parentA = this.targetParentObjA[i];
                RigidBody parentB = this.targetParentObjB[i];
                if (joint == null)
                {
                    continue;
                }

                if (parentA != null)
                {
                    parentA.AddJoint(joint, parentB);
                }
                else if (parentB != null)
                {
                    parentB.AddJoint(joint, parentA);
                }
            }

            var affectedBodies = this.targetParentObjA
                                 .Concat(this.targetParentObjB)
                                 .Concat(this.backupParentObjA)
                                 .Concat(this.backupParentObjB)
                                 .Distinct();

            DualityEditorApp.NotifyObjPropChanged(this, new ObjectSelection(affectedBodies), ReflectionInfo.Property_RigidBody_Joints);
        }
        [Test] public void CloneJointRigidBodies()
        {
            // Create two joint bodies
            GameObject sourceA = new GameObject("ObjectA");
            GameObject sourceB = new GameObject("ObjectB", sourceA);

            sourceA.AddComponent <Transform>();
            sourceB.AddComponent <Transform>();
            RigidBody sourceBodyA = sourceA.AddComponent <RigidBody>();
            RigidBody sourceBodyB = sourceB.AddComponent <RigidBody>();

            sourceBodyA.AddJoint(new DistanceJointInfo(), sourceBodyB);

            // Are the two bodies joint together as expected?
            Assert.AreEqual(1, sourceBodyA.Joints.Count());
            Assert.AreSame(sourceBodyA.Joints.First().OtherBody, sourceBodyB);
            Assert.IsTrue(sourceBodyB.Joints == null || !sourceBodyB.Joints.Any());

            // Clone the object hierarchy
            GameObject targetA     = sourceA.DeepClone();
            GameObject targetB     = targetA.Children[0];
            RigidBody  targetBodyA = targetA.GetComponent <RigidBody>();
            RigidBody  targetBodyB = targetB.GetComponent <RigidBody>();

            // Is the cloned hierarchy joint together as expected?
            Assert.AreEqual(1, targetBodyA.Joints.Count());
            Assert.IsTrue(targetBodyB.Joints == null || !targetBodyB.Joints.Any());
            Assert.AreSame(targetBodyA.Joints.First().OtherBody, targetBodyB);
            Assert.AreNotSame(sourceBodyA.Joints.First(), targetBodyA.Joints.First());

            // Clone only the source joint, but not any body
            JointInfo isolatedSourceJoint = sourceBodyA.Joints.FirstOrDefault();
            JointInfo isolatedTargetJoint = isolatedSourceJoint.DeepClone();

            // Is the cloned joint still isolated, and not attached to any body?
            Assert.IsNotNull(isolatedSourceJoint.ParentBody);
            Assert.IsNotNull(isolatedSourceJoint.OtherBody);
            Assert.IsNull(isolatedTargetJoint.ParentBody);
            Assert.IsNull(isolatedTargetJoint.OtherBody);
            Assert.AreEqual(1, sourceBodyA.Joints.Count());
        }
        public override void Do()
        {
            if (this.backupParentBody == null)
            {
                this.backupParentBody = new RigidBody[this.targetObj.Length];
                this.backupOtherBody  = new RigidBody[this.targetObj.Length];
                for (int i = 0; i < this.backupParentBody.Length; i++)
                {
                    this.backupParentBody[i] = this.targetObj[i].ParentBody;
                    this.backupOtherBody[i]  = this.targetObj[i].OtherBody;
                }
            }

            for (int i = 0; i < this.targetObj.Length; i++)
            {
                JointInfo joint      = this.targetObj[i];
                RigidBody parentBody = this.targetParentBody[i];
                RigidBody otherBody  = this.targetOtherBody[i];
                if (joint == null)
                {
                    continue;
                }

                if (parentBody != null)
                {
                    parentBody.AddJoint(joint, otherBody);
                }
                else if (otherBody != null)
                {
                    otherBody.AddJoint(joint, parentBody);
                }
            }

            var affectedBodies = this.targetParentBody
                                 .Concat(this.targetOtherBody)
                                 .Concat(this.backupParentBody)
                                 .Concat(this.backupOtherBody)
                                 .Distinct();

            DualityEditorApp.NotifyObjPropChanged(this, new ObjectSelection(affectedBodies), ReflectionInfo.Property_RigidBody_Joints);
        }
        /// <summary>
        ///
        /// Code for left click selection on joints (toggle structure, foil, motors at joints)
        /// and joint handles for connections (assembly process)
        ///
        /// </summary>
        /// <param name="selected"></param>
        private string leftClickSelected(GameObject selected)
        {
            string typeAction = "NoEvent";

            // check for left click on joint handle
            if (selected.name.StartsWith(JOINT))
            {
                JointInfo.UAVComponentType componentType = JointInfo.getNextComponentType(jointGraph[selected].componentType);
                changeJointToComponent(selected, componentType);
            }
            // check for left click on assembly handle
            else if (selected.name.Equals(POSITIVEZ) ||
                     selected.name.Equals(NEGATIVEZ) ||
                     selected.name.Equals(POSITIVEX) ||
                     selected.name.Equals(NEGATIVEX))
            {
                typeAction = addConnectorAtHandle(selected);
            }

            return(typeAction);
        }
    private void Awake()
    {
        //IL_0018: Unknown result type (might be due to invalid IL or missing references)
        //IL_001d: Unknown result type (might be due to invalid IL or missing references)
        //IL_0034: Unknown result type (might be due to invalid IL or missing references)
        //IL_0039: Unknown result type (might be due to invalid IL or missing references)
        int num = pointList.Length;

        for (int i = 1; i < num; i++)
        {
            Vector3   localPosition = pointList[i].get_localPosition();
            JointInfo jointInfo     = new JointInfo();
            jointInfo.distance  = localPosition.get_magnitude();
            jointInfo.basisAxis = localPosition.get_normalized();
            m_jointInfoList.Add(jointInfo);
        }
        m_prevPositionList = (Vector3[])new Vector3[num];
        UpdatePreviousPositionList();
        m_lerpPositionList = (Vector3[])new Vector3[num];
        m_lerpRotationList = (Quaternion[])new Quaternion[num];
        UpdateLerpInfo();
    }
Beispiel #23
0
        public override void HandleError(SerializeError error)
        {
            AssignFieldError fieldError = error as AssignFieldError;

            if (fieldError != null && fieldError.TargetObject is JointInfo)
            {
                RigidBody target = fieldError.FieldValue as RigidBody;
                JointInfo joint  = fieldError.TargetObject as JointInfo;

                bool      other = false;
                FieldInfo field = null;
                if (fieldError.FieldName == "colA")
                {
                    field = fieldError.TargetObjectType.Fields.FirstOrDefault(f => f.Name == "parentBody");
                }
                else if (fieldError.FieldName == "colB")
                {
                    field = fieldError.TargetObjectType.Fields.FirstOrDefault(f => f.Name == "otherBody");
                    other = true;
                }

                if (field != null)
                {
                    if (other)
                    {
                        FieldInfo         jointsField = typeof(RigidBody).GetField("joints", BindingFlags.Instance | BindingFlags.NonPublic);
                        IList <JointInfo> jointList   = jointsField.GetValue(target) as IList <JointInfo>;
                        jointList.Remove(joint);
                    }

                    field.SetValue(fieldError.TargetObject, fieldError.FieldValue);
                    fieldError.AssignSuccess = true;
                }
            }

            return;
        }
        protected override void BeforeAutoCreateEditors()
        {
            base.BeforeAutoCreateEditors();
            JointInfo joint = this.GetValue().Cast <JointInfo>().FirstOrDefault();

            if (joint != null && joint.DualJoint)
            {
                if (this.otherColEditor == null)
                {
                    this.otherColEditor              = this.ParentGrid.CreateEditor(typeof(RigidBody), this);
                    this.otherColEditor.Getter       = this.CreateOtherColValueGetter();
                    this.otherColEditor.Setter       = this.CreateOtherColValueSetter();
                    this.otherColEditor.PropertyName = Properties.EditorBaseRes.PropertyName_OtherCollider;
                    this.otherColEditor.PropertyDesc = Properties.EditorBaseRes.PropertyDesc_OtherCollider;
                    this.ParentGrid.ConfigureEditor(this.otherColEditor);
                    this.AddPropertyEditor(this.otherColEditor);
                }
            }
            else if (this.otherColEditor != null)
            {
                this.RemovePropertyEditor(this.otherColEditor);
                this.otherColEditor = null;
            }
        }
Beispiel #25
0
    // First step : from every end effectors go up to closest fork
    // At fork, determine centroid position for the targets
    // then go up to the next fork
    private void ForwardStep(JointInfo[] effectors, Vector3[] targets)
    {
        Dictionary <JointInfo, TargetCentroid> centroids = new Dictionary <JointInfo, TargetCentroid>();

        for (int i = 0; i < effectors.Length; ++i)
        {
            JointInfo effector = effectors[i];
            Vector3   target   = targets[i];
            transforms_[effector.id_].position = target;
            Vector3   forkTarget = ForwardStepJoint(effector);
            JointInfo fork       = effector.fork_;
            if (fork != null)
            {
                if (!centroids.ContainsKey(fork))
                {
                    centroids[fork] = new TargetCentroid();
                }
                centroids[fork].addTarget(forkTarget);
            }
        }
        int nbCentroids = centroids.Count;

        if (nbCentroids > 0)
        {
            JointInfo[] upEffectors = new JointInfo[nbCentroids];
            Vector3[]   upTargets   = new Vector3[nbCentroids];
            int         j           = 0;
            foreach (KeyValuePair <JointInfo, TargetCentroid> pair in centroids)
            {
                upEffectors[j] = pair.Key;
                upTargets[j]   = pair.Value.Target;
                ++j;
            }
            ForwardStep(upEffectors, upTargets);
        }
    }
Beispiel #26
0
        void Start()
        {
            IRobotJoint[]    joints = GetComponentsInChildren <IRobotJoint> ();
            List <JointInfo> jList  = new List <JointInfo> ();

            if (Joints != null && Joints.Length != 0)
            {
                jList.AddRange(Joints);
            }
            //	Root = null;
            foreach (var j in joints)
            {
                if (GetJoint(j) != null)
                {
                    continue;
                }
                if (j.isFixed)
                {
                    continue;
                }
                JointInfo ifo = new JointInfo();
                ifo.Joint = j;
                ifo.Value = 0;
                jList.Add(ifo);
            }

            foreach (var j in jList)
            {
                if (Root == null && j.Joint.ParentJoint == null)
                {
                    Root = j.Joint;
                    break;
                }
            }
            Joints = jList.ToArray();
        }
 /// Calculates a color for the line
 /// @param sourceData the joint info on the source joint
 /// @param targetData the joint info on the target joint
 /// @return a color for the line
 protected virtual Color GetColor(JointInfo sourceData, JointInfo targetData)
 {
     if (sourceData.m_posConfidence < 0.5 || targetData.m_posConfidence < 0.5)
         return Color.red;
     else if (sourceData.m_posConfidence < 1 || targetData.m_posConfidence < 1)
         return Color.yellow;
     return Color.green;
 }
 /// Does the actual drawing of the line
 /// @param sourceData the joint info on the source joint
 /// @param targetData the joint info on the target joint
 /// @param lineNumber the number of the line in m_debugLines
 protected virtual void DrawSingleLine(JointInfo sourceData, JointInfo targetData, int lineNumber)
 {
     Debug.DrawLine(sourceData.m_jointPos, targetData.m_jointPos, GetColor(sourceData,targetData));
 }
Beispiel #29
0
    public static FurnitureInfo Read(string fileName, string folderName = "/Models/")
    {
        FurnitureInfo     furnitureInfo = new FurnitureInfo();
        List <PartInfo>   unitList      = new List <PartInfo>();
        List <ManualInfo> manualList    = new List <ManualInfo>();

        string      filePath = Application.dataPath + folderName + fileName + ".xml";
        XmlDocument document = new XmlDocument();

        document.Load(filePath);
        XmlElement furnitureElement = document["FurnitureInfo"];

        furnitureInfo.version = furnitureElement.GetAttribute("version");
        furnitureInfo.path    = furnitureElement.GetAttribute("path");
        furnitureInfo.name    = furnitureElement.GetAttribute("name");
        string scale = furnitureElement.GetAttribute("scale");

        furnitureInfo.scale = scale.Equals("") ? 1f : System.Convert.ToSingle(scale);

        XmlNode unitListElement = furnitureElement.ChildNodes[0];

        furnitureInfo.numPart = 0;
        foreach (XmlElement unitElement in unitListElement.ChildNodes)
        {
            PartInfo unit = new PartInfo();
            unit.name      = unitElement.GetAttribute("name");
            unit.path      = unitElement.GetAttribute("path");
            unit.shapeDesc = unitElement.GetAttribute("shape");
            unit.scale     = ReadVector3(unitElement, "s");
            unit.scale    *= furnitureInfo.scale;
            // TODO: rotation and position are used for checking correct assembly result.
            unit.rotation  = ReadVector3(unitElement, "r");
            unit.position  = ReadVector3(unitElement, "p");
            unit.position *= furnitureInfo.scale;

            unit.joints = new List <JointInfo>();
            foreach (XmlElement jointElement in unitElement.ChildNodes)
            {
                JointInfo joint = new JointInfo();
                joint.group    = jointElement.GetAttribute("group");
                joint.opponent = jointElement.GetAttribute("opponent");
                joint.path     = jointElement.GetAttribute("path");
                joint.scale    = ReadVector3(jointElement, "s");
                if (furnitureInfo.version != "1")
                {
                    joint.scale.x = joint.scale.x * 3f;
                    joint.scale.z = joint.scale.z * 3f;
                }
                joint.rotation = ReadVector3(jointElement, "r");
                joint.position = ReadVector3(jointElement, "p");
                joint.type     = jointElement.GetAttribute("type");
                unit.joints.Add(joint);
            }
            unitList.Add(unit);
            furnitureInfo.numPart++;
        }
        furnitureInfo.partList = unitList;

        // Write manual info
        XmlNode manualListElement = furnitureElement.ChildNodes[1];

        foreach (XmlElement manualElement in manualListElement.ChildNodes)
        {
            ManualInfo manual = new ManualInfo {
                m1     = System.Convert.ToInt32(manualElement.GetAttribute("m1")),
                m2     = System.Convert.ToInt32(manualElement.GetAttribute("m2")),
                group1 = manualElement.GetAttribute("group1"),
                group2 = manualElement.GetAttribute("group2")
            };
            string scale1 = manualElement.GetAttribute("scale1");
            string scale2 = manualElement.GetAttribute("scale2");
            manual.scale1 = scale1.Equals("") ? 1f : System.Convert.ToSingle(scale1);
            manual.scale2 = scale2.Equals("") ? 1f : System.Convert.ToSingle(scale2);
            manualList.Add(manual);
        }
        furnitureInfo.manualList = manualList;

        return(furnitureInfo);
    }
Beispiel #30
0
 public bool Equals(JointInfo jInfo)
 {
     return(jInfo != null && id_ == jInfo.id_);
 }
Beispiel #31
0
    private static void LoadObjectsInfo()
    {
        int CountObjects = BinaryReader.ReadUInt16();

        for (int i = 0; i < CountObjects; i++)
        {
            byte frameType = BinaryReader.ReadByte(), visualType = 0;
            if (frameType == (int)FrameType.FRAME_VISUAL)
            {
                visualType = BinaryReader.ReadByte();
                byte[] visualFlags = BinaryReader.ReadBytes(2);
            }

            OBJECTINFO objMainInfo  = CustomReader.ReadType <OBJECTINFO>();
            byte       cullingFlags = BinaryReader.ReadByte();

            byte   uniqueMeshNameLength = BinaryReader.ReadByte();
            string uniqueMeshName       = new string(BinaryReader.ReadChars(uniqueMeshNameLength));

            byte   meshParametersLength = BinaryReader.ReadByte();
            string meshParameters       = new string(BinaryReader.ReadChars(meshParametersLength));

            GameObject uniqueMesh = new GameObject(uniqueMeshName);
            uniqueMesh.transform.parent = ModelObject.transform;
            UniqueMeshes.Add(uniqueMesh); _4DSObjects.Add(objMainInfo);

            UniqueMesh = uniqueMesh;

            if (frameType == (int)FrameType.FRAME_VISUAL)
            {
                switch (visualType)
                {
                case (int)VisualType.VISUAL_OBJECT: LoadStandartMesh(objMainInfo, uniqueMeshName); break;

                case (int)VisualType.VISUAL_SINGLEMESH: LoadStandartMesh(objMainInfo, uniqueMeshName); LoadSingleMesh(); break;

                case (int)VisualType.VISUAL_SINGLEMORPH: LoadStandartMesh(objMainInfo, uniqueMeshName); LoadSingleMesh(); LoadMorph(); break;

                case (int)VisualType.VISUAL_BILLBOARD: LoadStandartMesh(objMainInfo, uniqueMeshName); BinaryReader.BaseStream.Position += 5; break;

                case (int)VisualType.VISUAL_MORPH: LoadStandartMesh(objMainInfo, uniqueMeshName); LoadMorph(); break;

                case (int)VisualType.VISUAL_MIRROR: LoadMirror(); break;

                default: Debug.Log("Unknown Visual Type. Abort..."); return;
                }
            }

            switch (frameType)
            {
            case (int)FrameType.FRAME_VISUAL: continue;

            case (int)FrameType.FRAME_SECTOR: LoadSector(); break;

            case (int)FrameType.FRAME_TARGET: LoadTarget(); break;

            case (int)FrameType.FRAME_DUMMY: LoadDummy(); break;

            case (int)FrameType.FRAME_JOINT:
                JointInfo jointInfo = new JointInfo(); jointInfo.boneObj = uniqueMesh;
                LoadJoint(out jointInfo.transformMatrix, out jointInfo.boneID);
                _4DSJoints.Add(jointInfo); break;

            default: Debug.Log("Unknown Frame Type. Abort..."); return;
            }
        }

        ParentObjects();
    }
 /// internal initialization (which can be overriden)
 protected virtual void InternalAwake()
 {
     int jointCount = Enum.GetNames(typeof(SkeletonJoint)).Length + 1; // Enum starts at 1
     m_jointsInfo = new JointInfo[jointCount];
     foreach (SkeletonJoint j in Enum.GetValues(typeof(SkeletonJoint)))
     {
         m_jointsInfo[(int)j] = null;
     }
 }
 protected override void DrawSingleLine(JointInfo sourceData, JointInfo targetData,int lineNumber)
 {
     m_LineRenderers[lineNumber].SetColors(GetColor(sourceData, sourceData), GetColor(targetData, targetData));
     m_LineRenderers[lineNumber].SetPosition(0, sourceData.m_jointPos);
     m_LineRenderers[lineNumber].SetPosition(1, targetData.m_jointPos);
 }
 /// @brief Initializes the joint
 /// 
 /// @note a line containing a joint not initialized will not be drawn. This means that it is 
 /// possible to use a debugger with lots of lines and connect it to a skeleton controller with few
 /// joints. The skeleton controller is responsible for setting the joints and therefore irrelevant
 /// joints will simply not be used.
 /// @param joint the joint to initialize.
 public virtual void InitJoint(SkeletonJoint joint)
 {
     m_jointsInfo[(int)joint] = new JointInfo();
 }
Beispiel #35
0
 /// Does the actual drawing of the line
 /// @param sourceData the joint info on the source joint
 /// @param targetData the joint info on the target joint
 /// @param lineNumber the number of the line in m_debugLines
 protected virtual void DrawSingleLine(JointInfo sourceData, JointInfo targetData, int lineNumber)
 {
     Debug.DrawLine(sourceData.m_jointPos, targetData.m_jointPos, GetColor(sourceData, targetData));
 }
Beispiel #36
0
 /// @brief Initializes the joint
 ///
 /// @note a line containing a joint not initialized will not be drawn. This means that it is
 /// possible to use a debugger with lots of lines and connect it to a skeleton controller with few
 /// joints. The skeleton controller is responsible for setting the joints and therefore irrelevant
 /// joints will simply not be used.
 /// @param joint the joint to initialize.
 public virtual void InitJoint(SkeletonJoint joint)
 {
     m_jointsInfo[(int)joint] = new JointInfo();
 }