Ejemplo n.º 1
0
        public void AddGeometryResources(ModelRoot root, IEnumerable <SceneBuilder> srcScenes, SceneBuilderSchema2Settings settings)
        {
            // gather all unique MeshBuilders

            var srcMeshes = srcScenes
                            .SelectMany(item => item.Instances)
                            .Select(item => item.Content?.GetGeometryAsset())
                            .Where(item => item != null)
                            .Distinct()
                            .ToArray();

            // gather all unique MaterialBuilders

            var materialGroups = srcMeshes
                                 .SelectMany(item => item.Primitives)
                                 .Where(item => !Geometry.MeshBuilderToolkit.IsEmpty(item))
                                 .Select(item => item.Material)
                                 .Distinct()
                                 .ToList()
                                 // group by equal content, to reduce material splitting whenever possible.
                                 .GroupBy(item => item, Materials.MaterialBuilder.ContentComparer);

            // create a Schema2.Material for every MaterialBuilder.

            foreach (var mg in materialGroups)
            {
                var val = root.CreateMaterial(mg.Key);
                foreach (var key in mg)
                {
                    _Materials[key] = val;
                }
            }

            // create a Schema2.Mesh for every MeshBuilder.

            var dstMeshes = root.CreateMeshes(mat => _Materials[mat], settings, srcMeshes);

            for (int i = 0; i < srcMeshes.Length; ++i)
            {
                _Meshes[srcMeshes[i]] = dstMeshes[i];
            }

            // TODO: here we could check that every dstMesh has been correctly created.
        }
Ejemplo n.º 2
0
        public void OnElementEnd(ElementId elementId)
        {
            Element e = CurrentDocument.GetElement(elementId);

            if (e != null)
            {
                if (null == e.Category)
                {
                    Debug.WriteLine("\r\n*** Non-category element!\r\n");
                    return;
                }
            }

            if (_mesh.Primitives.Count > 0)
            {
                _scene.CreateNode().WithMesh(_model.CreateMeshes(_mesh)[0]);
            }
            Debug.Print($"ElementEnd {elementId.IntegerValue}");
        }