Exemplo n.º 1
0
        public static SceneBuilder CreateFrom(Scene srcScene)
        {
            if (srcScene == null)
            {
                return(null);
            }

            // Process armatures

            var dstNodes = new Dictionary <Node, NodeBuilder>();

            foreach (var srcArmature in srcScene.VisualChildren)
            {
                var dstArmature = new NodeBuilder();
                _CopyToNodeBuilder(dstArmature, srcArmature, dstNodes);
            }

            // TODO: we must also process the armatures of every skin, in case the joints are outside the scene.

            var dstScene = new SceneBuilder();

            dstScene.SetNameAndExtrasFrom(srcScene);

            // process mesh instances
            var srcMeshInstances = Node.Flatten(srcScene)
                                   .Where(item => item.Mesh != null)
                                   .ToList();

            _AddMeshInstances(dstScene, dstNodes, srcMeshInstances);

            // process cameras
            var srcCameraInstances = Node.Flatten(srcScene)
                                     .Where(item => item.Camera != null)
                                     .ToList();

            _AddCameraInstances(dstScene, dstNodes, srcCameraInstances);

            var srcLightInstances = Node.Flatten(srcScene)
                                    .Where(item => item.PunctualLight != null)
                                    .ToList();

            _AddLightInstances(dstScene, dstNodes, srcCameraInstances);

            #if DEBUG
            dstScene._VerifyConversion(srcScene);
            #endif

            return(dstScene);
        }
Exemplo n.º 2
0
        public void AddScene(Scene dstScene, SceneBuilder srcScene)
        {
            _Nodes.Clear();
            AddArmatureResources(new[] { srcScene }, () => dstScene.CreateNode());

            // gather single operators (RigidTransformer and SkinnedTransformer)

            var srcSingleOperators = srcScene
                                     .Instances
                                     .Select(item => item.Content)
                                     .Where(item => !Geometry.MeshBuilderToolkit.IsEmpty(item.GetGeometryAsset()))
                                     .OfType <IOperator <Scene> >();

            // gather multi operators (Fixed Transformer)

            var srcChildren = srcScene
                              .Instances
                              .Select(item => item.Content)
                              .Where(item => !Geometry.MeshBuilderToolkit.IsEmpty(item.GetGeometryAsset()))
                              .OfType <FixedTransformer>();

            var srcMultiOperators = _MeshInstancing.CreateFrom(srcChildren, this.GpuMeshInstancingMinCount);

            // apply operators

            var srcOperators = srcSingleOperators.Concat(srcMultiOperators);

            foreach (var op in srcOperators)
            {
                op.ApplyTo(dstScene, this);
            }

            #if DEBUG
            srcScene._VerifyConversion(dstScene);
            #endif
        }