예제 #1
0
        /// <summary>
        /// R_TextureAnimation
        /// Returns the proper texture for a given time and base texture
        /// </summary>
        private ModelTexture TextureAnimation(ModelTexture t)
        {
            if (_CurrentEntity.frame != 0)
            {
                if (t.alternate_anims != null)
                {
                    t = t.alternate_anims;
                }
            }

            if (t.anim_total == 0)
            {
                return(t);
            }

            var reletive = ( Int32 )(Host.Client.cl.time * 10) % t.anim_total;
            var count    = 0;

            while (t.anim_min > reletive || t.anim_max <= reletive)
            {
                t = t.anim_next;
                if (t == null)
                {
                    Utilities.Error("R_TextureAnimation: broken cycle");
                }
                if (++count > 100)
                {
                    Utilities.Error("R_TextureAnimation: infinite cycle");
                }
            }

            return(t);
        }
예제 #2
0
 public Terrain(vec2 pos,Loader loader,ModelTexture texture)
 {
     this.texture = texture;
     Position.x = pos.x * SIZE;
     Position.y = pos.y * SIZE;
     model = generateTerrain(loader);
 }
예제 #3
0
    public void Build(ModelTexture mtex)
    {
        if (mtex == null)
        {
            return;
        }
        Grid.Clear();
        Grid.AddElement(Instantiate(HLine));
        Variant variant = mtex.GetParent <Variant>();

        foreach (ModelTexture sibling in variant.Children <ModelTexture>())
        {
            if (sibling != mtex)
            {
                ARColorIcon icon = MakeIcon();
                icon.modeltexture       = sibling;
                icon.ColorIcon.Selected = sibling == mtex;
                icon.ClickBox.AddEventListener("onclick", () => {
                    if (OnSelect != null)
                    {
                        OnSelect(sibling);
                    }
                });
                Grid.AddElement(icon);
                Grid.AddElement(Instantiate(HLine));
            }
        }
    }
예제 #4
0
 public Terrain(int gridX, int gridZ, Loader loader, ModelTexture texture)
 {
     this.texture = texture;
     this.x       = gridX;
     this.z       = gridZ;
     this.model   = generateTerrain(loader);
 }
예제 #5
0
    public Variant(DataSnapshot variantData)
    {
        if (variantData == null)
        {
            return;
        }
        if (!variantData.HasChildren)
        {
            return;
        }

        Name = (string)variantData.Key;

        foreach (DataSnapshot child in variantData.Children)
        {
            if (child.Key == "info")
            {
                ParseInfo(child);
            }
            else if (child.HasChildren)
            {
                ModelTexture modelTexture = new ModelTexture(child);
                Add(modelTexture);
            }
        }
    }
예제 #6
0
        public void LoadSubFiles()
        {
            foreach (Bar.Entry barEntry in BarFile)
            {
                try
                {
                    switch (barEntry.Type)
                    {
                    case Bar.EntryType.Model:
                        ModelFile = Mdlx.Read(barEntry.Stream);
                        break;

                    case Bar.EntryType.ModelTexture:
                        TextureFile = ModelTexture.Read(barEntry.Stream);
                        break;

                    case Bar.EntryType.ModelCollision:
                        CollisionFile = new ModelCollision(barEntry.Stream);
                        break;

                    default:
                        break;
                    }
                }
                catch (Exception e) { }
            }
        }
예제 #7
0
        public void Render(Entity entity, StaticShader shader)
        {
            TexturedModel texturedModel = entity.TexturedModel;
            RawModel      model         = texturedModel.RawModel;

            GL.BindVertexArray(model.vaoID);
            GL.EnableVertexAttribArray(0);
            GL.EnableVertexAttribArray(1);
            GL.EnableVertexAttribArray(2);

            Matrix4 transformationMatrix = Maths.CreateTransformationMatrix(
                entity.Position,
                entity.RotationX,
                entity.RotationY,
                entity.RotationZ,
                entity.Scale);

            shader.LoadTransformationMatrix(ref transformationMatrix);

            ModelTexture modelTexture = entity.TexturedModel.Texture;

            shader.LoadShineVariables(modelTexture.ShineDamper, modelTexture.Reflectivity);

            GL.ActiveTexture(TextureUnit.Texture0);
            GL.BindTexture(TextureTarget.Texture2D, texturedModel.Texture.TextureID);
            GL.DrawElements(PrimitiveType.Triangles, model.vertexCount, DrawElementsType.UnsignedInt, 0);
            GL.DisableVertexAttribArray(0);
            GL.DisableVertexAttribArray(1);
            GL.DisableVertexAttribArray(2);
            GL.BindVertexArray(0);
        }
