public void Serialize()
        {
            var container = new GraphicStreamContainer();
            var positions = new[] { Vector3.XAxis, Vector3.YAxis, Vector3.ZAxis };
            container.Create(GraphicStreamUsage.Position, positions);
            var texCoords = new[] { Vector2.XAxis, Vector2.YAxis };
            container.Create(GraphicStreamUsage.TextureCoordinate, texCoords);

            var filename = "test.txt";
            Serializer.SerializeBinary(container, filename);

            var deserializedContainer = Serializer.DeserializeBinary<GraphicStreamContainer>(filename);

            deserializedContainer.ShouldNotBeNull();
            deserializedContainer.Count().ShouldEqual(2);

            deserializedContainer.GetByUsage(GraphicStreamUsage.Position)
                .ShouldNotBeNull()
                .TypeShouldBe<GraphicStream<Vector3>>()
                .Data.ShouldEqual(positions);

            deserializedContainer.GetByUsage(GraphicStreamUsage.TextureCoordinate)
                .ShouldNotBeNull()
                .TypeShouldBe<GraphicStream<Vector2>>()
                .Data.ShouldEqual(texCoords);
        }
        public void GetByUsage()
        {
            var container = new GraphicStreamContainer();

            var indices = new[] { 0, 1, 3 };
            container.Create(GraphicStreamUsage.Position, new[] { 1f, 2f, 3f });
            container.Create(GraphicStreamUsage.Index, indices);

            var stream = container.GetByUsage(GraphicStreamUsage.Index);

            Assert.IsNotNull(stream);
            Assert.AreEqual(GraphicStreamUsage.Index, stream.Description.Usage);
            Assert.AreElementsEqual(indices, stream.DowncastTo<GraphicStream<int>>().Data);
        }
Esempio n. 3
0
        public GraphicStreamContainer Parse()
        {
            int triangleCount = Convert.ToInt32(
                mTriangleElement.Attribute("count").Value,
                CultureInfo.InvariantCulture);

            var allIndices = ParseUIntArray(mTriangleElement.Element(
                ColladaImporter.Namespace + "p"));
            var segmentLenght = allIndices.Count() / triangleCount / 3;

            var container = new GraphicStreamContainer();
            var indices = allIndices.EachNthElement(segmentLenght).ToArray();
            container.Create(GraphicStreamUsage.Index, indices);
            var vertexCount = (int)indices.Max() + 1;

            var inputs = ParseInputs();

            foreach (var input in inputs)
            {
                var usage = SemanticHelper.GetUsageForSemantic(input.Semantic);
                var data = new SourceParser(input.SourceElement).Parse();

                if (usage != GraphicStreamUsage.Position)
                {
                    var specificIndices = allIndices.EachNthElement(
                        segmentLenght, input.Offset).ToArray();

                    var newData = new float[vertexCount][];
                    for (int i = 0; i < indices.Length; i++)
                    {
                        var positionIndex = (int)indices[i];
                        newData[positionIndex] = data.ElementAt((int)specificIndices[i]);
                    }

                    data = newData;
                }

                var elementLength = data.First().Length;
                switch (elementLength)
                {
                    case 2:
                        container.Create(usage,
                            data.Select(element => new Vector2(element)).ToArray());
                        break;
                    case 3:
                        container.Create(usage,
                            data.Select(element => new Vector3(element)).ToArray());
                        break;
                    case 4:
                        container.Create(usage,
                            data.Select(element => new Vector4(element)).ToArray());
                        break;
                }
            }

            return container;
        }
        /// <summary>
        /// Loads the resources for this scene.
        /// </summary>
        public override void Load()
        {
            var container = new GraphicStreamContainer();
            var positions = container.Create(GraphicStreamUsage.Position, CreatePositions());
            var colors = container.Create(GraphicStreamUsage.Color, CreateColors());
            var indices = container.Create(GraphicStreamUsage.Index, CreateIndices());

            IBufferService bufferService = new OpenTKBufferService();

            var bufferBindings = new[]
            {
                bufferService.CreateFor(positions),
             //   bufferService.CreateFor(colors),
                bufferService.CreateFor(indices)
            };

            mRenderer = new OpenTKObjectRenderer(bufferBindings);
        }
        /// <summary>
        /// Loads the resources for this scene.
        /// </summary>
        public override void Load()
        {
            var container = new GraphicStreamContainer();
            var positions = container.Create(GraphicStreamUsage.Position, CreatePositions());
            var colors = container.Create(GraphicStreamUsage.Color, CreateColors());

            IBufferService bufferService = new SlimDXBufferService(RenderWindow.Device);

            var bufferBindings = new[]
            {
                bufferService.CreateFor(positions),
                bufferService.CreateFor(colors)
            };

            mEffect = new SlimDXEffectCompiler(RenderWindow.Device).Compile("MyShader10.fx");

            mRenderer = new SlimDXObjectRenderer(RenderWindow.Device,
                mEffect, bufferBindings);

            mWorldViewProjectionParameter = new SlimDXMatrixEffectParameter("WorldViewProjection");
        }
        public void Create_Returns_Stream_And_Adds_Stream()
        {
            var container = new GraphicStreamContainer();

            var usage = GraphicStreamUsage.Normal;
            var data = new[] { 1f, 2f, 3f };
            var stream = container.Create(usage, data);

            Assert.IsNotNull(stream);
            Assert.AreEqual(usage, stream.Description.Usage);
            Assert.AreEqual(data, stream.Data);

            Assert.AreEqual(1, container.Count());
        }
Esempio n. 7
0
        /// <summary>
        /// Loads the resources for this scene.
        /// </summary>
        public override void Load()
        {
            var container = new GraphicStreamContainer();
            var positions = container.Create(GraphicStreamUsage.Position, CreatePositions());
            var colors = container.Create(GraphicStreamUsage.Color, CreateColors());

            IBufferService bufferService = new XnaBufferService(RenderWindow.Device);

            var bufferBindings = new[]
            {
                bufferService.CreateFor(colors),
                bufferService.CreateFor(positions),
            };

            mEffect = new XnaEffectCompiler(RenderWindow.Device).Compile("MyShader.fx");
            mRenderer = new XnaObjectRenderer(RenderWindow.Device, mEffect, bufferBindings);

            mWorldViewProjectionParameter = new XnaMatrixEffectParameter("WorldViewProjection");

            mCamera = new Camera(new Stand(), new PerspectiveProjectionLense());
            mCamera.Stand.Position = new Vector3(0, 0, 3);

            SetupKeysAndActions();
        }