public override Scene GetScene(ISite site, bool designMode)
        {
            Scene scene = new Scene();

            foreach (Mesh mesh in Meshes)
            {
                Meshellator.Mesh meshellatorMesh = new Meshellator.Mesh();
                scene.Meshes.Add(meshellatorMesh);

                meshellatorMesh.Positions.AddRange(mesh.Positions.Select(p => new Nexus.Point3D(p.X, p.Y, p.Z)));
                meshellatorMesh.TextureCoordinates.AddRange(mesh.TextureCoordinates.Select(p => new Nexus.Point3D(p.X, p.Y, 0)));
                MeshUtility.CalculateNormals(meshellatorMesh, false);

                meshellatorMesh.Indices.AddRange(mesh.Indices.Select(i => i.Value));

                Meshellator.Material meshellatorMaterial = new Meshellator.Material();
                meshellatorMaterial.DiffuseColor = ConversionUtility.ToNexusColorRgbF(mesh.Material.DiffuseColor);
                if (!string.IsNullOrEmpty(mesh.Material.TextureFileName))
                {
                    string textureFileName = FileSourceHelper.ResolveFileName(mesh.Material.TextureFileName, Site, DesignMode);
                    if (!File.Exists(textureFileName))
                        throw new DynamicImageException("Could not find texture '" + mesh.Material.TextureFileName + "'.");
                    meshellatorMaterial.DiffuseTextureName = textureFileName;
                }
                meshellatorMaterial.Shininess = mesh.Material.Shininess;
                meshellatorMaterial.SpecularColor = ConversionUtility.ToNexusColorRgbF(mesh.Material.SpecularColor);
                meshellatorMaterial.Transparency = mesh.Material.Transparency;

                meshellatorMesh.Material = meshellatorMaterial;
                scene.Materials.Add(meshellatorMaterial);
            }

            return scene;
        }
 public override Nexus.Graphics.Cameras.Camera GetNexusCamera(Scene scene, Viewport viewport)
 {
     return new Nexus.Graphics.Cameras.PerspectiveCamera
     {
         FarPlaneDistance = FarPlaneDistance,
         FieldOfView = FieldOfView,
         LookDirection = new Nexus.Vector3D(LookDirection.X, LookDirection.Y, LookDirection.Z),
         NearPlaneDistance = NearPlaneDistance,
         Position = new Nexus.Point3D(Position.X, Position.Y, Position.Z),
         UpDirection = new Nexus.Vector3D(UpDirection.X, UpDirection.Y, UpDirection.Z)
     };
 }
 public override Nexus.Graphics.Cameras.Camera GetNexusCamera(Scene scene, Viewport viewport)
 {
     return new Nexus.Graphics.Cameras.OrthographicCamera
     {
         FarPlaneDistance = FarPlaneDistance,
         LookDirection = new Nexus.Vector3D(LookDirection.X, LookDirection.Y, LookDirection.Z),
         NearPlaneDistance = NearPlaneDistance,
         Position = new Nexus.Point3D(Position.X, Position.Y, Position.Z),
         UpDirection = new Nexus.Vector3D(UpDirection.X, UpDirection.Y, UpDirection.Z),
         Width = Width
     };
 }
示例#4
0
		public WarpSceneRenderer(Scene scene, int width, int height)
		{
			_scene = scene;
			_width = width;
			_height = height;
			_aspectRatio = width / (float)height;

			_device = GraphicsDevice.New(DriverType.Warp, DeviceCreationFlags.None, FeatureLevel.Level_10_1);

			var serviceProvider = new ServiceProvider();
			serviceProvider.AddService<IGraphicsDeviceService>(new GraphicsDeviceService(_device));

			_contentManager = new ContentManager(serviceProvider);
			_contentManager.Resolvers.Add(new ContentResolver());

			var viewport = new Viewport(0, 0, _width, _height);
			_device.SetViewports(viewport);

			const MSAALevel msaaLevel = MSAALevel.None;
			_depthStencilTexture = DepthStencilBuffer.New(_device, _width, _height, msaaLevel, DepthFormat.Depth24Stencil8);
			_renderTexture = RenderTarget2D.New(_device, _width, _height, msaaLevel, PixelFormat.R8G8B8A8.UNorm);

			Options = new RenderOptions();

			_effect = new BasicEffect(_device);
			_effect.EnableDefaultLighting();

			_inputLayout = VertexInputLayout.New(0, typeof(VertexPositionNormalTexture));
			_device.SetVertexInputLayout(_inputLayout);

			_meshes = new List<WarpMesh>();
			foreach (Mesh mesh in _scene.Meshes)
			{
				if (!mesh.Positions.Any())
					continue;

				var warpMesh = new WarpMesh(_device, mesh);
				_meshes.Add(warpMesh);

				warpMesh.Initialize(_contentManager);
			}
		}
 public abstract Nexus.Graphics.Cameras.Camera GetNexusCamera(Scene scene, Viewport viewport);
 public override Nexus.Graphics.Cameras.Camera GetNexusCamera(Scene scene, Viewport viewport)
 {
     return Nexus.Graphics.Cameras.PerspectiveCamera.CreateFromBounds(
         scene.Bounds, viewport, MathUtility.PI_OVER_4, MathUtility.ToRadians(Yaw),
         MathUtility.ToRadians(-Pitch), Zoom);
 }
示例#7
0
        private static Scene CreateFromPrimitive(BasicPrimitiveTessellator tessellator)
        {
            tessellator.Tessellate();

            Material material = new Material();
            material.Name = "Default";
            material.DiffuseColor = ColorsRgbF.Blue;
            material.SpecularColor = ColorsRgbF.White;

            Mesh mesh = new Mesh();
            mesh.Positions.AddRange(tessellator.Positions);
            mesh.Indices.AddRange(tessellator.Indices);
            mesh.Normals.AddRange(tessellator.Normals);
            mesh.Material = material;

            Scene scene = new Scene { FileName = "[New Sphere]" };
            scene.Materials.Add(material);
            scene.Meshes.Add(mesh);

            return scene;
        }