Пример #1
0
        private void contextMenuStripSubmesh_Opening(object sender, CancelEventArgs e)
        {
            Point           contextLoc  = new Point(contextMenuStripSubmesh.Left, contextMenuStripSubmesh.Top);
            Point           relativeLoc = treeView.PointToClient(contextLoc);
            TreeNode        submeshNode = treeView.GetNodeAt(relativeLoc);
            ImportedSubmesh submesh     = (ImportedSubmesh)submeshNode.Tag;

            toolStripTextBoxTargetPosition.Text = submesh.Index.ToString();
            TreeNode   meshNode       = submeshNode.Parent;
            DragSource dragSrc        = (DragSource)meshNode.Tag;
            var        srcEditor      = (ImportedEditor)Gui.Scripting.Variables[dragSrc.Variable];
            bool       replaceSubmesh = srcEditor.Meshes[(int)dragSrc.Id].isSubmeshReplacingOriginal(submesh);

            replaceToolStripMenuItem.Checked          = replaceSubmesh;
            toolStripTextBoxMaterialName.Text         = submesh.Material;
            worldCoordinatesToolStripMenuItem.Checked = submesh.WorldCoords;
        }
Пример #2
0
 private void treeView_AfterCheck(object sender, TreeViewEventArgs e)
 {
     if (e.Node.Tag is ImportedSubmesh)
     {
         TreeNode        submeshNode = e.Node;
         ImportedSubmesh submesh     = (ImportedSubmesh)submeshNode.Tag;
         TreeNode        meshNode    = submeshNode.Parent;
         DragSource      dragSrc     = (DragSource)meshNode.Tag;
         var             srcEditor   = (ImportedEditor)Gui.Scripting.Variables[dragSrc.Variable];
         srcEditor.Meshes[(int)dragSrc.Id].setSubmeshEnabled(submesh, submeshNode.Checked);
     }
     else if (e.Node.Tag is ImportedMorphKeyframe)
     {
         TreeNode keyframeNode          = e.Node;
         ImportedMorphKeyframe keyframe = (ImportedMorphKeyframe)keyframeNode.Tag;
         TreeNode   morphNode           = keyframeNode.Parent;
         DragSource dragSrc             = (DragSource)morphNode.Tag;
         var        srcEditor           = (ImportedEditor)Gui.Scripting.Variables[dragSrc.Variable];
         srcEditor.Morphs[(int)dragSrc.Id].setMorphKeyframeEnabled(keyframe, keyframeNode.Checked);
     }
     else if (e.Node.Tag is ImportedAnimationKeyframedTrack)
     {
         TreeNode trackNode = e.Node;
         ImportedAnimationKeyframedTrack track = (ImportedAnimationKeyframedTrack)trackNode.Tag;
         TreeNode   animationNode = trackNode.Parent;
         DragSource dragSrc       = (DragSource)animationNode.Tag;
         var        srcEditor     = (ImportedEditor)Gui.Scripting.Variables[dragSrc.Variable];
         srcEditor.Animations[(int)dragSrc.Id].setTrackEnabled(track, trackNode.Checked);
     }
     else if (e.Node.Tag is ImportedAnimationSampledTrack)
     {
         TreeNode trackNode = e.Node;
         ImportedAnimationSampledTrack track = (ImportedAnimationSampledTrack)trackNode.Tag;
         TreeNode   animationNode            = trackNode.Parent;
         DragSource dragSrc   = (DragSource)animationNode.Tag;
         var        srcEditor = (ImportedEditor)Gui.Scripting.Variables[dragSrc.Variable];
         srcEditor.Animations[(int)dragSrc.Id].setTrackEnabled(track, trackNode.Checked);
     }
 }
