Exemplo n.º 1
0
        public void Physics_Element_Can_Be_Retrieved_When_It_Is_Present()
        {
            var primitive = new Primitive();
            var physics = new Physics();
            physics.Enabled = true;
            physics.Movable = true;
            physics.Weight = 1234;

            primitive.Add(physics);

            Assert.NotNull(primitive.GetPhysics());
            Assert.Equal(physics.Weight, primitive.GetPhysics().Weight);
        }
Exemplo n.º 2
0
        public void Material_Elements_Can_Be_Retrieved_From_A_MaterialGroup()
        {
            var primitive = new Primitive();

            var mGroupIdOne = new MaterialGroup();
            mGroupIdOne.Id = 1;

            mGroupIdOne.Add(Material.Default);
            primitive.Add(mGroupIdOne);

            Assert.NotNull(primitive.GetMaterialGroup(1));
            Assert.Equal(Material.Default.ToString(), primitive.GetMaterialGroup(1).GetMaterial().ToString());
        }
Exemplo n.º 3
0
        public void Network_Element_Can_Be_Retrieved_When_It_Is_Present()
        {
            var primitive = new Primitive();
            var network = new Network();
            network.Enabled = true;
            network.Owner = Guid.NewGuid().ToString();

            primitive.Add(network);

            Assert.NotNull(primitive.GetNetwork());
            Assert.Equal(network.Enabled, primitive.GetNetwork().Enabled);
            Assert.Equal(network.Owner, primitive.GetNetwork().Owner);
        }
Exemplo n.º 4
0
        public void Texture_Elements_Can_Be_Retrieved_From_A_MaterialGroup()
        {
            var primitive = new Primitive();

            var mGroupIdOne = new MaterialGroup();
            mGroupIdOne.Id = 1;

            var texture = new Texture { Source = Guid.NewGuid().ToString() };
            mGroupIdOne.Add(texture);
            primitive.Add(mGroupIdOne);

            Assert.NotNull(primitive.GetMaterialGroup(1));
            Assert.Equal(texture.Source, primitive.GetMaterialGroup(1).GetTexture().Source);
        }
Exemplo n.º 5
0
        public void Video_Elements_Can_Be_Retrieved_From_A_MaterialGroup()
        {
            var primitive = new Primitive();

            var mGroupIdOne = new MaterialGroup();
            mGroupIdOne.Id = 1;

            var video = new Video { Source = Guid.NewGuid().ToString() };
            mGroupIdOne.Add(video);
            primitive.Add(mGroupIdOne);

            Assert.NotNull(primitive.GetMaterialGroup(1));
            Assert.Equal(video.Source, primitive.GetMaterialGroup(1).GetVideo().Source);
        }
Exemplo n.º 6
0
        public void Filter_Settings_Can_Be_Retrieved_From_A_Network_Element()
        {
            var primitive = new Primitive();
            var network = new Network();

            var filter = new Filter();
            filter.Target = Guid.NewGuid().ToString();

            network.Add(filter);
            primitive.Add(network);

            Assert.NotEmpty(primitive.GetNetwork().GetFilters());
            Assert.Equal(1, primitive.GetNetwork().GetFilters().Count);
            Assert.Equal(filter.Target, primitive.GetNetwork().GetFilters().First().Target);
        }
Exemplo n.º 7
0
        public void Interaction_Settings_Can_Be_Retrieved_From_A_Physics_Element()
        {
            var primitive = new Primitive();
            var physics = new Physics();

            var interaction = new Interaction();
            interaction.Element = Guid.NewGuid().ToString();

            physics.Add(interaction);
            primitive.Add(physics);

            Assert.NotEmpty(primitive.GetPhysics().GetInteractions());
            Assert.Equal(1, primitive.GetPhysics().GetInteractions().Count);
            Assert.Equal(interaction.Element, primitive.GetPhysics().GetInteractions().First().Element);
        }
