Beispiel #1
0
        public void SelectVertices()
        {
            if (SelectedMesh != null && SelectedVertex != null)
            {
                CalcSkindeform();
                Vector3 center = SelectedVertex.deformed_position;

                MqoMesh mqo_mesh       = MqoMesh.FromTSOMesh(SelectedMesh);
                float   squared_radius = radius * radius;

                foreach (MqoVert v in mqo_mesh.vertices)
                {
                    //頂点間距離が半径未満なら選択する。
                    Vector3 p1             = v.deformed_position;
                    float   squared_length = Vector3.LengthSq(p1 - center);
                    v.selected = squared_length - squared_radius < float.Epsilon;
                    if (v.selected)
                    {
                        if (squared_radius < float.Epsilon)
                        {
                            v.factor = 1.0f;
                        }
                        else
                        {
                            //半径 1.0f とみなしたときの平方距離を得る
                            double len = 1.0 - squared_length / squared_radius;
                            //ウェイト乗数
                            //半径境界で 0.0f になる
                            v.factor = (float)Math.Pow(len, power);
                        }
                    }
                }
            }
        }
Beispiel #2
0
        /// <summary>
        /// シーンをレンダリングします。
        /// </summary>
        public void RenderDerived()
        {
            if (MotionEnabled)
            {
                return;
            }

            Figure fig;

            if (TryGetFigure(out fig))
            {
                if (node_selection_mode == NodeSelectionMode.AllBones)
                {
                    //nodeを描画する。
                    DrawNodeTree(fig);
                    DrawSelectedNode(fig);
                }

                if (SelectedMesh != null)
                {
                    //頂点を描画する。
                    MqoMesh mqo_mesh = MqoMesh.FromTSOMesh(SelectedMesh);
                    DrawVertices(mqo_mesh);
                    DrawSelectedVertex();
                }
            }
        }
Beispiel #3
0
        public void SelectVerticesFromPath()
        {
            if (SelectedMesh != null && source != null && target != null)
            {
                MqoMesh mqo_mesh = MqoMesh.FromTSOMesh(SelectedMesh);
                mqo_mesh.CreatePathDijkstra(source.Index, target.Index);
                float squared_radius = mqo_mesh.djk.GetCostToTarget();

                foreach (MqoVert v in mqo_mesh.vertices)
                {
                    v.selected = mqo_mesh.djk.Selected(v.Index);
                    if (v.selected)
                    {
                        float squared_length = mqo_mesh.djk.GetCostToNode(v.Index);

                        if (squared_radius < float.Epsilon)
                        {
                            v.factor = 1.0f;
                        }
                        else
                        {
                            //半径 1.0f とみなしたときの平方距離を得る
                            double len = 1.0 - squared_length / squared_radius;
                            //ウェイト乗数
                            //半径境界で 0.0f になる
                            v.factor = (float)Math.Pow(len, power);
                        }
                    }
                }
            }
        }
Beispiel #4
0
 /// 統合メッシュ操作を生成します。
 public MqoMeshCommand(TSOFile tso, MqoMesh mqo_mesh, TSONode selected_node, float weight, WeightOperation weight_op)
 {
     this.tso           = tso;
     this.mqo_mesh      = mqo_mesh;
     this.selected_node = selected_node;
     this.weight        = weight;
     this.weight_op     = weight_op;
 }
Beispiel #5
0
        /// 統合メッシュ操作を生成します。
        public SmoothMqoMeshCommand(TSOFile tso, MqoMesh mqo_mesh, TSONode selected_node)
        {
            this.tso           = tso;
            this.mqo_mesh      = mqo_mesh;
            this.selected_node = selected_node;

            weits     = new float[mqo_mesh.vertices.Length];
            new_weits = new float[mqo_mesh.vertices.Length];
        }
Beispiel #6
0
 Vector3[] CreateViewNormals(MqoMesh mqo_mesh)
 {
     Vector3[] view_normals = new Vector3[mqo_mesh.vertices.Length];
     for (int i = 0; i < mqo_mesh.vertices.Length; i++)
     {
         Vector3 n1 = mqo_mesh.vertices[i].deformed_normal;
         Matrix  m  = Transform_View;
         m.M41           = 0;
         m.M42           = 0;
         m.M43           = 0;
         view_normals[i] = Vector3.TransformCoordinate(n1, m);
     }
     return(view_normals);
 }
Beispiel #7
0
        /// 選択ボーンに対応するウェイトを加算する。
        /// returns: ウェイトを変更したか
        public bool Execute()
        {
            bool updated = false;

            MqoMesh mqo_mesh = MqoMesh.FromTSOMesh(mesh);
            SmoothMqoMeshCommand mqo_mesh_command = new SmoothMqoMeshCommand(tso, mqo_mesh, selected_node);

            if (mqo_mesh_command.Execute())
            {
                mqo_mesh.WriteBuffer();
                this.mqo_mesh_commands.Add(mqo_mesh_command);
                updated = true;
            }
            return(updated);
        }
Beispiel #8
0
        internal static MqoMesh FromTSOMesh(TSOMesh mesh)
        {
            MqoMesh mqo_mesh;

            if (meshmap.TryGetValue(mesh, out mqo_mesh))
            {
                return(mqo_mesh);
            }

            mqo_mesh = new MqoMesh(mesh);
            mqo_mesh.CreateVertices();
            meshmap[mesh] = mqo_mesh;

            return(mqo_mesh);
        }