Пример #3
0
            public ImporterMorph(string path)
            {
                try
                {
                    Importer importer = new Importer(path);
                    MorphList = new List <ImportedMorph>();

                    ImportedMorph morphList = new ImportedMorph();
                    MorphList.Add(morphList);
                    morphList.KeyframeList = new List <ImportedMorphKeyframe>(importer.MeshList.Count);
                    ImportedSubmesh firstVisibleSubmesh = null;
                    string          firstVisibleMorph   = null;
                    foreach (ImportedMesh meshList in importer.MeshList)
                    {
                        int dotPos = meshList.Name.IndexOf('.');
                        if (dotPos >= 0 && morphList.Name == null)
                        {
                            morphList.Name = meshList.Name.Substring(0, dotPos);
                        }
                        foreach (ImportedSubmesh submesh in meshList.SubmeshList)
                        {
                            ImportedMorphKeyframe morph = new ImportedMorphKeyframe();
                            morph.Name = meshList.Name;
                            dotPos     = morph.Name.IndexOf('.');
                            if (dotPos >= 0)
                            {
                                morph.Name = morph.Name.Substring(dotPos + 1);
                            }
                            morph.VertexList = submesh.VertexList;
                            morphList.KeyframeList.Add(morph);

                            if (firstVisibleSubmesh == null && submesh.Visible)
                            {
                                firstVisibleSubmesh = submesh;
                                firstVisibleMorph   = meshList.Name;
                            }
                        }
                    }
                    if (firstVisibleMorph == null && importer.MeshList.Count > 0 && importer.MeshList[0].SubmeshList.Count > 0)
                    {
                        firstVisibleSubmesh = importer.MeshList[0].SubmeshList[0];
                        firstVisibleMorph   = importer.MeshList[0].Name;
                    }
                    if (firstVisibleMorph != null)
                    {
                        Report.ReportLog("Building morph mask from " + firstVisibleMorph);
                        morphList.MorphedVertexIndices = new List <ushort>();
                        List <ImportedVertex> vertList = firstVisibleSubmesh.VertexList;
                        for (ushort i = 0; i < vertList.Count; i++)
                        {
                            if (vertList[i] is ImportedVertexWithColour)
                            {
                                ImportedVertexWithColour vertCol = (ImportedVertexWithColour)vertList[i];
                                if (vertCol.Colour.Red < 0.1 && vertCol.Colour.Green < 0.1 && vertCol.Colour.Blue > 0.9)
                                {
                                    morphList.MorphedVertexIndices.Add(i);
                                }
                            }
                        }
                    }

                    if (morphList.Name == null)
                    {
                        int startIdx = path.IndexOf('-', path.LastIndexOf('\\')) + 1;
                        int endIdx   = path.LastIndexOf('-');
                        if (startIdx > endIdx)
                        {
                            int extIdx = path.ToLower().LastIndexOf(".morph.mqo");
                            for (int i = extIdx - 1; i >= 0; i--)
                            {
                                if (!Char.IsDigit(path[i]))
                                {
                                    endIdx = i + 1;
                                    break;
                                }
                            }
                        }
                        if ((startIdx > 0) && (endIdx > 0) && (startIdx < endIdx))
                        {
                            morphList.Name = path.Substring(startIdx, endIdx - startIdx);
                        }
                        if (morphList.Name == String.Empty)
                        {
                            morphList.Name = "(no name)";
                        }
                    }
                }
                catch (Exception ex)
                {
                    Report.ReportLog("Error importing .morphs.mqo: " + ex.Message);
                }
            }