Exemplo n.º 8
0
        public void MaterialGroup_Elements_Can_Be_Retrieved_By_Id()
        {
            var primitive = new Primitive();

            var mGroupIdOne = new MaterialGroup();
            mGroupIdOne.Id = 1;

            var mGroupIdTwo = new MaterialGroup();
            mGroupIdTwo.Id = 2;

            var mGroupIdDefault = new MaterialGroup();
            mGroupIdDefault.Id = -1;

            primitive.Add(mGroupIdDefault);
            primitive.Add(mGroupIdTwo);
            primitive.Add(mGroupIdOne);

            Assert.NotNull(primitive.GetMaterialGroup(-1));
            Assert.NotNull(primitive.GetMaterialGroup(1));
            Assert.NotNull(primitive.GetMaterialGroup(2));
        }
Exemplo n.º 9
0
        public void Serialiser_Can_Write_A_Simple_Nested_Hierarchy_To_A_String()
        {
            var immlDocument = new ImmlDocument();
            immlDocument.Author = Guid.NewGuid().ToString();

            var model = new Model();
            model.Name = Guid.NewGuid().ToString();
            model.Source = string.Format("http://{0}", Guid.NewGuid().ToString());

            var primitive = new Primitive();
            primitive.Name = Guid.NewGuid().ToString();

            var camera = new Camera();
            camera.Name = Guid.NewGuid().ToString();

            primitive.Add(camera);
            model.Add(primitive);
            immlDocument.Add(model);

            var immlSerialiser = new ImmlSerialiser();
            var immlString = immlSerialiser.Write(immlDocument);

            var textReader = new StringReader(immlString);
            var xDoc = XDocument.Load(textReader);

            //verify the model is in the correct place
            var xElementModel = xDoc.Descendants(XName.Get("Model", immlSerialiser.Namespace)).Where(e => e.Attribute(XName.Get("Name")).Value == model.Name).FirstOrDefault();
            Assert.NotNull(xElementModel);
            Assert.Equal(immlDocument.Name, xElementModel.Parent.Attribute(XName.Get("Name")).Value);

            //verify the primitive is in the correct place
            var xElementPrimitive = xDoc.Descendants(XName.Get("Primitive", immlSerialiser.Namespace)).Where(e => e.Attribute(XName.Get("Name")).Value == primitive.Name).FirstOrDefault();
            Assert.NotNull(xElementPrimitive);
            Assert.Equal(model.Name, xElementPrimitive.Parent.Attribute(XName.Get("Name")).Value);

            //verify the camera is in the correct place
            var xElementCamera = xDoc.Descendants(XName.Get("Camera", immlSerialiser.Namespace)).Where(e => e.Attribute(XName.Get("Name")).Value == camera.Name).FirstOrDefault();
            Assert.NotNull(xElementCamera);
            Assert.Equal(primitive.Name, xElementCamera.Parent.Attribute(XName.Get("Name")).Value);
        }
Exemplo n.º 10
0
        public void TryGetElementByName_Returns_An_ImmlElement_When_Found()
        {
            var name = "PrimitiveElement";

            var primitive = new Primitive();
            primitive.Name = name;

            var collection = new ImmlElement();
            collection.Add(primitive);

            ImmlElement outElement = null;
            var found = collection.TryGetElementByName(name, out outElement);

            Assert.True(found);
            Assert.Equal(primitive, outElement);
        }
Exemplo n.º 11
0
 public void Primitive_Element_Is_Created_Without_A_Default_MaterialGroup()
 {
     var primitive = new Primitive();
     Assert.Null(primitive.GetMaterialGroup(-1));
 }
Exemplo n.º 12
0
        public void TryGetElementByName_Returns_False_When_An_Element_With_The_Specified_Name_Is_Not_Found()
        {
            var name = "PrimitiveElement";

            var primitive = new Primitive();
            primitive.Name = name;

            var collection = new ImmlElement();
            collection.Add(primitive);

            ImmlElement outElement = null;
            var found = collection.TryGetElementByName(Guid.NewGuid().ToString(), out outElement);

            Assert.False(found);
            Assert.Null(outElement);
        }
Exemplo n.º 13
0
 public void Default_Type_Is_Box()
 {
     var primitive = new Primitive();
     Assert.Equal(PrimitiveType.Box, primitive.Type);
 }
