Ejemplo n.º 1
0
 public bool DrawgroupMatch(ModelInstance other)
 {
     return(
         ((DrawGroup1 & other.DrawGroup1) != 0) ||
         ((DrawGroup2 & other.DrawGroup2) != 0) ||
         ((DrawGroup3 & other.DrawGroup3) != 0) ||
         ((DrawGroup4 & other.DrawGroup4) != 0)
         );
 }
        public void AddModelInstance(ModelInstance ins)
        {
            lock (_lock_ModelLoad_Draw)
            {
                ModelInstanceList.Add(ins);

                foreach (var submesh in ins.Model.Submeshes)
                {
                    Debug_VertexCount += submesh.VertexCount;
                    Debug_SubmeshCount++;
                }
            }
        }
Ejemplo n.º 3
0
        public void AddNewInstance(ModelInstance ins)
        {
            Instances.Add(ins);

            if (InstanceBuffer != null)
            {
                InstanceBuffer.Dispose();
            }

            InstanceBuffer = new VertexBuffer(GFX.Device, instanceVertexDeclaration, Instances.Count, BufferUsage.WriteOnly);
            InstanceBuffer.SetData(Instances.Select(x => x.Data).ToArray());
            InstanceBufferBinding = new VertexBufferBinding(InstanceBuffer, 0, 1);
        }
        public void DrawSelected()
        {
            lock (_lock_ModelLoad_Draw)
            {
                if (Selected != null && (HighlightSelectedPiece || WireframeSelectedPiece))
                {
                    if (Selected.Model == null)
                    {
                        Selected = null;
                        return;
                    }

                    GFX.World.ApplyViewToShader(GFX.DbgPrimShader, Selected.Transform);

                    var lod = GFX.World.GetLOD(Selected.Transform);

                    var oldWireframeSetting = GFX.Wireframe;

                    var effect = ((BasicEffect)GFX.DbgPrimShader.Effect);

                    if (HighlightSelectedPiece)
                    {
                        GFX.Wireframe = false;

                        effect.VertexColorEnabled = true;

                        foreach (var submesh in Selected.Model.Submeshes)
                        {
                            submesh.Draw(lod, GFX.DbgPrimShader, forceNoBackfaceCulling: true);
                        }
                    }

                    if (WireframeSelectedPiece)
                    {
                        GFX.Wireframe             = true;
                        effect.VertexColorEnabled = false;

                        foreach (var submesh in Selected.Model.Submeshes)
                        {
                            submesh.Draw(lod, GFX.DbgPrimShader, forceNoBackfaceCulling: true);
                        }

                        GFX.Wireframe = oldWireframeSetting;
                    }

                    effect.VertexColorEnabled = true;
                }
            }
        }
        public List <ModelInstance> AddObj(int id, Transform location)
        {
            var models = InterrootLoader.LoadModelObj(id);

            var returnedModelInstances = new List <ModelInstance>();

            for (int i = 0; i < models.Count; i++)
            {
                var m = new ModelInstance($"o{id:D4}{(i > 0 ? $"[{i + 1}]" : "")}", models[i], location, -1, -1, -1, -1);
                AddModelInstance(m);
                returnedModelInstances.Add(m);
            }

            GFX.ModelDrawer.RequestTextureLoad();

            return(returnedModelInstances);
        }