예제 #8
0
파일: Terrain.cs 프로젝트: podobar/GK_P4
 public Terrain(float x, float z, Loader loader, ModelTexture texture)
 {
     Texture = texture;
     X       = x * SIZE;
     Z       = z * SIZE;
     Model   = generateTerrain(loader);
 }
예제 #9
0
        public Terrain(int gridX, int gridZ, Loader loader, ModelTexture texture)
        {
            this.texture = texture;
            x            = gridX * SIZE;
            z            = gridZ * SIZE;

            model = GenerateTerrain(loader);
        }
예제 #10
0
        public int Execute()
        {
            var outDir   = Path.GetDirectoryName(MapFile);
            var baseName = Path.GetFileNameWithoutExtension(MapFile);

            var perTexture = new DeserializerBuilder()
                             .IgnoreUnmatchedProperties()
                             .WithAttributeOverride <TextureFrame>(it => it.Data, new YamlIgnoreAttribute())
                             .Build()
                             .Deserialize <PerTexture>(File.ReadAllText(Path.Combine(outDir, YmlFile ?? $"{baseName}.footer.yml")));

            var anyChanges = false;

            var barEntries = File.OpenRead(MapFile).Using(Bar.Read);

            foreach (var entry in barEntries
                     .Where(entry => entry.Type == Bar.EntryType.ModelTexture &&
                            ModelTexture.IsValid(entry.Stream) &&
                            perTexture.Textures.ContainsKey(entry.Name)
                            )
                     )
            {
                var model = perTexture.Textures[entry.Name];

                entry.Stream.SetPosition(0);

                var modelTexture = ModelTexture.Read(entry.Stream);

                model.ConvertBackTo(
                    pngFile =>
                {
                    return(new SpriteBitmap(Path.Combine(outDir, pngFile)));
                },
                    modelTexture.TextureFooterData
                    );

                {
                    var buffer = new MemoryStream();
                    modelTexture.Write(buffer);
                    buffer.Position = 0;

                    entry.Stream = buffer;
                }

                anyChanges |= true;
            }

            if (anyChanges)
            {
                var buffer = new MemoryStream();
                Bar.Write(buffer, barEntries);

                File.WriteAllBytes(MapFile, buffer.ToArray());
            }

            return(0);
        }
예제 #11
0
    public bool exceedsLimit(ModelTexture mtex)
    {
        Variant var = mtex.GetParent <Variant>();

        if (model_sizes.ContainsKey(var) && library.Count > 0)
        {
            return(mem + model_sizes[var] > MemoryLimitMb);
        }
        return(false);
    }
예제 #12
0
 public void RemoveModel(ModelTexture mtex)
 {
     if (Contains(mtex))
     {
         GameObject model = library[mtex];
         library.Remove(mtex);
         queue.Remove(mtex);
         Garbage(model);
     }
 }
예제 #13
0
 public bool ContainsModelTexture(ModelTexture model)
 {
     foreach (ARModel armodel in ModelsInScene)
     {
         if (armodel.ModelTexture == model)
         {
             return(true);
         }
     }
     return(false);
 }
예제 #14
0
    //DefaultThumbnail is the texture closest to white FFFFFF
    public override Thumbnail GetDefaultThumbnail()
    {
        ModelTexture res = GetDefaultModelTexture();

        if (res == null)
        {
            return(null);
        }

        return(res.Thumbnail);
    }
예제 #15
0
    // async get AR Model fetches a model textures glb ar model object
    public async Task <ARModel> GetModel(ModelTexture mtex)
    {
        if (!Contains(mtex))
        {
            if (!(await LoadModel(mtex)))
            {
                return(null);
            }
        }

        return(newModel(mtex));
    }
