Beispiel #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))
                {
                    SpectaclesContainer.SpectaclesMaterial m
                        = new SpectaclesContainer.SpectaclesMaterial();

                    m.uuid        = uid;
                    m.type        = "MeshLambertMaterial";
                    m.color       = iColor;
                    m.ambient     = m.color;
                    m.emissive    = 0;
                    m.shading     = 1;
                    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);
            }
        }
Beispiel #2
0
        /// <summary>
        /// Set the current material
        /// </summary>
        void SetCurrentMaterial(string uidMaterial)
        {
            if (!_materials.ContainsKey(uidMaterial))
            {
                Material material = _doc.GetElement(
                    uidMaterial) as Material;

                SpectaclesContainer.SpectaclesMaterial m
                    = new SpectaclesContainer.SpectaclesMaterial();

                //m.metadata = new SpectaclesContainer.SpectaclesMaterialMetadata();
                //m.metadata.type = "material";
                //m.metadata.version = 4.2;
                //m.metadata.generator = "Spectacles.RevitExporter 2015.0.0.0";

                m.uuid        = uidMaterial;
                m.name        = material.Name;
                m.type        = "MeshLambertMaterial";
                m.color       = Util.ColorToInt(material.Color);
                m.ambient     = m.color;
                m.emissive    = 0;
                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.shading     = 1;
                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 SpectaclesContainer.SpectaclesObject());
                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 SpectaclesContainer.SpectaclesGeometry());
                CurrentGeometryPerMaterial.uuid               = uid_per_material;
                CurrentGeometryPerMaterial.type               = "Geometry";
                CurrentGeometryPerMaterial.data               = new SpectaclesContainer.SpectaclesGeometryData();
                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());
            }
        }