Ejemplo n.º 6
0
        public void AddModelInstance(Model model, string name, Transform location)
        {
            lock (_lock_ModelLoad_Draw)
            {
                if (!Models.Contains(model))
                {
                    Models.Add(model);
                }

                var instance = new ModelInstance(name, model, location, -1, -1, -1, -1);
                if (LightmapAtlasMap.ContainsKey(name))
                {
                    instance.Data.atlasScale  = new Vector2(LightmapAtlasMap[name].X, LightmapAtlasMap[name].Y);
                    instance.Data.atlasOffset = new Vector2(LightmapAtlasMap[name].Z, LightmapAtlasMap[name].W);
                }
                model.AddNewInstance(instance);
            }
        }
 public static void LoadDragDroppedFiles(string[] fileNames)
 {
     LoadingTaskMan.DoLoadingTask("LoadDragDroppedFiles_" + DateTime.Now.Ticks, "Loading dropped models...", prog =>
     {
         var spawnTransform = GFX.World.GetSpawnPointFromMouseCursor(10.0f, false, true, true);
         int i = 0;
         foreach (var fn in fileNames)
         {
             var shortName = Path.GetFileNameWithoutExtension(fn);
             var upper     = fn.ToUpper();
             if (upper.EndsWith(".CHRBND") || upper.EndsWith(".OBJBND") || upper.EndsWith(".PARTSBND"))
             {
                 BND bnd = null;
                 lock (_lock_IO)
                 {
                     bnd = DataFile.LoadFromFile <BND>(fn);
                 }
                 TexturePool.AddTextureBnd(bnd, null);
                 var models = LoadModelsFromBnd(bnd);
                 foreach (var m in models)
                 {
                     GFX.ModelDrawer.AddModelInstance(
                         new ModelInstance(shortName, m, spawnTransform, -1, -1, -1, -1));
                 }
             }
             else if (upper.EndsWith(".FLVER") || upper.EndsWith(".FLVER.DCX"))
             {
                 var flver         = SoulsFormats.FLVER.Read(File.ReadAllBytes(fn));
                 var model         = new Model(flver);
                 var modelInstance = new ModelInstance(shortName, model, spawnTransform, -1, -1, -1, -1);
                 GFX.ModelDrawer.AddModelInstance(modelInstance);
             }
             prog?.Report(1.0 * (++i) / fileNames.Length);
         }
     });
 }
        public static void LoadBBMapInBackground(string mapName, bool excludeScenery,
                                                 Action <ModelInstance> addMapModel, IProgress <double> progress)
        {
            var modelDir  = GetInterrootPath($@"map\{mapName}");
            var modelDict = new Dictionary <string, Model>();

            Model loadModel(string modelName)
            {
                if (!modelDict.ContainsKey(modelName))
                {
                    SoulsFormats.FLVER flver = null;

                    lock (_lock_IO)
                    {
                        flver = LoadMapFlver(
                            GetInterrootPath($@"map\{mapName}\{mapName}_{modelName.Substring(1)}"));
                    }

                    if (flver != null)
                    {
                        modelDict.Add(modelName, new Model(flver));
                    }
                }

                if (modelDict.ContainsKey(modelName))
                {
                    return(modelDict[modelName]);
                }
                else
                {
                    return(null);
                }
            }

            var msb = MSB64.Read(GetInterrootPath($@"map\MapStudio\{mapName}.msb.dcx"),
                                 (Type == InterrootType.InterrootBloodborne ? MSB64.MSBVersion.MSBVersionBB : MSB64.MSBVersion.MSBVersionDS3));

            void addMsbPart(MSB64.Part part)
            {
                var model = loadModel(part.ModelName);

                if (model != null)
                {
                    var partModelInstance = new ModelInstance(part.Name, model, new Transform(part.Position.X, part.Position.Y, part.Position.Z,
                                                                                              MathHelper.ToRadians(part.Rotation.X), MathHelper.ToRadians(part.Rotation.Y), MathHelper.ToRadians(part.Rotation.Z),
                                                                                              part.Scale.X, part.Scale.Y, part.Scale.Z), (int)part.DrawGroup1, (int)part.DrawGroup2, (int)part.DrawGroup3, (int)part.DrawGroup4);

                    addMapModel.Invoke(partModelInstance);
                }
            }

            // Be sure to update this count if more types of parts are loaded.
            int totalNumberOfParts =
                msb.Parts.MapPieces.Count
            ;

            int i = 0;

            foreach (var part in msb.Parts.MapPieces)
            {
                addMsbPart(part);
                progress?.Report(1.0 * (++i) / totalNumberOfParts);
            }

            modelDict = null;

            GFX.ModelDrawer.RequestTextureLoad();
        }
        public static void LoadDS1MapInBackground(string mapName, bool excludeScenery,
                                                  Action <ModelInstance> addMapModel, IProgress <double> progress)
        {
            var modelDir  = GetInterrootPath($@"map\{mapName}");
            var modelDict = new Dictionary <string, Model>();

            int area = int.Parse(mapName.Substring(1, 2));

            //foreach (var mfn in modelFileNames)
            //{
            //    if (excludeScenery && (mfn.StartsWith("m8") || mfn.StartsWith("m9")))
            //        continue;
            //    modelDict.Add(MiscUtil.GetFileNameWithoutDirectoryOrExtension(mfn), DataFile.LoadFromFile<FLVER>(mfn));
            //}

            Model loadModel(string modelName, PartsParamSubtype partType)
            {
                if (!modelDict.ContainsKey(modelName))
                {
                    SoulsFormats.FLVER flver = null;

                    lock (_lock_IO)
                    {
                        switch (partType)
                        {
                        case PartsParamSubtype.MapPieces:
                            flver = LoadMapFlver(
                                GetInterrootPath($@"map\{mapName}\{modelName}A{area:D2}"));
                            break;

                        case PartsParamSubtype.NPCs:
                        case PartsParamSubtype.DummyNPCs:
                        case PartsParamSubtype.Objects:
                        case PartsParamSubtype.DummyObjects:
                            string bndRelPath = (partType == PartsParamSubtype.Objects ||
                                                 partType == PartsParamSubtype.DummyObjects)
                                    ? $@"obj\{modelName}.objbnd" : $@"chr\{modelName}.chrbnd";

                            var bnd = LoadDecompressedBND(GetInterrootPath(bndRelPath));
                            if (bnd != null)
                            {
                                foreach (var entry in bnd)
                                {
                                    var compareName = entry.Name.ToUpper();
                                    if (flver == null && compareName.EndsWith(".FLVER"))
                                    {
                                        flver = SoulsFormats.FLVER.Read(entry.GetBytes());
                                    }
                                    else if (compareName.EndsWith(".TPF"))
                                    {
                                        TexturePool.AddTpf(SoulsFormats.TPF.Read(entry.GetBytes()));
                                    }
                                }
                            }
                            break;
                        }
                    }

                    if (flver != null)
                    {
                        modelDict.Add(modelName, new Model(flver));
                    }
                }

                if (modelDict.ContainsKey(modelName))
                {
                    return(modelDict[modelName]);
                }
                else
                {
                    return(null);
                }
            }

            var msb = DataFile.LoadFromFile <MSB>(GetInterrootPath($@"map\MapStudio\{mapName}.msb"));

            void addMsbPart(MsbPartsBase part)
            {
                var partSubtype = part.GetSubtypeValue();

                var model = loadModel(part.ModelName, partSubtype);

                if (model != null)
                {
                    var partModelInstance = new ModelInstance(part.Name, model, new Transform(part.PosX, part.PosY, part.PosZ,
                                                                                              MathHelper.ToRadians(part.RotX), MathHelper.ToRadians(part.RotY), MathHelper.ToRadians(part.RotZ),
                                                                                              part.ScaleX, part.ScaleY, part.ScaleZ), part.DrawGroup1, part.DrawGroup2, part.DrawGroup3, part.DrawGroup4);

                    if (partSubtype == PartsParamSubtype.DummyNPCs || partSubtype == PartsParamSubtype.DummyObjects)
                    {
                        partModelInstance.IsDummyMapPart = true;
                    }

                    addMapModel.Invoke(partModelInstance);
                }
            }

            // Be sure to update this count if more types of parts are loaded.
            int totalNumberOfParts =
                msb.Parts.MapPieces.Count +
                msb.Parts.NPCs.Count +
                msb.Parts.DummyNPCs.Count +
                msb.Parts.Objects.Count +
                msb.Parts.DummyObjects.Count
            ;

            int i = 0;

            foreach (var part in msb.Parts.MapPieces)
            {
                addMsbPart(part);
                progress?.Report(1.0 * (++i) / totalNumberOfParts);
            }

            foreach (var part in msb.Parts.NPCs)
            {
                addMsbPart(part);
                progress?.Report(1.0 * (++i) / totalNumberOfParts);
            }

            foreach (var part in msb.Parts.DummyNPCs)
            {
                addMsbPart(part);
                progress?.Report(1.0 * (++i) / totalNumberOfParts);
            }

            foreach (var part in msb.Parts.Objects)
            {
                addMsbPart(part);
                progress?.Report(1.0 * (++i) / totalNumberOfParts);
            }

            foreach (var part in msb.Parts.DummyObjects)
            {
                addMsbPart(part);
                progress?.Report(1.0 * (++i) / totalNumberOfParts);
            }

            modelDict = null;

            GFX.ModelDrawer.RequestTextureLoad();
        }