Пример #4
0
            private static ImportedMesh ImportMeshList(List <MqoObject> mqoObjects, List <string> mqoMaterials)
            {
                ImportedMesh meshList = new ImportedMesh();

                meshList.Name = mqoObjects[0].name;
                float scale = 1f;

                if (!mqoObjects[0].worldCoords)
                {
                    int startPos = meshList.Name.IndexOf("(Scale=");
                    if (startPos > 0)
                    {
                        int endPos = meshList.Name.IndexOf(')');
                        scale = 1f / Single.Parse(meshList.Name.Substring(startPos + 7, endPos - startPos - 7));
                    }
                }
                meshList.BoneList    = new List <ImportedBone>(0);
                meshList.SubmeshList = new List <ImportedSubmesh>(mqoObjects.Count);

                int vertIdx = 0;

                foreach (MqoObject mqoObject in mqoObjects)
                {
                    List <VertexMap>[]            vertexMapList = new List <VertexMap> [mqoMaterials.Count + 1];
                    Dictionary <int, VertexMap>[] vertexMapDic  = new Dictionary <int, VertexMap> [mqoMaterials.Count + 1];
                    List <VertexMap[]>[]          faceMap       = new List <VertexMap[]> [mqoMaterials.Count + 1];
                    foreach (MqoFace mqoFace in mqoObject.faces)
                    {
                        int mqoFaceMatIdxOffset = mqoFace.materialIndex + 1;
                        if (vertexMapList[mqoFaceMatIdxOffset] == null)
                        {
                            vertexMapList[mqoFaceMatIdxOffset] = new List <VertexMap>(mqoObject.vertices.Length);
                            vertexMapDic[mqoFaceMatIdxOffset]  = new Dictionary <int, VertexMap>();
                            faceMap[mqoFaceMatIdxOffset]       = new List <VertexMap[]>(mqoObject.faces.Length);
                        }

                        VertexMap[] faceMapArray = new VertexMap[mqoFace.vertexIndices.Length];
                        faceMap[mqoFaceMatIdxOffset].Add(faceMapArray);
                        for (int i = 0; i < mqoFace.vertexIndices.Length; i++)
                        {
                            VertexMap vertMap;
                            if (!vertexMapDic[mqoFaceMatIdxOffset].TryGetValue(mqoFace.vertexIndices[i], out vertMap))
                            {
                                ImportedVertex vert;
                                MqoVertex      mqoVert = mqoObject.vertices[mqoFace.vertexIndices[i]];
                                if (mqoVert is MqoVertexWithColour)
                                {
                                    vert = new ImportedVertexWithColour();
                                    ((ImportedVertexWithColour)vert).Colour = ((MqoVertexWithColour)mqoVert).colour;
                                }
                                else
                                {
                                    vert = new ImportedVertex();
                                }
                                vert.BoneIndices = new byte[4];
                                vert.Weights     = new float[4];
                                vert.Normal      = new Vector3();
                                vert.UV          = mqoFace.UVs[i];
                                vert.Position    = mqoVert.coords * scale;

                                vertMap = new VertexMap {
                                    mqoIdx = mqoFace.vertexIndices[i], vert = vert
                                };
                                vertexMapDic[mqoFaceMatIdxOffset].Add(mqoFace.vertexIndices[i], vertMap);
                                vertMap.uvDic.Add(mqoFace.UVs[i], vertMap);
                                vertexMapList[mqoFaceMatIdxOffset].Add(vertMap);
                            }

                            VertexMap uvVertMap;
                            if (!vertMap.uvDic.TryGetValue(mqoFace.UVs[i], out uvVertMap))
                            {
                                ImportedVertex vert = new ImportedVertex();
                                vert.BoneIndices = new byte[4];
                                vert.Weights     = new float[4];
                                vert.Normal      = new Vector3();
                                vert.UV          = mqoFace.UVs[i];
                                vert.Position    = mqoObject.vertices[mqoFace.vertexIndices[i]].coords;

                                uvVertMap = new VertexMap {
                                    mqoIdx = Int32.MaxValue, vert = vert
                                };
                                vertMap.uvDic.Add(mqoFace.UVs[i], uvVertMap);
                                vertexMapList[mqoFaceMatIdxOffset].Add(uvVertMap);
                            }

                            faceMapArray[i] = uvVertMap;
                        }
                    }

                    for (int i = 0; i < vertexMapList.Length; i++)
                    {
                        if (vertexMapList[i] != null)
                        {
                            ImportedSubmesh mesh = new ImportedSubmesh();
                            mesh.VertexList  = new List <ImportedVertex>(vertexMapList[i].Count);
                            mesh.FaceList    = new List <ImportedFace>(faceMap[i].Count);
                            mesh.Index       = mqoObject.baseIdx;
                            mesh.WorldCoords = mqoObject.worldCoords;
                            mesh.Visible     = mqoObject.visible;
                            int matIdx = i - 1;
                            if ((matIdx >= 0) && (matIdx < mqoMaterials.Count))
                            {
                                mesh.Material = mqoMaterials[matIdx];
                            }
                            meshList.SubmeshList.Add(mesh);

                            vertexMapList[i].Sort();
                            for (int j = 0; j < vertexMapList[i].Count; j++)
                            {
                                vertexMapList[i][j].wsMeshIdx = j;
                                mesh.VertexList.Add(vertexMapList[i][j].vert);
                                vertIdx++;
                            }

                            for (int j = 0; j < faceMap[i].Count; j++)
                            {
                                ImportedFace face = new ImportedFace();
                                face.VertexIndices = new int[] { faceMap[i][j][0].wsMeshIdx, faceMap[i][j][2].wsMeshIdx, faceMap[i][j][1].wsMeshIdx };
                                mesh.FaceList.Add(face);
                            }
                        }
                    }
                }

                return(meshList);
            }
