Esempio n. 1
0
        //============================================================
        public override void DrawRenderable(FDxRegion region, FDxRenderable renderable, FDxEffect effect)
        {
            // 设置顶点缓冲
            FDxGeometry geometry = renderable as FDxGeometry;

            effect.NativeEffect.GetVariableByName("_modelMatrix").AsMatrix().SetMatrix(renderable.Matrix.Native);
            effect.NativeEffect.GetVariableByName("_viewMatrix").AsMatrix().SetMatrix(region.Camera.Matrix.Native);
            effect.NativeEffect.GetVariableByName("_projectionMatrix").AsMatrix().SetMatrix(region.Camera.Viewport.Matrix);
            effect.NativeEffect.GetVariableByName("_cameraPosition").AsVector().Set(new Vector3(region.Camera.Position.X, region.Camera.Position.Y, region.Camera.Position.Z));
            effect.NativeEffect.GetVariableByName("_lightPosition").AsVector().Set(new Vector3(region.LightDirectional.Position.X, region.LightDirectional.Position.Y, region.LightDirectional.Position.Z));
            effect.NativeEffect.GetVariableByName("_lightDirection").AsVector().Set(new Vector3(region.LightDirectional.Camera.Direction.X, region.LightDirectional.Camera.Direction.Y, region.LightDirectional.Camera.Direction.Z));
            _device.NativeDevice.InputAssembler.PrimitiveTopology = PrimitiveTopology.TriangleList;
            _device.NativeDevice.InputAssembler.SetVertexBuffers(0, renderable.VertexBuffer.NativeBuffers);
            _device.NativeDevice.InputAssembler.SetIndexBuffer(renderable.FaceBuffer.NativeBuffer, Format.R32_UInt, 0);
            int textureCount = geometry.Material.Textures.Count;

            for (int i = 0; i < textureCount; i++)
            {
                FDxTexture texture = geometry.Material.Textures[i];
                if (null != texture)
                {
                    string textureName = "_texture" + RString.FirstUpper(texture.TypeName);
                    effect.NativeEffect.GetVariableByName(textureName).AsResource().SetResource(texture.NativeResource);
                }
            }
            effect.NativePass.Apply(_device.NativeDevice);
            _device.NativeDevice.DrawIndexed(renderable.FaceBuffer.count, 0, 0);
        }
Esempio n. 2
0
        //============================================================
        public override void DrawRenderable(FDxRegion region, FDxRenderable renderable, FDxEffect effect)
        {
            if (renderable.IsUi)
            {
                return;
            }
            // 设置输入数据缓冲
            _device.NativeDevice.InputAssembler.PrimitiveTopology = PrimitiveTopology.TriangleList;
            _device.NativeDevice.InputAssembler.SetVertexBuffers(0, renderable.VertexBuffer.NativeBuffers);
            _device.NativeDevice.InputAssembler.SetIndexBuffer(renderable.FaceBuffer.NativeBuffer, Format.R32_UInt, 0);
            // 设置渲染对象参数
            Vector4 flags = new Vector4(renderable.IsSelected ? 1 : 0, renderable.IsUi ? 1 : 0, 0, 0);
            // 设置渲染对象参数
            FDxGeometry geometry = renderable as FDxGeometry;
            FDxMaterial material = geometry.Material;

            effect.NativeEffect.GetVariableByName("_flags").AsVector().Set(new Vector4(renderable.Id, 0, 0, 0));
            effect.NativeEffect.GetVariableByName("_status").AsVector().Set(flags);
            effect.SetMatrix("_modelMatrix", renderable.ModelMatrix);
            effect.SetNativeMatrix("_viewMatrix", region.Camera.Matrix.Native);
            effect.SetNativeMatrix("_projectionMatrix", region.Camera.Viewport.Matrix);
            effect.NativeEffect.GetVariableByName("_projectionMatrix").AsMatrix().SetMatrix(region.Camera.Viewport.Matrix);
            effect.NativeEffect.GetVariableByName("_cameraPosition").AsVector().Set(new Vector3(region.Camera.Position.X, region.Camera.Position.Y, region.Camera.Position.Z));
            effect.NativeEffect.GetVariableByName("_lightPosition").AsVector().Set(new Vector3(region.LightDirectional.Position.X, region.LightDirectional.Position.Y, region.LightDirectional.Position.Z));
            effect.NativeEffect.GetVariableByName("_lightDirection").AsVector().Set(new Vector3(region.LightDirectional.Camera.Direction.X, region.LightDirectional.Camera.Direction.Y, region.LightDirectional.Camera.Direction.Z));
            // 设置渲染材质参数
            effect.NativeEffect.GetVariableByName("_ambientColor").AsVector().Set(new Vector4(material.AmbientColor.R, material.AmbientColor.G, material.AmbientColor.B, material.AmbientColor.A));
            effect.NativeEffect.GetVariableByName("_diffuseColor").AsVector().Set(new Vector4(material.DiffuseColor.R, material.DiffuseColor.G, material.DiffuseColor.B, material.DiffuseColor.A));
            effect.NativeEffect.GetVariableByName("_specularColor").AsVector().Set(new Vector4(material.SpecularColor.R, material.SpecularColor.G, material.SpecularColor.B, material.SpecularColor.A));
            // 设置纹理列表
            int textureCount = geometry.Material.Textures.Count;

            for (int i = 0; i < textureCount; i++)
            {
                FDxTexture texture = geometry.Material.Textures[i];
                if (null != texture)
                {
                    string textureName = "_texture" + RString.FirstUpper(texture.TypeName);
                    effect.NativeEffect.GetVariableByName(textureName).AsResource().SetResource(texture.NativeResource);
                }
            }
            // 提交效果设置
            effect.NativePass.Apply(_device.NativeDevice);
            // 绘制几何体
            _device.NativeDevice.DrawIndexed(renderable.FaceBuffer.count, 0, 0);
        }