Exemplo n.º 14
0
        public void TryGetElementByID_Returns_An_ImmlElement_When_Found()
        {
            var primitive = new Primitive();

            var collection = new ImmlElement();
            collection.Add(primitive);

            ImmlElement outElement = null;
            var found = collection.TryGetElementByID(primitive.ID, out outElement);

            Assert.True(found);
            Assert.Equal(primitive, outElement);
        }
Exemplo n.º 15
0
 public void Default_Complexity_Is_Medium()
 {
     var primitive = new Primitive();
     Assert.Equal(PrimitiveComplexity.Medium, primitive.Complexity);
 }
Exemplo n.º 16
0
        public void TryGetElementByName_Returns_Strongly_Typed_Elements_When_Found()
        {
            var name = "PrimitiveElement";

            var primitive = new Primitive();
            primitive.Name = name;

            var collection = new ImmlElement();
            collection.Add(primitive);

            Primitive outPrimitive = null;
            var found = collection.TryGetElementByName<Primitive>(name, out outPrimitive);

            Assert.True(found);
            Assert.Equal(primitive, outPrimitive);
        }
Exemplo n.º 17
0
        public void Web_Elements_Can_Be_Retrieved_From_A_MaterialGroup()
        {
            var primitive = new Primitive();

            var mGroupIdOne = new MaterialGroup();
            mGroupIdOne.Id = 1;

            var web = new Web { Source = Guid.NewGuid().ToString() };
            mGroupIdOne.Add(web);
            primitive.Add(mGroupIdOne);

            Assert.NotNull(primitive.GetMaterialGroup(1));
            Assert.Equal(web.Source, primitive.GetMaterialGroup(1).GetWeb().Source);
        }
Exemplo n.º 18
0
        public void Serialiser_Can_Write_An_Object_To_A_String()
        {
            var primitive = new Primitive();
            primitive.Name = Guid.NewGuid().ToString();

            var immlSerialiser = new ImmlSerialiser();
            var imml = immlSerialiser.Write(primitive);

            Assert.True(imml.Contains(string.Format("Name=\"{0}\"", primitive.Name)));
        }
Exemplo n.º 19
0
        public void Serialiser_Can_Write_An_Object_To_A_Stream()
        {
            var primitive = new Primitive();
            primitive.Name = Guid.NewGuid().ToString();

            var outputStream = new MemoryStream();
            var immlSerialiser = new ImmlSerialiser();
            immlSerialiser.Write(primitive, outputStream);

            Assert.True(outputStream.Length > 0);

            var immlString = Encoding.ASCII.GetString(outputStream.ToArray());
            Assert.True(immlString.Contains(string.Format("Name=\"{0}\"", primitive.Name)));
        }
Exemplo n.º 20
0
 public void Primitive_Element_Is_Created_Without_Network()
 {
     var primitive = new Primitive();
     Assert.Null(primitive.GetNetwork());
 }
Exemplo n.º 21
0
        public void Using_A_Sort_Comparer_Alters_The_Order_Of_The_Attrbutes_Written_By_The_Serialiser()
        {
            var immlSerialiser = new ImmlSerialiser();
            var primitive = new Primitive();
            primitive.Behaviours.Add(Guid.NewGuid().ToString());
            primitive.CastShadows = true;
            primitive.Complexity = PrimitiveComplexity.VeryHigh;
            primitive.Name = Guid.NewGuid().ToString();
            primitive.Position = new Vector3(1, 2, 3);
            primitive.Rotation = new Vector3(4, 5, 6);
            primitive.Size = new Vector3(7, 8, 9);

            var attribSortComparer = new Mock<IComparer<string>>();
            attribSortComparer.Setup(c => c.Compare(It.IsAny<string>(), It.IsAny<string>())).Returns(new Func<string, string, int>(_NameFirstAttributeComparer));

            var immlString = immlSerialiser.Write(primitive, attribSortComparer.Object);

            var textReader = new StringReader(immlString);
            var xDoc = XDocument.Load(textReader);

            var xElementPrimitive = xDoc.Descendants(XName.Get("Primitive", immlSerialiser.Namespace)).FirstOrDefault();
            Assert.NotNull(xElementPrimitive);

            Assert.Equal("Name", xElementPrimitive.Attributes().First().Name.LocalName);
        }
