Пример #1
0
        private void GetBaseInfluence()
        {
            ResourceNode[] boneCache = _externalModel._linker.BoneCache;
            if ((_node = (MDL0ObjectNode)comboBox1.SelectedItem).Weighted)
            {
                int least = int.MaxValue;
                foreach (IMatrixNode inf in _node.Influences)
                {
                    if (inf is MDL0BoneNode && ((MDL0BoneNode)inf).BoneIndex < least)
                    {
                        least = ((MDL0BoneNode)inf).BoneIndex;
                    }
                }

                if (least != int.MaxValue)
                {
                    MDL0BoneNode temp = (MDL0BoneNode)boneCache[least];
                    _baseInf = (IMatrixNode)temp.Parent;
                }
            }
            else
            {
                _baseInf = _node.MatrixNode;
            }

            if (_baseInf is Influence)
            {
                label2.Hide();
                comboBox2.Hide();
            }
            else if (_baseInf is MDL0BoneNode)
            {
                label2.Show();
                comboBox2.Show();
            }

            baseBone.Text = _baseInf.ToString();

            if (comboBox3.SelectedIndex == 0 && _baseInf is MDL0BoneNode)
            {
                int i = 0;
                foreach (MDL0BoneNode s in comboBox2.Items)
                {
                    if (s.Name == baseBone.Text)
                    {
                        comboBox2.SelectedIndex = i;
                        break;
                    }
                    i++;
                }
            }

            modelPanel1.AddTarget(_node);
            Vector3 min, max;

            _node.GetBox(out min, out max);
            modelPanel1.SetCamWithBox(min, max);
        }
Пример #2
0
        public bool SetTarget(MDL0ObjectNode o)
        {
            //lstDrawCalls.Items.Clear();
            lstDrawCalls.DataSource = null;
            modelPanel.ClearAll();
            cboMaterial.Items.Clear();
            cboVisBone.Items.Clear();
            try
            {
                if ((_targetObject = o) != null)
                {
                    _targetObject.IsRendering = true;

                    cboMaterial.Items.AddRange(o.Model.MaterialList.ToArray());
                    cboVisBone.Items.AddRange(o.Model._linker.BoneCache.ToArray());
                    lstDrawCalls.DataSource = o._drawCalls;
                    //lstDrawCalls.DisplayMember = "";
                    //lstDrawCalls.ValueMember = "_isXLU";

                    modelPanel.AddTarget(o);
                    //if (o._drawCalls.Count > 0)
                    //    lstDrawCalls.SelectedIndex = 0;
                    modelPanel.SetCamWithBox(o.GetBox());
                    return(true);
                }
            }
            catch
            {
                // ignored
            }

            if (_targetObject != null)
            {
                try
                {
                    _targetObject.IsRendering = false;
                }
                catch
                {
                    // ignored
                }
            }

            _targetObject           = null;
            lstDrawCalls.DataSource = null;
            modelPanel.ClearAll();
            cboMaterial.Items.Clear();
            cboVisBone.Items.Clear();

            return(false);
        }