Пример #5
0
        private void AddList <T>(List <T> list, string rootName, string editorVar)
        {
            if ((list != null) && (list.Count > 0))
            {
                TreeNode root = new TreeNode(rootName);
                root.Checked = true;
                this.treeView.AddChild(root);

                for (int i = 0; i < list.Count; i++)
                {
                    dynamic  item = list[i];
                    TreeNode node = new TreeNode(item is WorkspaceAnimation
                                                ? ((WorkspaceAnimation)item).importedAnimation is ImportedKeyframedAnimation
                                                        ? "Animation" + i : "Animation(Reduced Keys)" + i
                                                : item.Name);
                    node.Checked = true;
                    node.Tag     = new DragSource(editorVar, typeof(T), i);
                    this.treeView.AddChild(root, node);
                    if (item is WorkspaceMesh)
                    {
                        WorkspaceMesh mesh = item;
                        for (int j = 0; j < mesh.SubmeshList.Count; j++)
                        {
                            ImportedSubmesh submesh     = mesh.SubmeshList[j];
                            TreeNode        submeshNode = new TreeNode();
                            submeshNode.Checked          = mesh.isSubmeshEnabled(submesh);
                            submeshNode.Tag              = submesh;
                            submeshNode.ContextMenuStrip = this.contextMenuStripSubmesh;
                            this.treeView.AddChild(node, submeshNode);
                            UpdateSubmeshNode(submeshNode);
                        }
                    }
                    else if (item is WorkspaceMorph)
                    {
                        WorkspaceMorph morph     = item;
                        string         extraInfo = morph.MorphedVertexIndices != null ? " (morphed vertices: " + morph.MorphedVertexIndices.Count : String.Empty;
                        extraInfo += (extraInfo.Length == 0 ? " (" : ", ") + "keyframes: " + morph.KeyframeList.Count + ")";
                        node.Text += extraInfo;
                        for (int j = 0; j < morph.KeyframeList.Count; j++)
                        {
                            ImportedMorphKeyframe keyframe = morph.KeyframeList[j];
                            TreeNode keyframeNode          = new TreeNode();
                            keyframeNode.Checked          = morph.isMorphKeyframeEnabled(keyframe);
                            keyframeNode.Tag              = keyframe;
                            keyframeNode.ContextMenuStrip = this.contextMenuStripMorphKeyframe;
                            this.treeView.AddChild(node, keyframeNode);
                            UpdateMorphKeyframeNode(keyframeNode);
                        }
                    }
                    else if (item is WorkspaceAnimation)
                    {
                        WorkspaceAnimation animation = item;
                        if (animation.importedAnimation is ImportedKeyframedAnimation)
                        {
                            List <ImportedAnimationKeyframedTrack> trackList = ((ImportedKeyframedAnimation)animation.importedAnimation).TrackList;
                            for (int j = 0; j < trackList.Count; j++)
                            {
                                ImportedAnimationKeyframedTrack track = trackList[j];
                                TreeNode trackNode = new TreeNode();
                                trackNode.Checked = animation.isTrackEnabled(track);
                                trackNode.Tag     = track;
                                int numKeyframes = 0;
                                foreach (ImportedAnimationKeyframe keyframe in track.Keyframes)
                                {
                                    if (keyframe != null)
                                    {
                                        numKeyframes++;
                                    }
                                }
                                trackNode.Text = "Track: " + track.Name + ", Keyframes: " + numKeyframes;
                                this.treeView.AddChild(node, trackNode);
                            }
                        }
                        else if (animation.importedAnimation is ImportedSampledAnimation)
                        {
                            List <ImportedAnimationSampledTrack> trackList = ((ImportedSampledAnimation)animation.importedAnimation).TrackList;
                            for (int j = 0; j < trackList.Count; j++)
                            {
                                ImportedAnimationSampledTrack track = trackList[j];
                                TreeNode trackNode = new TreeNode();
                                trackNode.Checked = animation.isTrackEnabled(track);
                                trackNode.Tag     = track;
                                int numScalings = 0;
                                for (int k = 0; k < track.Scalings.Length; k++)
                                {
                                    if (track.Scalings[k] != null)
                                    {
                                        numScalings++;
                                    }
                                }
                                int numRotations = 0;
                                for (int k = 0; k < track.Rotations.Length; k++)
                                {
                                    if (track.Rotations[k] != null)
                                    {
                                        numRotations++;
                                    }
                                }
                                int numTranslations = 0;
                                for (int k = 0; k < track.Translations.Length; k++)
                                {
                                    if (track.Translations[k] != null)
                                    {
                                        numTranslations++;
                                    }
                                }
                                trackNode.Text = "Track: " + track.Name + ", Length: " + track.Scalings.Length + ", Scalings: " + numScalings + ", Rotations: " + numRotations + ", Translations: " + numTranslations;
                                this.treeView.AddChild(node, trackNode);
                            }
                        }
                    }
                }
            }
        }
