Exemplo n.º 1
0
        /// <summary>
        /// Runs every time, and immediately prior to, a mesh being processed (OnPolymesh).
        /// It supplies the material for the mesh, and we use this to create a new material
        /// in our material container, or switch the current material if it already exists.
        /// </summary>
        /// <param name="node"></param>
        public void OnMaterial(MaterialNode node)
        {
            string       matName;
            ElementId    id     = node.MaterialId;
            glTFMaterial gl_mat = new glTFMaterial();

            if (id != ElementId.InvalidElementId)
            {
                // construct a material from the node
                Element m = _doc.GetElement(node.MaterialId);
                matName = m.Name;

                // construct the material
                gl_mat.name = matName;
                glTFPBR pbr = new glTFPBR();
                pbr.baseColorFactor = new List <float>()
                {
                    node.Color.Red / 255f, node.Color.Green / 255f, node.Color.Blue / 255f, 1f
                };
                pbr.metallicFactor          = 0f;
                pbr.roughnessFactor         = 1f;
                gl_mat.pbrMetallicRoughness = pbr;

                Materials.AddOrUpdateCurrent(m.UniqueId, gl_mat);
            }
            else
            {
                // I'm really not sure what situation this gets triggered in?
                // make your own damn material!
                // (currently this is equivalent to above until I understand BlinnPhong/PBR conversion better)
                string uuid = string.Format("r{0}g{1}b{2}", node.Color.Red.ToString(), node.Color.Green.ToString(), node.Color.Blue.ToString());
                // construct the material
                matName     = string.Format("MaterialNode_{0}_{1}", Util.ColorToInt(node.Color), Util.RealString(node.Transparency * 100));
                gl_mat.name = matName;
                glTFPBR pbr = new glTFPBR();
                pbr.baseColorFactor = new List <float>()
                {
                    node.Color.Red / 255f, node.Color.Green / 255f, node.Color.Blue / 255f, 1f
                };
                pbr.metallicFactor          = 0f;
                pbr.roughnessFactor         = 1f;
                gl_mat.pbrMetallicRoughness = pbr;

                Materials.AddOrUpdateCurrent(uuid, gl_mat);
            }
            Debug.WriteLine(string.Format("    OnMaterial: {0}", matName));
        }
Exemplo n.º 2
0
        public void SwitchMaterial(MaterialNode matNode, string name = null, string id = null)
        {
            glTFMaterial gl_mat = new glTFMaterial();

            gl_mat.name = name;

            glTFPBR pbr = new glTFPBR();

            pbr.baseColorFactor = new List <float>()
            {
                matNode.Color.Red / 255f,
                matNode.Color.Green / 255f,
                matNode.Color.Blue / 255f,
                1f - (float)matNode.Transparency
            };
            pbr.metallicFactor          = 0f;
            pbr.roughnessFactor         = 1f;
            gl_mat.pbrMetallicRoughness = pbr;

            materialDict.AddOrUpdateCurrent(id, gl_mat);
        }