Example #1
0
        public void OnMaterial(MaterialNode node)
        {
            Debug.WriteLine("     --> On Material: "
                            + node.MaterialId + ": " + node.NodeName);

            // OnMaterial method can be invoked for every
            // single out-coming mesh even when the material
            // has not actually changed. Thus it is usually
            // beneficial to store the current material and
            // only get its attributes when the material
            // actually changes.

            ElementId id = node.MaterialId;

            if (ElementId.InvalidElementId != id)
            {
                Element m = _doc.GetElement(node.MaterialId);
                SetCurrentMaterial(m.UniqueId);
            }
            else
            {
                //string uid = Guid.NewGuid().ToString();

                // Generate a GUID based on colour,
                // transparency, etc. to avoid duplicating
                // non-element material definitions.

                int iColor = Util.ColorToInt(node.Color);

                string uid = string.Format("MaterialNode_{0}_{1}",
                                           iColor, Util.RealString(node.Transparency * 100));

                if (!_materials.ContainsKey(uid))
                {
                    Va3cContainer.Va3cMaterial m
                        = new Va3cContainer.Va3cMaterial();

                    m.uuid    = uid;
                    m.type    = "MeshPhongMaterial";
                    m.color   = iColor;
                    m.ambient = m.color;
                    //m.emissive = 0;
                    m.specular = m.color;
                    //m.shininess = node.Glossiness; // todo: does this need scaling to e.g. [0,100]?
                    m.opacity     = 1;                       // 128 - material.Transparency;
                    m.opacity     = 1.0 - node.Transparency; // Revit MaterialNode has double Transparency in ?range?, three.js expects opacity in [0.0,1.0]
                    m.transparent = 0.0 < node.Transparency;
                    m.wireframe   = false;

                    _materials.Add(uid, m);
                }
                SetCurrentMaterial(uid);
            }
        }
Example #2
0
        /// <summary>
        /// Set the current material
        /// </summary>
        void SetCurrentMaterial(string uidMaterial)
        {
            if (!_materials.ContainsKey(uidMaterial))
            {
                Material material = _doc.GetElement(
                    uidMaterial) as Material;

                Va3cContainer.Va3cMaterial m
                    = new Va3cContainer.Va3cMaterial();

                //m.metadata = new Va3cContainer.Va3cMaterialMetadata();
                //m.metadata.type = "material";
                //m.metadata.version = 4.2;
                //m.metadata.generator = "RvtVa3c 2015.0.0.0";

                m.uuid    = uidMaterial;
                m.name    = material.Name;
                m.type    = "MeshPhongMaterial";
                m.color   = Util.ColorToInt(material.Color);
                m.ambient = m.color;
                //m.emissive = 0;
                m.specular = m.color;
                //m.shininess = 1; // todo: does this need scaling to e.g. [0,100]?
                m.opacity     = 0.01 * (double)(100 - material.Transparency); // Revit has material.Transparency in [0,100], three.js expects opacity in [0.0,1.0]
                m.transparent = 0 < material.Transparency;
                m.wireframe   = false;

                _materials.Add(uidMaterial, m);
            }
            _currentMaterialUid = uidMaterial;

            string uid_per_material = _currentElement.uuid + "-" + uidMaterial;

            if (!_currentObject.ContainsKey(uidMaterial))
            {
                Debug.Assert(!_currentGeometry.ContainsKey(uidMaterial), "expected same keys in both");

                _currentObject.Add(uidMaterial, new Va3cContainer.Va3cObject());
                CurrentObjectPerMaterial.name     = _currentElement.name;
                CurrentObjectPerMaterial.geometry = uid_per_material;
                CurrentObjectPerMaterial.material = _currentMaterialUid;
                CurrentObjectPerMaterial.matrix   = new double[] { 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 };
                CurrentObjectPerMaterial.type     = "Mesh";
                CurrentObjectPerMaterial.uuid     = uid_per_material;
            }

            if (!_currentGeometry.ContainsKey(uidMaterial))
            {
                _currentGeometry.Add(uidMaterial, new Va3cContainer.Va3cGeometry());
                CurrentGeometryPerMaterial.uuid               = uid_per_material;
                CurrentGeometryPerMaterial.type               = "Geometry";
                CurrentGeometryPerMaterial.data               = new Va3cContainer.Va3cGeometryData();
                CurrentGeometryPerMaterial.data.faces         = new List <int>();
                CurrentGeometryPerMaterial.data.vertices      = new List <double>();
                CurrentGeometryPerMaterial.data.normals       = new List <double>();
                CurrentGeometryPerMaterial.data.uvs           = new List <double>();
                CurrentGeometryPerMaterial.data.visible       = true;
                CurrentGeometryPerMaterial.data.castShadow    = true;
                CurrentGeometryPerMaterial.data.receiveShadow = false;
                CurrentGeometryPerMaterial.data.doubleSided   = true;
                CurrentGeometryPerMaterial.data.scale         = 1.0;
            }

            if (!_vertices.ContainsKey(uidMaterial))
            {
                _vertices.Add(uidMaterial, new VertexLookupInt());
            }
        }