Esempio n. 1
0
        void LoadTextures(XmlElement xRoot)
        {
            const string nodeImg        = "library_images";
            var          imagesNodeRoot = xRoot.FindNodes(nodeImg);

            if (imagesNodeRoot.Length == 0)
            {
                return;
            }

            var imageNodes = imagesNodeRoot[0].FindNodes("image");

            foreach (var imageNode in imageNodes)
            {
                var       id      = imageNode.Attributes.GetNamedItem("id").Value;
                Texture2D texture = null;
                var       source  = imageNode.FindNodes("init_from");
                if (source.Length == 1)
                {
                    texture = ResourcesManager.LoadAsset <Texture2D>(dir + source[0].InnerText);
                    textures.Add(id, texture);
                }
                //dont load textures from binary data
            }
        }
Esempio n. 2
0
        void ReadTexturesFromMaterial(string name, Material mat)
        {
            string path   = dir + "Materials/" + name + ".material";
            Stream fs     = File.OpenRead(path);
            var    reader = new Reader(fs);

            reader.EncodingType = 1;

            byte[] buffer = new byte[3];
            while (reader.BaseStream.Read(buffer, 2, 1) > 0)
            {
                //looking for sequence "00 0A 75" 0A - 10 chars string; 0x75 - u char
                if (buffer[0] == 0 && buffer[2] == 'u' && buffer[1] == 10)
                {
                    reader.BaseStream.Position -= 2;
                    string      textureId = reader.readStringB();
                    string      textPath  = "";
                    TextureType type      = TextureType.Diffuse;

                    switch (textureId)
                    {
                    case "u_texture0":
                        reader.BaseStream.Position += 1;
                        textPath = reader.readStringB();
                        type     = TextureType.Diffuse;
                        break;

                    case "u_texture1":
                        reader.BaseStream.Position += 1;
                        textPath = reader.readStringB();
                        type     = TextureType.Specular;
                        break;

                    case "u_texture2":
                        reader.BaseStream.Position += 1;
                        textPath = reader.readStringB();
                        type     = TextureType.Toon;
                        break;
                    }
                    if (textPath != "")
                    {
                        textPath = textPath.Substring(textPath.LastIndexOf("Models/") + 7);
                        if (texturesDict.ContainsKey(textPath))
                        {
                            mat.SetTexture(texturesDict[textPath], type);
                        }
                        else
                        {
                            var text = ResourcesManager.LoadAsset <Texture2D>(dir + textPath);
                            texturesDict.Add(textPath, text);
                            mat.SetTexture(text, type);
                        }
                    }
                }

                buffer[0] = buffer[1];
                buffer[1] = buffer[2];
            }
        }
Esempio n. 3
0
        public static void Main(params string[] args)
        {
            if (args.Length == 0)
            {
                return;
            }

            CoreEngine core = new CoreEngine();

            var scene = core.mainScene;

            //string str = "";
            SceneNode node = ResourcesManager.LoadAsset <SceneNode>(args[0]);

            var       camera    = new Camera();
            SceneNode sceneNode = new SceneNode();

            sceneNode.AddComponent(camera);
            sceneNode.AddComponent <CameraControllScript>();
            sceneNode.GetTransform.Position = new Vector3(0, 1, 3);
            sceneNode.AddComponent <DynamicFormScript>();
            scene.AddObject(sceneNode);
            camera.Background = new BackgroundSkybox();


            //node.Name = "Model1";
            //var loader = new ReaderLMD(args[0]);
            //SceneNode node = loader.GetModel;
            //node.GetTransform.Rotation = new Vector3(0,(float)Math.PI / 2,0);
            //MeshDrawer md = (MeshDrawer)node.GetComponent(typeof(MeshDrawer));
            //node.GetTransform.Position = new Vector3(0f, 1.0f, 0.0f);
            //node.phys.ReinstalizeBodys();

            //need sync

            /*
             * var tb = new TextBox();
             * node.AddComponent(tb);
             * tb.SetText("牡丹制服高校(アニメ版)ver3");
             */
            scene.AddObject(node);
            TestScript      ts = (TestScript)node.AddComponent <TestScript>();
            FrameTimeScript ft = (FrameTimeScript)node.AddComponent <FrameTimeScript>();

            var task = new Task(() =>
            {
                Application.Init();
                Window wndw = new Window(node, core);
                Application.Run();
            });

            task.Start();

            core.Run(60);
        }
Esempio n. 4
0
        Texture2D GetTexture(string path)
        {
            Texture2D result = null;

            if (textures.ContainsKey(path))
            {
                result = textures[path];
            }
            else
            {
                result = ResourcesManager.LoadAsset <Texture2D>(path);
                textures.Add(path, result);
            }

            return(result);
        }
Esempio n. 5
0
        void ReadTextures(Reader reader)
        {
            int texCount = reader.ReadInt32();

            textures = new Texture2D[texCount];
            for (int i = 0; i < texCount; i++)
            {
                string    texture = reader.readString();
                Texture2D tex     = ResourcesManager.LoadAsset <Texture2D>(dir + texture);

                if (texture.Contains("toon"))
                {
                    tex.ChangeType(TextureType.Toon);
                }
                else
                {
                    tex.ChangeType(TextureType.Diffuse);
                    tex.WrapMode = TextureWrapMode.Repeat;
                }

                textures[i] = tex;
            }
        }
Esempio n. 6
0
        void ReadPanel(Reader reader)
        {
            var expressionCount = reader.ReadByte();

            for (int i = 0; i < expressionCount; i++)
            {
                reader.ReadUInt16();
            }

            var nodeCount = reader.ReadByte();

            for (int i = 0; i < nodeCount; i++)
            {
                //node names
                reader.readStringLength(50);
            }

            var boneNodesCount = reader.ReadUInt16();

            reader.ReadUInt16();
            for (int i = 0; i < boneNodesCount; i++)
            {
                //bone id
                reader.ReadUInt16();
                //node id
                reader.ReadByte();
            }

            //english names
            bool eng = reader.ReadByte() != 0;

            if (eng)
            {
                header.NameEng    = reader.readStringLength(20);
                header.CommentEng = reader.readStringLength(256);
                //fill english bones names
                for (int i = 0; i < bones.Length; i++)
                {
                    bones[i].NameEng = reader.readStringLength(20);
                }
                //fill english morphs names
                for (int i = 0; i < morphs.Length - 1; i++)
                {
                    morphs[i].NameEng = reader.readStringLength(20);
                }
                //fill english nodes names
                for (int i = 0; i < nodeCount; i++)
                {
                    reader.readStringLength(50);
                }
            }

            //load toon textures
            var toonData = new Texture2D[10];

            for (int i = 0; i < 10; i++)
            {
                var toonName = reader.readStringLength(100);
                //detect internal texture
                if (toonName.StartsWith("toon"))
                {
                    var assembly = System.Reflection.IntrospectionExtensions.GetTypeInfo(typeof(Texture2D)).Assembly;
                    using (var pic = new System.Drawing.Bitmap(assembly.GetManifestResourceStream("Toys.Resourses.textures.PMX." + toonName)))
                    {
                        toonData[i] = new Texture2D(pic, TextureType.Toon, toonName);
                    }
                }
                else
                {
                    toonData[i] = ResourcesManager.LoadAsset <Texture2D>(toonName);
                }
            }

            //assign toon textures to materials
            for (int i = 0; i < mats.Length; i++)
            {
                mats[i].SetTexture(toonData[materialToonTable[i]], TextureType.Toon);
            }
        }