예제 #16
0
        protected override void OnLoad(EventArgs e)
        {
            GL.ClearColor(0, 0, 1, 1);

            _texture = new ModelTexture(_loader.LoadTexture(@"Content\whitetexture.png"));
            var model = OBjLoader.LoadObjModel(@"Content\dragon.obj", _loader);

            _texturedModel = new TexturedModel(model, _texture);
            _entity        = new Entity(_texturedModel, new Vector3(0, 0, -25.0f), 0, 0, 0, 1);

            Console.WriteLine("Running OpenGL version: " + GL.GetString(StringName.Version));
        }
예제 #17
0
        public Subject(List <string> modelInfo)
        {
            AbbName = modelInfo.GetStringParameter("Id");
            string path       = modelInfo.GetStringParameter("ModelPath");
            bool   isSameSide = modelInfo.GetBooleanParameter("IsSameSide");

            texture = new ModelTexture(path, isSameSide);
            bool isPassThrough = modelInfo.GetBooleanParameter("IsViewThrough");
            bool isViewThrough = modelInfo.GetBooleanParameter("IsPassThrough");

            Type = new BlockType(isPassThrough, isViewThrough);
        }
예제 #18
0
        public static MeshGroup FromKH2(GraphicsDevice graphics, Mdlx model, ModelTexture texture)
        {
            if (model == null || texture == null)
            {
                return(null);
            }

            var meshGroup = FromKH2(model);

            meshGroup.Textures = LoadTextures(graphics, texture).ToArray();

            return(meshGroup);
        }
예제 #19
0
        public static MeshGroup FromKH2(GraphicsDevice graphics, Mdlx model, ModelTexture texture)
        {
            if (model == null || texture == null)
            {
                return(null);
            }

            var modelParsed = new MdlxParser(model);

            return(modelParsed.MeshDescriptors != null?
                   LoadNew(graphics, modelParsed, texture) :
                       LoadLegacy(graphics, modelParsed, texture));
        }
예제 #20
0
        public MeshGroup this[int objId]
        {
            get
            {
                if (_meshGroups.TryGetValue(objId, out var meshGroup))
                {
                    return(meshGroup);
                }

                var objEntryName = _objEntryLookupReversed[objId];

                var modelPath     = Path.Combine(_objPath, objEntryName);
                var modelFileName = modelPath + ".mdlx";
                if (File.Exists(modelFileName))
                {
                    var mdlxEntries = File.OpenRead(modelFileName).Using(Bar.Read);
                    var modelEntry  = mdlxEntries.FirstOrDefault(x => x.Type == Bar.EntryType.Model);
                    if (modelEntry != null)
                    {
                        var          model    = Mdlx.Read(modelEntry.Stream);
                        ModelTexture textures = null;

                        var textureEntry = mdlxEntries.FirstOrDefault(x => x.Type == Bar.EntryType.ModelTexture);
                        if (textureEntry != null)
                        {
                            textures = ModelTexture.Read(textureEntry.Stream);
                        }

                        var modelMotion = MeshLoader.FromKH2(model);
                        modelMotion.ApplyMotion(modelMotion.InitialPose);
                        meshGroup = new MeshGroup
                        {
                            MeshDescriptors = modelMotion.MeshDescriptors,
                            Textures        = textures == null ? new IKingdomTexture[0] : textures.LoadTextures(_graphics).ToArray()
                        };
                    }
                    else
                    {
                        meshGroup = EmptyMeshGroup;
                    }
                }
                else
                {
                    meshGroup = EmptyMeshGroup;
                }

                _meshGroups[objId] = meshGroup;
                return(meshGroup);
            }
        }
예제 #21
0
        public void Read8bitPaletteCorrectly() => File.OpenRead(FileName2).Using(stream =>
        {
            var images = ModelTexture.Read(stream).Images;

            AssertPalette(images, 0, 0, 0, 0, 0);
            AssertPalette(images, 0, 4, 10, 10, 10);
            AssertPalette(images, 0, 8, 11, 15, 23);
            AssertPalette(images, 0, 16, 23, 19, 29);
            AssertPalette(images, 0, 32, 23, 35, 56);
            AssertPalette(images, 0, 64, 57, 51, 71);
            AssertPalette(images, 0, 128, 153, 96, 7);

            AssertPalette(images, 1, 3, 22, 18, 27);
        });
