Exemplo n.º 1
0
        public SceneBuilder DeepClone(bool cloneArmatures = true)
        {
            var clone = new SceneBuilder();

            clone.SetNameAndExtrasFrom(this);

            var nodeMap = new Dictionary <NodeBuilder, NodeBuilder>();

            if (cloneArmatures)
            {
                foreach (var root in FindArmatures())
                {
                    var dict = root.DeepClone();

                    foreach (var pair in dict)
                    {
                        nodeMap[pair.Key] = pair.Value;
                    }
                }
            }

            var args = new ContentTransformer.DeepCloneContext(nodeMap);

            foreach (var inst in this._Instances)
            {
                var cloneInst = inst._CopyTo(clone, args);

                clone._Instances.Add(cloneInst);
            }

            return(clone);
        }
Exemplo n.º 2
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);
        }