Beispiel #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();
            float        opacity = 1 - (float)node.Transparency;

            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, opacity
                };
                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 = Guid.NewGuid().ToString();

                // construct the material
                matName     = string.Format("MaterialNode_{0}_{1}", Util.ColorToInt(node.Color), Util.RealString(opacity * 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, opacity
                };
                pbr.metallicFactor          = 0f;
                pbr.roughnessFactor         = 1f;
                gl_mat.pbrMetallicRoughness = pbr;

                Materials.AddOrUpdateCurrent(uuid, gl_mat);
            }
            Debug.WriteLine(string.Format("    OnMaterial: {0}", matName));
        }