Пример #6
0
        public void setSubmeshReplacingOriginal(int meshId, int id, bool replaceOriginal)
        {
            ImportedSubmesh submesh = this.Meshes[meshId].SubmeshList[id];

            this.Meshes[meshId].setSubmeshReplacingOriginal(submesh, replaceOriginal);
        }
Пример #7
0
        public void setSubmeshEnabled(int meshId, int id, bool enabled)
        {
            ImportedSubmesh submesh = this.Meshes[meshId].SubmeshList[id];

            this.Meshes[meshId].setSubmeshEnabled(submesh, enabled);
        }
Пример #8
0
        private void AddList <T>(List <T> list, string rootName, string editorVar)
        {
            if ((list != null) && (list.Count > 0))
            {
                TreeNode root = new TreeNode(rootName);
                root.Checked = true;
                this.treeView.AddChild(root);

                for (int i = 0; i < list.Count; i++)
                {
                    dynamic  item = list[i];
                    TreeNode node = new TreeNode(item is WorkspaceAnimation ? "Animation" + i : item.Name);
                    node.Checked = true;
                    node.Tag     = new DragSource(editorVar, typeof(T), i);
                    this.treeView.AddChild(root, node);
                    if (item is WorkspaceMesh)
                    {
                        WorkspaceMesh mesh = item;
                        for (int j = 0; j < mesh.SubmeshList.Count; j++)
                        {
                            ImportedSubmesh submesh     = mesh.SubmeshList[j];
                            TreeNode        submeshNode = new TreeNode();
                            submeshNode.Checked          = mesh.isSubmeshEnabled(submesh);
                            submeshNode.Tag              = submesh;
                            submeshNode.ContextMenuStrip = this.contextMenuStripSubmesh;
                            this.treeView.AddChild(node, submeshNode);
                            UpdateSubmeshNode(submeshNode);
                        }
                    }
                    else if (item is WorkspaceMorph)
                    {
                        WorkspaceMorph morph = item;
                        for (int j = 0; j < morph.KeyframeList.Count; j++)
                        {
                            ImportedMorphKeyframe keyframe = morph.KeyframeList[j];
                            TreeNode keyframeNode          = new TreeNode();
                            keyframeNode.Checked          = morph.isMorphKeyframeEnabled(keyframe);
                            keyframeNode.Tag              = keyframe;
                            keyframeNode.ContextMenuStrip = this.contextMenuStripMorphKeyframe;
                            this.treeView.AddChild(node, keyframeNode);
                            UpdateMorphKeyframeNode(keyframeNode);
                        }
                    }
                    else if (item is WorkspaceAnimation)
                    {
                        WorkspaceAnimation animation = item;
                        for (int j = 0; j < animation.TrackList.Count; j++)
                        {
                            ImportedAnimationTrack track = animation.TrackList[j];
                            TreeNode trackNode           = new TreeNode();
                            trackNode.Checked = animation.isTrackEnabled(track);
                            trackNode.Tag     = track;
                            int numKeyframes = 0;
                            foreach (ImportedAnimationKeyframe keyframe in track.Keyframes)
                            {
                                if (keyframe != null)
                                {
                                    numKeyframes++;
                                }
                            }
                            trackNode.Text = "Track: " + track.Name + ", Keyframes: " + numKeyframes;
                            this.treeView.AddChild(node, trackNode);
                        }
                    }
                }
            }
        }