예제 #22
0
    public ModelTexture GetDefaultModelTexture()
    {
        List <ModelTexture> textures = Children <ModelTexture>();
        ModelTexture        res      = null;

        foreach (ModelTexture texture in textures)
        {
            if (res == null || (texture.Color > res.Color))
            {
                res = texture;
            }
        }

        return(res);
    }
예제 #23
0
    public void AddModel(ModelTexture modeltexture, string title)
    {
        GameObject textGO = MakeText(title);

        ClickBox clickBox = textGO.GetComponent <ClickBox>();

        clickBox.AddEventListener("onclick", () => {
            if (OnSelect != null)
            {
                OnSelect(modeltexture);
            }
        });
        Grid.AddElement(textGO);
        Grid.AddElement(Instantiate(HLine));
    }
예제 #24
0
        private void prepareTerrain(Terrain terrain)
        {
            RawModel rawModel = terrain.Model;

            GL.BindVertexArray(rawModel.VaoID);
            GL.EnableVertexAttribArray(0);
            GL.EnableVertexAttribArray(1);
            GL.EnableVertexAttribArray(2);

            ModelTexture texture = terrain.Texture;

            shader.LoadShineVariables(texture.shineDamper, texture.reflectivity);
            GL.ActiveTexture(TextureUnit.Texture0);
            GL.BindTexture(TextureTarget.Texture2D, terrain.Texture.textureID);
        }
예제 #25
0
    //make a new model
    private ARModel newModel(ModelTexture mtex)
    {
        if (Contains(mtex))
        {
            GameObject obj   = Instantiate(library[mtex]);
            ARModel    model = obj.AddComponent <ARModel>();
            model.ModelTexture = mtex;

            Model parent = mtex.GetParent <Model>();
            model.baseScale = model.baseScale * parent.Scale;
            model.AddColliders();
            return(model);
        }
        return(null);
    }
        public void Start()
        {
            loader   = new Loader();
            shader   = new StaticShader();
            cam      = new Camera();
            renderer = new Renderer(WIDTH, HEIGHT, shader);

            model = OBJLoader.LoadObjFile("Resources\\stall.obj", loader);
            //model = loader.LoadToVAO(vertices, textureCoords, indicies);
            modelTexture  = new ModelTexture(loader.LoadTexture("Resources\\stallimage.jpg"));
            texturedModel = new TexturedModel(model, modelTexture);

            entity = new Entity(texturedModel, new Vector3(0, 0, -25), 0, 0, 0, 1);

            Run(FPS_CAP);
        }
예제 #27
0
    /* Move to ARView and add the given model to the scene */
    public async void MoveToARView(ModelTexture model)
    {
        //Turn ar on
        if (!ARScene.On)
        {
            Splash.bOpacity = 0.8f;
            Splash.Show     = true;
            ARScene.On      = true;
            await Task.Delay(750);

            Splash.Show = false;
        }

        MoveTo(ARView);
        ARScene.AddModel(model);
    }
예제 #28
0
    public void addModelSize(ModelTexture mtex, int size, bool overwrite = false)
    {
        Variant var = mtex.GetParent <Variant>();

        Debug.Log($"{var.Name} size: {size}Mb");
        if (model_sizes.ContainsKey(var))
        {
            if (overwrite)
            {
                model_sizes[var] = size;
            }
        }
        else
        {
            model_sizes.Add(var, size);
        }
    }
    /* Build, given a variant builds a grid with every color of its
     * children modelTexture's. The default modelTexture will be selected.
     */
    public void Build(Variant variant)
    {
        if (variant == null)
        {
            return;
        }

        Clear();


        ModelTexture def = variant.GetDefaultModelTexture();

        foreach (ModelTexture modelTexture in variant.Children <ModelTexture>())
        {
            AddIcon(modelTexture, def == modelTexture);
        }
    }