Exemplo n.º 22
0
        public void Initialise(IImmlElement context, DeviceManager deviceManager)
        {
            _Context = context as Primitive;

            RemoveAndDispose(ref _ConstantBuffer);

            var path = Windows.ApplicationModel.Package.Current.InstalledLocation.Path;

            var vertexShaderByteCode = NativeFile.ReadAllBytes(System.IO.Path.Combine(path, "MetroImml.Framework\\Resources\\Shaders\\MiniCube_VS.fxo"));
            _VertexShader = new VertexShader(deviceManager.DeviceDirect3D, vertexShaderByteCode);

            _PixelShader = new PixelShader(deviceManager.DeviceDirect3D, NativeFile.ReadAllBytes(System.IO.Path.Combine(path, "MetroImml.Framework\\Resources\\Shaders\\MiniCube_PS.fxo")));

            // Layout from VertexShader input signature
            _InputLayout = new InputLayout(deviceManager.DeviceDirect3D, vertexShaderByteCode, new[]
            {
                new InputElement("POSITION", 0, Format.R32G32B32A32_Float, 0, 0),
                new InputElement("COLOR", 0, Format.R32G32B32A32_Float, 16, 0)
            });

            // Instantiate Vertex buffer from vertex data
            var vertices = SharpDX.Direct3D11.Buffer.Create(deviceManager.DeviceDirect3D, BindFlags.VertexBuffer, new[]
            {
                new Vector4(-1.0f, -1.0f, -1.0f, 1.0f), new Vector4(1.0f, 0.0f, 0.0f, 1.0f), // Front
                new Vector4(-1.0f,  1.0f, -1.0f, 1.0f), new Vector4(1.0f, 0.0f, 0.0f, 1.0f),
                new Vector4( 1.0f,  1.0f, -1.0f, 1.0f), new Vector4(1.0f, 0.0f, 0.0f, 1.0f),
                new Vector4(-1.0f, -1.0f, -1.0f, 1.0f), new Vector4(1.0f, 0.0f, 0.0f, 1.0f),
                new Vector4( 1.0f,  1.0f, -1.0f, 1.0f), new Vector4(1.0f, 0.0f, 0.0f, 1.0f),
                new Vector4( 1.0f, -1.0f, -1.0f, 1.0f), new Vector4(1.0f, 0.0f, 0.0f, 1.0f),

                new Vector4(-1.0f, -1.0f,  1.0f, 1.0f), new Vector4(0.0f, 1.0f, 0.0f, 1.0f), // BACK
                new Vector4( 1.0f,  1.0f,  1.0f, 1.0f), new Vector4(0.0f, 1.0f, 0.0f, 1.0f),
                new Vector4(-1.0f,  1.0f,  1.0f, 1.0f), new Vector4(0.0f, 1.0f, 0.0f, 1.0f),
                new Vector4(-1.0f, -1.0f,  1.0f, 1.0f), new Vector4(0.0f, 1.0f, 0.0f, 1.0f),
                new Vector4( 1.0f, -1.0f,  1.0f, 1.0f), new Vector4(0.0f, 1.0f, 0.0f, 1.0f),
                new Vector4( 1.0f,  1.0f,  1.0f, 1.0f), new Vector4(0.0f, 1.0f, 0.0f, 1.0f),

                new Vector4(-1.0f, 1.0f, -1.0f,  1.0f), new Vector4(0.0f, 0.0f, 1.0f, 1.0f), // Top
                new Vector4(-1.0f, 1.0f,  1.0f,  1.0f), new Vector4(0.0f, 0.0f, 1.0f, 1.0f),
                new Vector4( 1.0f, 1.0f,  1.0f,  1.0f), new Vector4(0.0f, 0.0f, 1.0f, 1.0f),
                new Vector4(-1.0f, 1.0f, -1.0f,  1.0f), new Vector4(0.0f, 0.0f, 1.0f, 1.0f),
                new Vector4( 1.0f, 1.0f,  1.0f,  1.0f), new Vector4(0.0f, 0.0f, 1.0f, 1.0f),
                new Vector4( 1.0f, 1.0f, -1.0f,  1.0f), new Vector4(0.0f, 0.0f, 1.0f, 1.0f),

                new Vector4(-1.0f,-1.0f, -1.0f,  1.0f), new Vector4(1.0f, 1.0f, 0.0f, 1.0f), // Bottom
                new Vector4( 1.0f,-1.0f,  1.0f,  1.0f), new Vector4(1.0f, 1.0f, 0.0f, 1.0f),
                new Vector4(-1.0f,-1.0f,  1.0f,  1.0f), new Vector4(1.0f, 1.0f, 0.0f, 1.0f),
                new Vector4(-1.0f,-1.0f, -1.0f,  1.0f), new Vector4(1.0f, 1.0f, 0.0f, 1.0f),
                new Vector4( 1.0f,-1.0f, -1.0f,  1.0f), new Vector4(1.0f, 1.0f, 0.0f, 1.0f),
                new Vector4( 1.0f,-1.0f,  1.0f,  1.0f), new Vector4(1.0f, 1.0f, 0.0f, 1.0f),

                new Vector4(-1.0f, -1.0f, -1.0f, 1.0f), new Vector4(1.0f, 0.0f, 1.0f, 1.0f), // Left
                new Vector4(-1.0f, -1.0f,  1.0f, 1.0f), new Vector4(1.0f, 0.0f, 1.0f, 1.0f),
                new Vector4(-1.0f,  1.0f,  1.0f, 1.0f), new Vector4(1.0f, 0.0f, 1.0f, 1.0f),
                new Vector4(-1.0f, -1.0f, -1.0f, 1.0f), new Vector4(1.0f, 0.0f, 1.0f, 1.0f),
                new Vector4(-1.0f,  1.0f,  1.0f, 1.0f), new Vector4(1.0f, 0.0f, 1.0f, 1.0f),
                new Vector4(-1.0f,  1.0f, -1.0f, 1.0f), new Vector4(1.0f, 0.0f, 1.0f, 1.0f),

                new Vector4( 1.0f, -1.0f, -1.0f, 1.0f), new Vector4(0.0f, 1.0f, 1.0f, 1.0f), // Right
                new Vector4( 1.0f,  1.0f,  1.0f, 1.0f), new Vector4(0.0f, 1.0f, 1.0f, 1.0f),
                new Vector4( 1.0f, -1.0f,  1.0f, 1.0f), new Vector4(0.0f, 1.0f, 1.0f, 1.0f),
                new Vector4( 1.0f, -1.0f, -1.0f, 1.0f), new Vector4(0.0f, 1.0f, 1.0f, 1.0f),
                new Vector4( 1.0f,  1.0f, -1.0f, 1.0f), new Vector4(0.0f, 1.0f, 1.0f, 1.0f),
                new Vector4( 1.0f,  1.0f,  1.0f, 1.0f), new Vector4(0.0f, 1.0f, 1.0f, 1.0f),
            });

            _VertexBufferBinding = new VertexBufferBinding(vertices, Utilities.SizeOf<Vector4>() * 2, 0);

            //load the resources required by this type of primitive
            _ConstantBuffer = ToDispose(new Buffer(deviceManager.DeviceDirect3D, Utilities.SizeOf<Matrix>(), ResourceUsage.Default, BindFlags.ConstantBuffer, CpuAccessFlags.None, ResourceOptionFlags.None, 0));

            _Stopwatch = new System.Diagnostics.Stopwatch();
            _Stopwatch.Start();
        }
Exemplo n.º 23
0
 public void Primitive_Element_Is_Created_Without_Physics()
 {
     var primitive = new Primitive();
     Assert.Null(primitive.GetPhysics());
 }
Exemplo n.º 24
0
        public void Nested_Element_Parent_Property_Should_Be_Equal_To_The_Parent_Element()
        {
            var parent = new Primitive();
            var child = new Primitive();

            parent.Add(child);

            Assert.Equal(parent, child.Parent);
        }