Beispiel #9
0
        void CalcSkindeform()
        {
            if (!NeedSkindeform)
            {
                return;
            }

            Figure fig;

            if (TryGetFigure(out fig))
            {
                if (SelectedMesh != null)
                {
                    Matrix[] clipped_boneMatrices = fig.ClipBoneMatrices(SelectedTSOFile);
                    MqoMesh  mqo_mesh             = MqoMesh.FromTSOMesh(SelectedMesh);
                    mqo_mesh.CalcSkindeform(clipped_boneMatrices);
                }
            }
            NeedSkindeform = false;
        }
Beispiel #10
0
        /// 頂点を描画する。
        void DrawVertices(MqoMesh mqo_mesh)
        {
            CalcSkindeform();

            Rectangle rect        = new Rectangle(0, 0, 7, 7);//red
            Vector3   rect_center = new Vector3(3, 3, 0);

            switch (vertex_selection_mode)
            {
            case VertexSelectionMode.AllVertices:
            {
                if (selected_vertex != null)
                {
                    sprite.Begin(SpriteFlags.None);

                    foreach (MqoVert v in mqo_mesh.vertices)
                    {
                        if (HiddenVert(v))
                        {
                            continue;
                        }
                        rect = GetRectOnDotWeit(v);

                        Vector3 p2 = GetVertPositionOnScreen(v);
                        p2.Z = 0.0f;
                        sprite.Draw(dotweit_texture, rect, rect_center, p2, Color.White);
                    }
                    sprite.End();
                }
                else
                {
                    sprite.Begin(SpriteFlags.None);

                    foreach (MqoVert v in mqo_mesh.vertices)
                    {
                        if (HiddenVert(v))
                        {
                            continue;
                        }
                        Vector3 p2 = GetVertPositionOnScreen(v);
                        p2.Z = 0.0f;
                        sprite.Draw(dotweit_texture, rect, rect_center, p2, Color.White);
                    }
                    sprite.End();
                }
            }
            break;

            case VertexSelectionMode.CcwVertices:
            {
                bool[] ccws = CreateCcws(mqo_mesh);

                if (selected_vertex != null)
                {
                    sprite.Begin(SpriteFlags.None);

                    for (int i = 0; i < mqo_mesh.vertices.Length; i++)
                    {
                        if (!ccws[i])
                        {
                            continue;
                        }

                        MqoVert v = mqo_mesh.vertices[i];
                        if (HiddenVert(v))
                        {
                            continue;
                        }
                        rect = GetRectOnDotWeit(v);

                        Vector3 p2 = GetVertPositionOnScreen(v);
                        p2.Z = 0.0f;
                        sprite.Draw(dotweit_texture, rect, rect_center, p2, Color.White);
                    }
                    sprite.End();
                }
                else
                {
                    sprite.Begin(SpriteFlags.None);

                    for (int i = 0; i < mqo_mesh.vertices.Length; i++)
                    {
                        if (!ccws[i])
                        {
                            continue;
                        }

                        MqoVert v = mqo_mesh.vertices[i];
                        if (HiddenVert(v))
                        {
                            continue;
                        }
                        Vector3 p2 = GetVertPositionOnScreen(v);
                        p2.Z = 0.0f;
                        sprite.Draw(dotweit_texture, rect, rect_center, p2, Color.White);
                    }
                    sprite.End();
                }
            }
            break;

            case VertexSelectionMode.None:
                break;
            }
        }
Beispiel #11
0
 bool[] CreateCcws(MqoMesh mqo_mesh)
 {
     return(CreateCcws(CreateViewNormals(mqo_mesh)));
 }
Beispiel #12
0
        /// 頂点を選択します。
        /// returns: 頂点を見つけたかどうか
        public bool SelectVertex()
        {
            bool found = false;

            if (SelectedMesh != null)
            {
                //スクリーン座標から頂点を見つけます。
                //衝突する頂点の中で最も近い位置にある頂点を返します。

                float x = lastScreenPoint.X;
                float y = lastScreenPoint.Y;

                int   width = 3;//頂点ハンドルの幅
                float min_z = 1e12f;

                MqoVert found_vertex = null;

                MqoMesh mqo_mesh = MqoMesh.FromTSOMesh(SelectedMesh);
                CalcSkindeform();

                switch (vertex_selection_mode)
                {
                case VertexSelectionMode.AllVertices:
                {
                    for (int i = 0; i < mqo_mesh.vertices.Length; i++)
                    {
                        MqoVert v  = mqo_mesh.vertices[i];
                        Vector3 p2 = GetVertPositionOnScreen(v);
                        if (p2.X - width <= x && x <= p2.X + width && p2.Y - width <= y && y <= p2.Y + width)
                        {
                            if (p2.Z < min_z)
                            {
                                min_z        = p2.Z;
                                found        = true;
                                found_vertex = v;
                            }
                        }
                    }
                }
                break;

                case VertexSelectionMode.CcwVertices:
                {
                    bool[] ccws = CreateCcws(mqo_mesh);

                    for (int i = 0; i < mqo_mesh.vertices.Length; i++)
                    {
                        if (!ccws[i])
                        {
                            continue;
                        }

                        MqoVert v  = mqo_mesh.vertices[i];
                        Vector3 p2 = GetVertPositionOnScreen(v);
                        if (p2.X - width <= x && x <= p2.X + width && p2.Y - width <= y && y <= p2.Y + width)
                        {
                            if (p2.Z < min_z)
                            {
                                min_z        = p2.Z;
                                found        = true;
                                found_vertex = v;
                            }
                        }
                    }
                }
                break;

                case VertexSelectionMode.None:
                    break;
                }

                //

                if (found)
                {
                    selected_vertex = found_vertex;
                    SelectVertices();
                    if (SelectedVertexChanged != null)
                    {
                        SelectedVertexChanged(this, EventArgs.Empty);
                    }
                }
            }
            return(found);
        }