Esempio n. 3
0
 private void BuildNodeSource(FXmlNode config, string path)
 {
     if (config.HasNode)
     {
         // Build private
         foreach (FXmlNode node in config.Nodes)
         {
             string clsName = MakeClassName(path + config["name"] + node["name"]);
             string varname = "_" + RString.FirstLower(node["name"]);
             _source.Append("      private ");
             if (node.IsName("Folder"))
             {
                 _source.Append(clsName + " " + varname + " = new ");
                 _source.AppendLine(clsName + "();");
             }
             else if (node.IsName("Property"))
             {
                 _source.AppendLine("FStringValue " + varname + " = new FStringValue();");
             }
         }
         // Build property
         foreach (FXmlNode node in config.Nodes)
         {
             string clsName = MakeClassName(path + config["name"] + node["name"]);
             string varname = "_" + RString.FirstLower(node["name"]);
             string ptyname = RString.FirstUpper(node["name"]);
             _source.Append("      public ");
             if (node.IsName("Folder"))
             {
                 string scName = path + node["name"];
                 _source.Append(clsName + " " + ptyname + " {");
                 _source.AppendLine(" get { return " + varname + "; } }");
             }
             else if (node.IsName("Property"))
             {
                 _source.Append("FStringValue " + ptyname + " {");
                 _source.AppendLine(" get { return " + varname + "; } }");
             }
         }
     }
 }
Esempio n. 4
0
        //============================================================
        // <T>加载文件夹信息,取得地址。</T>
        // <P>加载文件下文件信息,取得文件地址。</P>
        //
        // @param directory 文件路径。
        //============================================================
        public void LoadDirectory(string rootDirectory)
        {
            // 加载给定路径下面的文件夹.
            FStrings directorys = RDirectory.ListDirectories(rootDirectory);

            foreach (string directory in directorys)
            {
                // 检查文件夹
                if (directory.Contains(".svn"))
                {
                    continue;
                }
                // 取得文件夹类型名称。
                string fileName       = directory.Substring(directory.LastIndexOf("\\") + 1);
                int    codeIndex      = fileName.IndexOf('-');
                string code           = fileName.Substring(0, codeIndex);
                int    nameBeginIndex = fileName.IndexOf('(');
                int    nameEndIndex   = fileName.LastIndexOf(')');
                string name           = fileName.Substring(nameBeginIndex + 1, nameEndIndex - nameBeginIndex - 1).Trim();
                string typeName       = RString.FirstUpper(name.Substring(name.LastIndexOf('.') + 1));
                string label          = fileName.Substring(codeIndex + 1, nameBeginIndex - codeIndex - 1).Trim();
                // 文件夹的全路径地址。
                FRcFrame frame = CreateComponent(typeName) as FRcFrame;
                if (frame != null)
                {
                    // 设置属性
                    frame.Code  = RInt.Parse(code);
                    frame.Name  = name;
                    frame.Label = label;
                    // 设置信息
                    frame.FileName  = directory + @"\config.xml";
                    frame.Directory = directory;
                    // 放入集合
                    _frames.Set(name, frame);
                }
            }
        }