private void GenerateBuffer()
 {
     _CustomizationBuffer.Clear();
     _CustomizationBuffer.AddRange(ModelCustom.GetAllSettings());
     _CustomizationBuffer.AddRange(AbilityCustom.GetAllSettings());
     _CustomizationBuffer.AddRange(ProjectileCustom.GetAllSettings());
     _CustomizationBuffer.AddRange(TentacleCustom.GetAllSettings());
     _CustomizationBuffer.AddRange(DetectionCustom.GetAllSettings());
     foreach (var custom in _CustomizationBuffer)
     {
         custom.Initialize();
         custom.LogDev("Init!");
         custom.LogVerbose(custom.Target.ToDebugString());
     }
 }
Exemplo n.º 2
0
        public static bool LoadCustomModel(string path, Shader shader)
        {
            string file = $"{SharpCraft.Instance.GameFolderDir}/assets/sharpcraft/models/{path}.json";

            if (!File.Exists(file))
            {
                return(false);
            }

            List <string> nonDuplicateTextures = new List <string>();

            List <JsonModel> models = new List <JsonModel> {
                FixBlockJson(file)
            };

            while (models.Last() is JsonModel jm && !string.IsNullOrEmpty(jm.inherit))
            {
                string inhertiedFile = $"{SharpCraft.Instance.GameFolderDir}/assets/sharpcraft/models/{jm.inherit}.json";

                if (File.Exists(inhertiedFile))
                {
                    models.Add(FixBlockJson(inhertiedFile));
                }
            }

            models.Reverse();

            foreach (var model in models)
            {
                foreach (var pair in model.textures) //iterating over the textureMap in the Json model
                {
                    if (!nonDuplicateTextures.Contains(pair.Value))
                    {
                        nonDuplicateTextures
                        .Add(pair
                             .Value);    //add the current texture name to a list of all textureMap if isn't already there
                    }
                }
            }

            //each texture name has it's UV values TODO - maybe make a TextureMap class where this could be used
            var id = Stitch(nonDuplicateTextures.ToArray(), 16, out var textureMapElements); //TODO - make the texture size variable

            List <float> vertexes = new List <float>();
            List <float> normals  = new List <float>();
            List <float> uvs      = new List <float>();

            foreach (var model in models)
            {
                foreach (var cube in model.cubes)
                {
                    CubeModelBuilder.AppendCubeModel(cube, model.textures, textureMapElements, ref vertexes,
                                                     ref normals, ref uvs);
                }
            }

            var customModel = new ModelCustom(id, ModelManager.LoadModel3ToVao(vertexes.ToArray(), normals.ToArray(), uvs.ToArray()), shader);

            CustomModels.Add(path, customModel);

            return(true);
        }