//public SurfaceMeshBuffer()
        //{
        //    VertexBuffer = new IndexedVertexBuffer<VertVNT>();
        //    BoneWeightBuffer = new IndexedVertexBuffer<VertVBW>();
        //    MeshModels = new List<SurfaceModelMesh>();
        //}

        public SurfaceMeshBuffer(PartSurface surface)
        {
            Surface      = surface;
            VertexBuffer = new IndexedVertexBuffer <VertVNT>();
            //BoneWeightBuffer = new IndexedVertexBuffer<VertVBW>();
            MeshModels = new List <SurfaceModelMesh>();
        }
Exemple #2
0
        public override PartSurface DeserializeSurface(XElement element)
        {
            var surface = new PartSurface();

            //DeserializeBaseElement(surface, element);

            if (element.TryGetIntAttribute(nameof(PartSurface.SurfaceID), out int surfID))
            {
                surface.SurfaceID = surfID;
            }

            surface.InternalSetID(StringUtils.GenerateUUID($"Surface{surfID}", 8));
            surface.InternalSetName($"Surface{surfID}");

            if (element.TryGetIntAttribute(nameof(PartSurface.SubMaterialIndex), out int matIDX))
            {
                surface.SubMaterialIndex = matIDX;
            }

            foreach (var compElem in element.Elements(SurfaceComponent.NODE_NAME))
            {
                var comp = DeserializeSurfaceComponent(compElem);
                if (comp != null)
                {
                    surface.Components.Add(comp);
                }
            }

            return(null);
        }
Exemple #3
0
        private void ImportAssimpModel(ImportModelsDialog imd)
        {
            ProjectManager.StartBatchChanges();

            foreach (var model in imd.ModelsToImport)
            {
                var geom    = Meshes.MeshConverter.AssimpToLdd(imd.SceneToImport, model.Mesh);
                var surface = CurrentProject.Surfaces.FirstOrDefault(x => x.SurfaceID == model.SurfaceID);

                if (surface == null)
                {
                    surface = new PartSurface(model.SurfaceID, CurrentProject.Surfaces.Max(x => x.SubMaterialIndex) + 1);
                    CurrentProject.Surfaces.Add(surface);
                }

                var partModel = surface.Components.FirstOrDefault(x => x.ComponentType == ModelComponentType.Part);

                if (partModel == null)
                {
                    partModel = new PartModel();
                    surface.Components.Add(partModel);
                }

                var modelMesh = CurrentProject.AddMeshGeometry(geom, model.Name);
                partModel.Meshes.Add(new ModelMeshReference(modelMesh));
            }

            ProjectManager.EndBatchChanges();
        }
Exemple #4
0
        public override XElement SerializeSurface(PartSurface surface)
        {
            var elem = SerializeBaseElement(surface, PartSurface.NODE_NAME);

            elem.RemoveAttributes();

            elem.Add(new XAttribute(nameof(PartSurface.SurfaceID), surface.SurfaceID));
            elem.Add(new XAttribute(nameof(PartSurface.SubMaterialIndex), surface.SubMaterialIndex));

            foreach (var comp in surface.Components)
            {
                var compXml = SerializeSurfaceComponent(comp);
                if (compXml != null)
                {
                    elem.Add(compXml);
                }
            }
            return(null);
        }
Exemple #5
0
 public abstract XElement SerializeSurface(PartSurface surface);
        private void ImportModels()
        {
            ProjectManager.StartBatchChanges();
            progressBar1.Style   = ProgressBarStyle.Continuous;
            progressBar1.Value   = 0;
            progressBar1.Maximum = SelectedModels.Count();

            var bonesToImport = GetBoneMappings();

            if (bonesToImport.Count > 0 && SelectedModels.Any(x => x.IsFlexible))
            {
                Project.Flexible = true;

                foreach (var boneMap in bonesToImport)
                {
                    var existing = Project.Bones.FirstOrDefault(x => x.BoneID == boneMap.AssimpID);

                    if (existing == null)
                    {
                        existing = new PartBone(boneMap.AssimpID);
                    }
                    existing.Transform = boneMap.Transform;

                    if (boneMap.ParentName != null)
                    {
                        var parentbone = bonesToImport.FirstOrDefault(x => x.Name == boneMap.ParentName);
                        existing.TargetBoneID = parentbone.AssimpID;
                    }

                    if (existing.Project == null)
                    {
                        Project.Bones.Add(existing);
                    }
                }
            }

            foreach (var model in SelectedModels)
            {
                var geom    = Meshes.MeshConverter.AssimpToLdd(SceneToImport, model.Mesh);
                var surface = Project.Surfaces.FirstOrDefault(x => x.SurfaceID == model.SurfaceID);

                if (surface == null)
                {
                    surface = new PartSurface(model.SurfaceID, Project.Surfaces.Max(x => x.SubMaterialIndex) + 1);
                    Project.Surfaces.Add(surface);
                }

                var partModel = surface.Components.FirstOrDefault(x => x.ComponentType == ModelComponentType.Part);

                if (partModel == null)
                {
                    partModel = new PartModel();
                    surface.Components.Add(partModel);
                }

                var modelMesh = Project.AddMeshGeometry(geom, model.Name);
                partModel.Meshes.Add(new ModelMeshReference(modelMesh));

                progressBar1.Value += 1;
            }

            if (bonesToImport.Any())
            {
                ProjectManager.RebuildBoneConnections();
            }

            ProjectManager.EndBatchChanges();
        }