Exemplo n.º 1
0
        private void LimitRotationZXY(TMONode node)
        {
            TMOConstraintItem item   = constraint_zxy.GetItem(node.Name);
            Vector3           angle1 = TMOMat.ToAngleZXY(node.Rotation);
            Vector3           angle0 = item.Limit(angle1);

            node.Rotation = TMOMat.ToQuaternionZXY(angle0);
            //Console.WriteLine("node {0} x {1:F2} y {2:F2} z {3:F2}", node.Name, angle0.X, angle0.Y, angle0.Z);
        }
Exemplo n.º 2
0
        private void LimitRotationXYZ(TMONode node)
        {
            TMOConstraintItem item   = constraint_xyz.GetItem(node.Name);
            Vector3           angle1 = Helper.ToAngleXYZ(node.Rotation);
            Vector3           angle0 = item.Limit(angle1);

            node.Rotation = Helper.ToQuaternionXYZ(angle0);
            //Console.WriteLine("node {0} x {1:F2} y {2:F2} z {3:F2}", node.Name, angle0.X, angle0.Y, angle0.Z);
        }
Exemplo n.º 3
0
        /// <summary>
        /// tmoファイルを含むディレクトリから要素を追加します。
        /// </summary>
        /// <param name="source_file">tmoファイルを含むディレクトリ名</param>
        public void AddItemFromTMODirectory(string source_file)
        {
            TMOFile tmo = new TMOFile();

            Dictionary <string, Vector3> min1_dic = new Dictionary <string, Vector3>();
            Dictionary <string, Vector3> max1_dic = new Dictionary <string, Vector3>();

            Dictionary <string, Vector3> min2_dic = new Dictionary <string, Vector3>();
            Dictionary <string, Vector3> max2_dic = new Dictionary <string, Vector3>();

            string[] files = Directory.GetFiles(source_file, "*.tmo");
            foreach (string file in files)
            {
                tmo.Load(file);
                foreach (TMONode node in tmo.nodes)
                {
                    TMOMat mat = node.matrices[0];

                    string  name   = node.Name;
                    Vector3 angle1 = Helper.ToAngleXYZ(mat.m);
                    Vector3 angle2 = angle1;

                    if (angle2.X < 0)
                    {
                        angle2.X += 360;
                    }
                    if (angle2.Y < 0)
                    {
                        angle2.Y += 360;
                    }
                    if (angle2.Z < 0)
                    {
                        angle2.Z += 360;
                    }

                    if (!min1_dic.ContainsKey(name))
                    {
                        min1_dic[name] = new Vector3(+180.0f, +180.0f, +180.0f);
                    }
                    if (!max1_dic.ContainsKey(name))
                    {
                        max1_dic[name] = new Vector3(-180.0f, -180.0f, -180.0f);
                    }

                    Vector3 min1 = min1_dic[name];
                    Vector3 max1 = max1_dic[name];

                    if (angle1.X < min1_dic[name].X)
                    {
                        min1.X = angle1.X;
                    }
                    if (angle1.X > max1_dic[name].X)
                    {
                        max1.X = angle1.X;
                    }

                    if (angle1.Y < min1_dic[name].Y)
                    {
                        min1.Y = angle1.Y;
                    }
                    if (angle1.Y > max1_dic[name].Y)
                    {
                        max1.Y = angle1.Y;
                    }

                    if (angle1.Z < min1_dic[name].Z)
                    {
                        min1.Z = angle1.Z;
                    }
                    if (angle1.Z > max1_dic[name].Z)
                    {
                        max1.Z = angle1.Z;
                    }

                    min1_dic[name] = min1;
                    max1_dic[name] = max1;

                    if (!min2_dic.ContainsKey(name))
                    {
                        min2_dic[name] = new Vector3(360.0f, 360.0f, 360.0f);
                    }
                    if (!max2_dic.ContainsKey(name))
                    {
                        max2_dic[name] = new Vector3(0.0f, 0.0f, 0.0f);
                    }

                    Vector3 min2 = min2_dic[name];
                    Vector3 max2 = max2_dic[name];

                    if (angle2.X < min2_dic[name].X)
                    {
                        min2.X = angle2.X;
                    }
                    if (angle2.X > max2_dic[name].X)
                    {
                        max2.X = angle2.X;
                    }

                    if (angle2.Y < min2_dic[name].Y)
                    {
                        min2.Y = angle2.Y;
                    }
                    if (angle2.Y > max2_dic[name].Y)
                    {
                        max2.Y = angle2.Y;
                    }

                    if (angle2.Z < min2_dic[name].Z)
                    {
                        min2.Z = angle2.Z;
                    }
                    if (angle2.Z > max2_dic[name].Z)
                    {
                        max2.Z = angle2.Z;
                    }

                    min2_dic[name] = min2;
                    max2_dic[name] = max2;
                }
            }

            foreach (string name in min1_dic.Keys)
            {
                TMOConstraintItem item = new TMOConstraintItem();
                item.Name = name;

                Vector3 min1 = min1_dic[name];
                Vector3 max1 = max1_dic[name];

                Vector3 min2 = min2_dic[name];
                Vector3 max2 = max2_dic[name];

                Vector3 sub1 = max1 - min1;
                Vector3 sub2 = max2 - min2;

                Vector3 min;
                Vector3 max;

                if (sub1.X <= sub2.X)
                {
                    min.X        = min1.X;
                    max.X        = max1.X;
                    item.SectorX = 1;
                }
                else
                {
                    min.X        = min2.X;
                    max.X        = max2.X;
                    item.SectorX = 2;
                }

                if (sub1.Y <= sub2.Y)
                {
                    min.Y        = min1.Y;
                    max.Y        = max1.Y;
                    item.SectorY = 1;
                }
                else
                {
                    min.Y        = min2.Y;
                    max.Y        = max2.Y;
                    item.SectorY = 2;
                }

                if (sub1.Z <= sub2.Z)
                {
                    min.Z        = min1.Z;
                    max.Z        = max1.Z;
                    item.SectorZ = 1;
                }
                else
                {
                    min.Z        = min2.Z;
                    max.Z        = max2.Z;
                    item.SectorZ = 2;
                }
                item.Min = min;
                item.Max = max;

                items.Add(item);
            }
        }