Пример #3
0
        private static void CreateMDL0Object(
            InstanceEntry inst,
            NodeEntry node,
            ResourceNode parent,
            PrimitiveManager manager,
            MDL0Node model,
            DecoderShell shell)
        {
            if (manager != null)
            {
                Error = "There was a problem creating a new object for " + (node._name != null ? node._name : node._id);

                MDL0ObjectNode poly = new MDL0ObjectNode()
                {
                    _manager   = manager,
                    _name      = node._name != null ? node._name : node._id,
                    _drawCalls = new BindingList <DrawCall>()
                };

                //Attach material
                if (inst._material != null)
                {
                    foreach (MaterialEntry mat in shell._materials)
                    {
                        if (mat._id == inst._material._target)
                        {
                            poly._drawCalls.Add(new DrawCall(poly)
                            {
                                MaterialNode = mat._node as MDL0MaterialNode
                            });
                        }
                    }
                }

                model._numTriangles  += poly._numFaces = manager._faceCount = manager._pointCount / 3;
                model._numFacepoints += poly._numFacepoints = manager._pointCount;

                poly._parent = model._objGroup;
                model._objList.Add(poly);

                model.ResetToBindState();

                //Attach single-bind
                if (parent != null && parent is MDL0BoneNode)
                {
                    MDL0BoneNode bone = (MDL0BoneNode)parent;
                    poly.DeferUpdateAssets();
                    poly.MatrixNode = bone;

                    foreach (DrawCall c in poly._drawCalls)
                    {
                        c.VisibilityBoneNode = bone;
                    }
                }
                else if (model._boneList.Count == 0)
                {
                    Error = String.Format("There was a problem rigging {0} to a single bone.", poly._name);

                    Box          box  = poly.GetBox();
                    MDL0BoneNode bone = new MDL0BoneNode()
                    {
                        Scale       = Vector3.One,
                        Translation = (box.Max + box.Min) / 2.0f,
                        _name       = "TransN_" + poly.Name,
                        Parent      = TempRootBone,
                    };

                    poly.DeferUpdateAssets();
                    poly.MatrixNode = bone;
                    ((MDL0BoneNode)TempRootBone).RecalcBindState(true, false, false);

                    foreach (DrawCall c in poly._drawCalls)
                    {
                        c.VisibilityBoneNode = bone;
                    }
                }
                else
                {
                    Error = String.Format("There was a problem checking if {0} is rigged to a single bone.", poly._name);

                    foreach (DrawCall c in poly._drawCalls)
                    {
                        c.VisibilityBoneNode = model._boneList[0] as MDL0BoneNode;
                    }

                    IMatrixNode mtxNode    = null;
                    bool        singlebind = true;

                    foreach (Vertex3 v in poly._manager._vertices)
                    {
                        if (v.MatrixNode != null)
                        {
                            if (mtxNode == null)
                            {
                                mtxNode = v.MatrixNode;
                            }

                            if (v.MatrixNode != mtxNode)
                            {
                                singlebind = false;
                                break;
                            }
                        }
                    }

                    if (singlebind && poly._matrixNode == null)
                    {
                        //Reassign reference entries
                        if (poly._manager._vertices[0].MatrixNode != null)
                        {
                            poly._manager._vertices[0].MatrixNode.Users.Add(poly);
                        }

                        foreach (Vertex3 v in poly._manager._vertices)
                        {
                            if (v.MatrixNode != null)
                            {
                                v.MatrixNode.Users.Remove(v);
                            }
                        }

                        poly._nodeId = -2; //Continued on polygon rebuild
                    }
                }
            }
        }
Пример #4
0
        private void GetBaseInfluence()
        {
            if (_node != null)
            {
                modelPanel1.RemoveReference(_node);
            }

            MDL0BoneNode[] boneCache = _externalModel._linker.BoneCache;
            if ((_node = (MDL0ObjectNode)comboBox1.SelectedItem).Weighted)
            {
                int least = int.MaxValue;
                foreach (IMatrixNode inf in _node.Influences)
                {
                    if (inf is MDL0BoneNode && ((MDL0BoneNode)inf).BoneIndex < least)
                    {
                        least = ((MDL0BoneNode)inf).BoneIndex;
                    }
                }

                if (least != int.MaxValue)
                {
                    MDL0BoneNode temp = boneCache[least];
                    _baseInf = (IMatrixNode)temp.Parent;
                }
            }
            else
            {
                _baseInf = _node.MatrixNode;
            }

            if (_baseInf is Influence)
            {
                label2.Hide();
                comboBox2.Hide();
            }
            else if (_baseInf is MDL0BoneNode)
            {
                label2.Show();
                comboBox2.Show();
            }

            baseBone.Text = _baseInf.ToString();

            if (comboBox3.SelectedIndex == 0 && _baseInf is MDL0BoneNode)
            {
                int i = 0;
                foreach (MDL0BoneNode s in comboBox2.Items)
                {
                    if (s.Name == baseBone.Text)
                    {
                        comboBox2.SelectedIndex = i;
                        break;
                    }

                    i++;
                }
            }

            _node.IsRendering = true;
            modelPanel1.ClearTargets();
            modelPanel1.AddTarget(_node, false);
            modelPanel1.SetCamWithBox(_node.GetBox());
        }