private void btnNew_Click(object sender, EventArgs e)
 {
     if (_targetObject != null)
     {
         DrawCall d = new DrawCall(_targetObject);
         _targetObject._drawCalls.Add(d);
         _targetObject.OnDrawCallsChanged();
         _targetObject.Model.RegenerateVIS0Indices();
         _targetObject.SignalPropertyChange();
     }
 }
        private void btnDelete_Click(object sender, EventArgs e)
        {
            if (lstDrawCalls.SelectedIndices != null)
            {
                for (int x = lstDrawCalls.SelectedIndices.Count - 1; x >= 0; x--)
                {
                    DrawCall drawCall = lstDrawCalls.Items[lstDrawCalls.SelectedIndices[x]] as DrawCall;
                    if (drawCall != null)
                    {
                        MDL0ObjectNode o = drawCall._parentObject;

                        o._drawCalls.Remove(drawCall);
                        o.OnDrawCallsChanged();
                        o.Model.RegenerateVIS0Indices();
                        o.SignalPropertyChange();
                    }
                }
            }
        }
Beispiel #3
0
        private void ImportObject(MDL0ObjectNode node)
        {
            MDL0ObjectNode newNode = node.SoftCopy();

            if (node._vertexNode != null)
            {
                _internalModel.VertexGroup.AddChild(node._vertexNode);
                (newNode._vertexNode = (MDL0VertexNode)_internalModel.VertexGroup.Children[_internalModel._vertList.Count - 1])._objects.Add(newNode);
            }
            if (node.NormalNode != null)
            {
                _internalModel.NormalGroup.AddChild(node._normalNode);
                (newNode._normalNode = (MDL0NormalNode)_internalModel.NormalGroup.Children[_internalModel._normList.Count - 1])._objects.Add(newNode);
            }
            for (int i = 0; i < 8; i++)
            {
                if (node._uvSet[i] != null)
                {
                    _internalModel.UVGroup.AddChild(node._uvSet[i]);
                    newNode._uvSet[i]      = (MDL0UVNode)_internalModel.UVGroup.Children[_internalModel._uvList.Count - 1];
                    newNode._uvSet[i].Name = "#" + (_internalModel._uvList.Count - 1);
                    newNode._uvSet[i]._objects.Add(newNode);
                }
            }

            for (int i = 0; i < 2; i++)
            {
                if (node._colorSet[i] != null)
                {
                    _internalModel.ColorGroup.AddChild(node._colorSet[i]);
                    (newNode._colorSet[i] = (MDL0ColorNode)_internalModel.ColorGroup.Children[_internalModel._colorList.Count - 1])._objects.Add(newNode);
                }
            }

            if (node.OpaMaterialNode != null)
            {
                _internalModel._matGroup.AddChild(node.OpaMaterialNode);
                newNode.OpaMaterialNode = (MDL0MaterialNode)_internalModel.MaterialGroup.Children[_internalModel._matList.Count - 1];

                _internalModel._shadGroup.AddChild(node.OpaMaterialNode._shader);
                newNode.OpaMaterialNode.ShaderNode = (MDL0ShaderNode)_internalModel.ShaderGroup.Children[_internalModel._shadList.Count - 1];

                foreach (MDL0MaterialRefNode r in newNode.OpaMaterialNode.Children)
                {
                    if (r._texture != null)
                    {
                        (r._texture = _internalModel.FindOrCreateTexture(r.TextureNode.Name))._references.Add(r);
                    }

                    if (r._palette != null)
                    {
                        (r._palette = _internalModel.FindOrCreatePalette(r.PaletteNode.Name))._references.Add(r);
                    }
                }
            }
            if (node.XluMaterialNode != null)
            {
                _internalModel._matGroup.AddChild(node.XluMaterialNode);
                newNode.XluMaterialNode = (MDL0MaterialNode)_internalModel.MaterialGroup.Children[_internalModel._matList.Count - 1];

                _internalModel._shadGroup.AddChild(node.XluMaterialNode._shader);
                newNode.XluMaterialNode.ShaderNode = (MDL0ShaderNode)_internalModel.ShaderGroup.Children[_internalModel._shadList.Count - 1];

                foreach (MDL0MaterialRefNode r in newNode.XluMaterialNode.Children)
                {
                    if (r._texture != null)
                    {
                        (r._texture = _internalModel.FindOrCreateTexture(r.TextureNode.Name))._references.Add(r);
                    }

                    if (r._palette != null)
                    {
                        (r._palette = _internalModel.FindOrCreatePalette(r.PaletteNode.Name))._references.Add(r);
                    }
                }
            }

            newNode._manager = node._manager;

            if (newNode.Weighted)
            {
                foreach (Vertex3 vert in newNode._manager._vertices)
                {
                    if (vert._matrixNode != null)
                    {
                        //To do:
                        //Get difference between new and old influence matrices
                        //and add it to the weighted position
                        //to fit the mesh to the new bones if it doesn't already.

                        //Matrix m = vert.MatrixNode.Matrix;
                        //Matrix invm = vert.MatrixNode.InverseMatrix;
                        if (vert._matrixNode is Influence)
                        {
                            for (int i = 0; i < vert.MatrixNode.Weights.Count; i++)
                            {
                                MDL0BoneNode b = vert.MatrixNode.Weights[i].Bone;
                                if (b != null)
                                {
                                    vert.MatrixNode.Weights[i].Bone = _internalModel._boneGroup.FindChildByType(b.Name, true, ResourceType.MDL0Bone) as MDL0BoneNode;
                                }
                            }

                            vert.MatrixNode = _internalModel._influences.FindOrCreate((Influence)vert._matrixNode, true);
                        }
                        else
                        {
                            vert.MatrixNode = _internalModel.BoneGroup.FindChildByType(((MDL0BoneNode)vert.MatrixNode).Name, true, ResourceType.MDL0Bone) as IMatrixNode;
                        }

                        //Matrix m2 = vert.MatrixNode.Matrix * invm;
                        //vert.WeightedPosition = vert.WeightedPosition * m2;
                    }
                }

                //foreach (Vertex3 vert in newNode._manager._vertices)
                //    vert.Unweight();
            }
            else if (newNode._matrixNode != null)
            {
                if (newNode._matrixNode is Influence)
                {
                    for (int i = 0; i < newNode.MatrixNode.Weights.Count; i++)
                    {
                        newNode.MatrixNode.Weights[i].Bone = _internalModel._boneGroup.FindChildByType(newNode.MatrixNode.Weights[i].Bone.Name, true, ResourceType.MDL0Bone) as MDL0BoneNode;
                    }

                    newNode.MatrixNode = _internalModel._influences.FindOrCreate((Influence)newNode._matrixNode, true);
                }
                else
                {
                    newNode.MatrixNode = _internalModel.BoneGroup.FindChildByType(((MDL0BoneNode)newNode.MatrixNode).Name, true, ResourceType.MDL0Bone) as IMatrixNode;
                }
            }

            newNode.RecalcIndices();
            newNode._bone    = (MDL0BoneNode)_internalModel.BoneGroup.Children[0];
            newNode.Name     = "polygon" + (_internalModel._objList.Count);
            newNode._rebuild = true;
            newNode.SignalPropertyChange();
            _internalModel._objGroup.AddChild(newNode);
        }