Inheritance: ResourceItem
Exemplo n.º 1
0
        //------------------------------------------------------------------------------------------
        //------------------------------------------------------------------------------------------
        public ResourceItem Convert(object input, String collection)
        {
            MaterialItem ret = new MaterialItem();
            MaterialObject obj = (MaterialObject) input;

            ret.Properties = new Dictionary<string, PropertyItem>();

            obj.Properties.ForEach(delegate(PropertyObject value) {
                PropertyItem property = new PropertyItem();

                if(value.Type == ColorType) {
                    property.Type = ColorType;
                    property.Value = value.Value.Split(new RegularExpression("[^0-9.]+"));
                } else if(value.Type == FloatType) {
                    property.Type = FloatType;
                    property.Value = float.Parse(value.Value);
                } else if (value.Type == TextureHandleType) {
                    Handle handle = new Handle();

                    handle.Id = value.Value;
                    handle.Collection = collection;

                    property.Type = TextureHandleType;
                    property.Value = handle;
                }

                ret.Properties[value.Name] = property;
            });

            ret.Shader = obj.Shader;

            return ret;
        }
Exemplo n.º 2
0
        public void BindGeometryMaterial(MaterialItem material)
        {
            if (this._parent.GeometryPassShader == null) return;

            /*bind material*/
            TextureItem texture = (TextureItem)this._library.GetResource((Handle)material.Properties["diffuse"].Value);

            this._graphics.Uniform1f(this._parent.GeometryPassShader.Uniforms["uShinines"], material.Properties["shininess"] != null ?
                (float)material.Properties["shininess"].Value : 0);
            this._graphics.Uniform1f(this._parent.GeometryPassShader.Uniforms["uEmissive"], material.Properties["emission"] != null ?
                ((float[])material.Properties["emission"].Value)[0] : 1);

            if (texture != null) {
                this._graphics.ActiveTexture(WebGLE.Texture0);
                this._graphics.BindTexture(WebGLE.Texture_2D, texture.Texture);
                this._graphics.Uniform1i(this._parent.GeometryPassShader.Uniforms["uSampler"], 0);
            } else {
                this._graphics.ActiveTexture(WebGLE.Texture0);
                this._graphics.BindTexture(WebGLE.Texture_2D, null);
                this._graphics.Uniform1i(this._parent.GeometryPassShader.Uniforms["uSampler"], 0);
            }
        }