예제 #30
0
        static ImageFormatService()
        {
            imageFormat = new IImageFormat[]
            {
                GetImageFormat("PNG", "png", true, Png.IsValid, Png.Read, (stream, image) => Png.Write(stream, image)),
                GetImageFormat("BMP", "bmp", true, Bmp.IsValid, Bmp.Read, (stream, image) => Bmp.Write(stream, image)),
                GetImageFormat("TIFF", "tiff", true, Tiff.IsValid, Tiff.Read, (stream, image) => Tiff.Write(stream, image)),

                GetImageFormat("FAC", "fac", true, Imgd.IsFac, s => Imgd.ReadAsFac(s), (stream, images) =>
                               Imgd.WriteAsFac(stream, images.Select(x => x.AsImgd()))),

                GetImageFormat("IMGD", "imd", true, Imgd.IsValid, Imgd.Read, (stream, image) => image.AsImgd().Write(stream)),

                GetImageFormat("IMGZ", "imz", true, Imgz.IsValid, s => Imgz.Read(s), (stream, images) =>
                               Imgz.Write(stream, images.Select(x => x.AsImgd()))),

                GetImageFormat("KH2 Font", "bar", true, IsKh2Font, ReadKh2Font, WriteKh2Font),

                GetImageFormat("Font ARC", "arc", false, FontsArc.IsValid, s =>
                {
                    var fonts = FontsArc.Read(s);
                    return(new[]
                    {
                        fonts.FontCmd.Image1,
                        fonts.FontCmd.Image2,
                        fonts.FontHelp.Image1,
                        fonts.FontHelp.Image2,
                        fonts.FontMenu.Image1,
                        fonts.FontMenu.Image2,
                        fonts.FontMes.Image1,
                        fonts.FontMes.Image2,
                        fonts.FontNumeral.Image1,
                        fonts.FontNumeral.Image2,
                        fonts.FontIcon,
                    });
                }, (stream, images) =>
                               throw new NotImplementedException()),

                GetImageFormat("TIM2", "tm2", false, Tm2.IsValid, s => Tm2.Read(s), (stream, images) =>
                               throw new NotImplementedException()),

                GetImageFormat("KH2TIM", "tex", false, _ => true,
                               s => ModelTexture.Read(s).Images.Cast <IImageRead>(),
                               (stream, images) => throw new NotImplementedException()),
            };
예제 #31
0
        public int Execute()
        {
            var perTexture = new PerTexture();

            var barEntries = File.OpenRead(MapFile).Using(Bar.Read);

            foreach (var entry in barEntries
                     .Where(entry => entry.Type == Bar.EntryType.ModelTexture && ModelTexture.IsValid(entry.Stream))
                     )
            {
                entry.Stream.SetPosition(0);

                var modelTexture = ModelTexture.Read(entry.Stream);

                if (modelTexture.Images == null || !modelTexture.Images.Any())
                {
                    return(1);
                }

                var footerData = modelTexture.TextureFooterData;

                perTexture.Textures[entry.Name] = new TextureFooterDataIMEx(footerData);
            }

            var outDir = Path.Combine(
                Path.GetDirectoryName(MapFile),
                OutputDir ?? "."
                );
            var baseName = Path.GetFileNameWithoutExtension(MapFile);

            Directory.CreateDirectory(outDir);

            File.WriteAllText(
                Path.Combine(outDir, $"{baseName}.footer.yml"),
                new SerializerBuilder()
                .WithTypeConverter(new UseJsonStyleArray <short>())
                .WithTypeConverter(new UseJsonStyleArray <byte>())
                .WithAttributeOverride <TextureFrame>(it => it.Data, new YamlIgnoreAttribute())
                .Build()
                .Serialize(ExportHelper.AlsoExportImages(outDir, baseName, perTexture))
                );

            return(0);
        }
예제 #32
0
        private File3di(BinaryReader reader, FileVersion version)
        {
            if (version != FileVersion.V8)
                throw new NotSupportedException();

            reader.BaseStream.Seek(0, SeekOrigin.Begin);
            var header = reader.ReadBytes(Header.STRUCT_SIZE).ToStruct<Header>();

            Textures = new List<ModelTexture>(header.TextureCount);
            for (var i = 0; i < header.TextureCount; i++)
            {
                var newTex = new ModelTexture(reader, header.Signature);
                Textures.Add(newTex);
            }

            Lods = new List<ModelLod>();
            for (var i = 0; i < header.LodInfo.Count; i++)
            {
                var lod = new ModelLod(reader, header.Signature);
                Lods.Add(lod);
            }
        }