Exemplo n.º 1
0
 private SceneTemplate(string name, Object extras, ArmatureTemplate armature, DrawableTemplate[] drawables)
 {
     _Name               = name;
     _Extras             = extras;
     _Armature           = armature;
     _DrawableReferences = drawables;
 }
Exemplo n.º 2
0
        internal SceneInstance(ArmatureTemplate armature, DrawableTemplate[] drawables)
        {
            Guard.NotNull(armature, nameof(armature));
            Guard.NotNull(drawables, nameof(drawables));

            _Armature = new ArmatureInstance(armature);

            _DrawableReferences = drawables;
            _DrawableTransforms = new IGeometryTransform[_DrawableReferences.Length];

            for (int i = 0; i < _DrawableTransforms.Length; ++i)
            {
                _DrawableTransforms[i] = _DrawableReferences[i].CreateGeometryTransform();
            }
        }
Exemplo n.º 3
0
        internal ArmatureInstance(ArmatureTemplate template)
        {
            _NodeTemplates = template.Nodes;

            var ni = new NodeInstance[_NodeTemplates.Count];

            for (var i = 0; i < ni.Length; ++i)
            {
                var n = _NodeTemplates[i];
                var p = n.ParentIndex < 0 ? null : ni[n.ParentIndex];

                ni[i] = new NodeInstance(n, p);
            }

            _NodeInstances = ni;

            _AnimationTracks = template.Tracks;
        }
Exemplo n.º 4
0
        /// <summary>
        /// Creates a new <see cref="SceneTemplate"/> from a given <see cref="Schema2.Scene"/>.
        /// </summary>
        /// <param name="srcScene">The source <see cref="Schema2.Scene"/> to templatize.</param>
        /// <param name="options">Custom processing options, or null.</param>
        /// <returns>A new <see cref="SceneTemplate"/> instance.</returns>
        public static SceneTemplate Create(Schema2.Scene srcScene, RuntimeOptions options = null)
        {
            Guard.NotNull(srcScene, nameof(srcScene));

            var armature = ArmatureTemplate.Create(srcScene, options);

            // gather scene nodes.

            var srcNodes = Schema2.Node.Flatten(srcScene)
                           .Select((key, idx) => (key, idx))
                           .ToDictionary(pair => pair.key, pair => pair.idx);

            int indexSolver(Schema2.Node srcNode)
            {
                if (srcNode == null)
                {
                    return(-1);
                }
                return(srcNodes[srcNode]);
            }

            // create drawables.

            var instances = srcNodes.Keys
                            .Where(item => item.Mesh != null)
                            .ToList();

            var drawables = new DrawableTemplate[instances.Count];

            for (int i = 0; i < drawables.Length; ++i)
            {
                var srcInstance = instances[i];

                drawables[i] = srcInstance.Skin != null
                    ?
                               new SkinnedDrawableTemplate(srcInstance, indexSolver)
                    :
                               (DrawableTemplate) new RigidDrawableTemplate(srcInstance, indexSolver);
            }

            var extras = RuntimeOptions.ConvertExtras(srcScene, options);

            return(new SceneTemplate(srcScene.Name, extras, armature, drawables));
        }
Exemplo n.º 5
0
        /// <summary>
        /// Creates a new <see cref="SceneTemplate"/> from a given <see cref="Schema2.Scene"/>.
        /// </summary>
        /// <param name="srcScene">The source <see cref="Schema2.Scene"/> to templatize.</param>
        /// <param name="options">Custom processing options, or null.</param>
        /// <returns>A new <see cref="SceneTemplate"/> instance.</returns>
        public static SceneTemplate Create(Schema2.Scene srcScene, RuntimeOptions options = null)
        {
            Guard.NotNull(srcScene, nameof(srcScene));

            if (options == null)
            {
                options = new RuntimeOptions();
            }

            var armature = ArmatureTemplate.Create(srcScene, options);

            // gather scene nodes.

            var srcNodes = Schema2.Node.Flatten(srcScene)
                           .Select((key, idx) => (key, idx))
                           .ToDictionary(pair => pair.key, pair => pair.idx);

            int indexSolver(Schema2.Node srcNode)
            {
                if (srcNode == null)
                {
                    return(-1);
                }
                return(srcNodes[srcNode]);
            }

            // create drawables.

            var instances = srcNodes.Keys
                            .Where(item => item.Mesh != null)
                            .ToList();

            var drawables = new List <DrawableTemplate>();

            for (int i = 0; i < instances.Count; ++i)
            {
                var srcInstance = instances[i];

                if (srcInstance.Skin != null)
                {
                    drawables.Add(new SkinnedDrawableTemplate(srcInstance, indexSolver));
                    continue;
                }

                if (srcInstance.GetGpuInstancing() == null)
                {
                    drawables.Add(new RigidDrawableTemplate(srcInstance, indexSolver));
                    continue;
                }

                switch (options.GpuMeshInstancing)
                {
                case MeshInstancing.Discard: break;

                case MeshInstancing.Enabled:
                    drawables.Add(new InstancedDrawableTemplate(srcInstance, indexSolver));
                    break;

                case MeshInstancing.SingleMesh:
                    drawables.Add(new RigidDrawableTemplate(srcInstance, indexSolver));
                    break;

                default: throw new NotImplementedException();
                }
            }

            var extras = RuntimeOptions.ConvertExtras(srcScene, options);

            return(new SceneTemplate(srcScene.Name, extras, armature, drawables.ToArray()));
        }
Exemplo n.º 6
0
 private SceneTemplate(string name, ArmatureTemplate armature, DrawableTemplate[] drawables)
 {
     _Name               = name;
     _Armature           = armature;
     _DrawableReferences = drawables;
 }