Пример #9
0
Файл: Mqo.cs Проект: kkdevs/sb3u
            public ImporterMorph(string path, float vertexScaling)
            {
                try
                {
                    Importer importer = new Importer(path, vertexScaling);
                    MorphList = new List <ImportedMorph>();

                    ImportedMorph   morphList           = null;
                    String          lastGroup           = String.Empty;
                    ImportedSubmesh firstVisibleSubmesh = null;
                    string          firstVisibleMorph   = null;
                    foreach (ImportedMesh meshList in importer.MeshList)
                    {
                        int    dotPos   = meshList.Name.IndexOf('.');
                        string meshName = dotPos >= 0 ? meshList.Name.Substring(0, dotPos) : meshList.Name;
                        int    nextDot  = dotPos >= 0 ? meshList.Name.IndexOf('.', dotPos + 1) : -1;
                        String group    = nextDot >= 0 ? meshList.Name.Substring(dotPos + 1, nextDot - dotPos - 1) : "unknown_blendshape";
                        if (group != lastGroup)
                        {
                            morphList          = new ImportedMorph();
                            morphList.Name     = meshName;
                            morphList.ClipName = group;
                            MorphList.Add(morphList);
                            morphList.KeyframeList = new List <ImportedMorphKeyframe>(importer.MeshList.Count);
                            morphList.Channels     = new List <Tuple <float, int, int> >(importer.MeshList.Count);
                            lastGroup = group;
                        }

                        foreach (ImportedSubmesh submesh in meshList.SubmeshList)
                        {
                            morphList.Channels.Add(new Tuple <float, int, int>(0f, morphList.KeyframeList.Count, 1));
                            ImportedMorphKeyframe morph = new ImportedMorphKeyframe();
                            morph.Name = meshList.Name;
                            dotPos     = morph.Name.LastIndexOf('.');
                            if (dotPos >= 0)
                            {
                                morph.Name = morph.Name.Substring(dotPos + 1);
                            }
                            morph.VertexList = submesh.VertexList;
                            morph.Weight     = 100f;
                            morphList.KeyframeList.Add(morph);

                            if (firstVisibleSubmesh == null && submesh.Visible)
                            {
                                firstVisibleSubmesh = submesh;
                                firstVisibleMorph   = meshList.Name;
                            }
                        }
                    }
                    if (firstVisibleMorph == null && importer.MeshList.Count > 0 && importer.MeshList[0].SubmeshList.Count > 0)
                    {
                        firstVisibleSubmesh = importer.MeshList[0].SubmeshList[0];
                        firstVisibleMorph   = importer.MeshList[0].Name;
                    }
                    if (firstVisibleMorph != null)
                    {
                        Report.ReportLog("Building morph mask from " + firstVisibleMorph);
                        morphList.MorphedVertexIndices = new List <ushort>();
                        List <ImportedVertex> vertList = firstVisibleSubmesh.VertexList;
                        for (ushort i = 0; i < vertList.Count; i++)
                        {
                            if (vertList[i] is ImportedVertexWithColour)
                            {
                                ImportedVertexWithColour vertCol = (ImportedVertexWithColour)vertList[i];
                                if (vertCol.Colour.Red < 0.1 && vertCol.Colour.Green < 0.1 && vertCol.Colour.Blue > 0.9)
                                {
                                    morphList.MorphedVertexIndices.Add(i);
                                }
                            }
                        }
                    }

                    if (morphList.Name == null)
                    {
                        int startIdx = path.IndexOf('-', path.LastIndexOf('\\')) + 1;
                        int endIdx   = path.LastIndexOf('-');
                        if (startIdx > endIdx)
                        {
                            int extIdx = path.ToLower().LastIndexOf(".morph.mqo");
                            for (int i = extIdx - 1; i >= 0; i--)
                            {
                                if (!Char.IsDigit(path[i]))
                                {
                                    endIdx = i + 1;
                                    break;
                                }
                            }
                        }
                        if ((startIdx > 0) && (endIdx > 0) && (startIdx < endIdx))
                        {
                            morphList.Name = path.Substring(startIdx, endIdx - startIdx);
                        }
                        if (morphList.Name == String.Empty)
                        {
                            morphList.Name = "(no name)";
                        }
                    }
                }
                catch (Exception ex)
                {
                    Report.ReportLog("Error importing .morphs.mqo: " + ex.Message);
                }
            }