private void AddSpheres() { var mesh = Icosahedron.Create(0.05f, 3); var spheres = new Node(Scene, "spheres"); spheres.Transform.WorldPosition = new Vector3(0, 0.3f, 0); var material = new Material(MaterialType.DiffuseColor); var count = 5; for (int i = 0; i < count; i++) { for (int j = 0; j < count; j++) { for (int k = 0; k < count; k++) { var so = new Node(Scene); var r = so.AddComponent <MeshRenderable>(); r.Mesh = mesh; r.Material = material; so.Transform.LocalPosition = (new Vector3(i, k, j) - new Vector3(1, 0, 1) * (count * 0.5f)) * 0.2f; so.Transform.Parent = spheres.Transform; } } } }
public MeshPreviewSelector() { InitializeComponent(); var previewRenderer = new PreviewRenderer(new Size(200, 200)); previewRenderer.BackgroundColor = new Vector4(0.75f, 0.75f, 0.75f, 1f); var meshes = new List <Mesh>(); meshes.Add(Icosahedron.Create(0.45f, 0)); meshes.Add(Icosahedron.Create(0.45f, 1)); meshes.Add(Tube.Create(0.3f, 0.35f, 0.7f, 20)); meshes.Add(Cloud.Create(CloudShape.Sphere, 0.9f, 50000)); meshes.Add(Cone.Create(0.3f, 0.8f)); meshes.Add(TrefoilKnot.Create()); var rotation = Quaternion.CreateFromYawPitchRoll(0, -0.25f, -0.2f); MeshesListBox.ItemsSource = meshes .Select(_ => new MeshPreviewViewModel(_, previewRenderer.RenderPreview(_, rotation))) .ToArray(); previewRenderer.Dispose(); }
private void AddReflectionTest() { var environmentMap = new TextureCubemap(); var images = new Bitmap[6] { (Bitmap)Bitmap.FromFile("Resources\\Textures\\Cubemap\\xneg.png"), (Bitmap)Bitmap.FromFile("Resources\\Textures\\Cubemap\\xpos.png"), (Bitmap)Bitmap.FromFile("Resources\\Textures\\Cubemap\\yneg.png"), (Bitmap)Bitmap.FromFile("Resources\\Textures\\Cubemap\\ypos.png"), (Bitmap)Bitmap.FromFile("Resources\\Textures\\Cubemap\\zneg.png"), (Bitmap)Bitmap.FromFile("Resources\\Textures\\Cubemap\\zpos.png"), }; environmentMap.SetImages(images); var mesh = Icosahedron.Create(0.4f, 3); var material = new Material(MaterialType.RimReflectionDiffuseTextureColor, RenderQueue.Opaque); material.Color = Vector4.Zero; material.SetTexture("uniform_ReflectionTexture", environmentMap); var so = new Node(_scene, "reflective"); var renderer = so.AddComponent <MeshRenderable>(); renderer.Material = material; renderer.Mesh = mesh; }
private void AddShakeLight() { var so = new Node(Scene, "shaking light 1"); var light = so.AddComponent <LightSource>(); light.Type = LightType.Point; var r = so.AddComponent <MeshRenderable>(); var mesh = Icosahedron.Create(0.05f, 3); var material = new Material(MaterialType.FlatColor); r.Mesh = mesh; r.Material = material; so.AddComponent <Tweener>(); //so.AddComponent<Shaker>(); }
private void AddBroccoli() { var mesh = Icosahedron.Create(0.7f, 4); var sphereSo = new Node(Scene, "big sphere"); sphereSo.Transform.LocalPosition = new Vector3(0, -3, 0); var material = new Material(Shaders.Brokkoli_vert, Shaders.Brokkoli_frag, RenderQueue.Opaque); material.MainTexture = new Texture2("Resources\\Textures\\green.png", false); material.MainTexture.Wrap = TextureWrapMode.ClampToEdge; material.Color = new Vector4(1, 1, 1, 1); material.SetValue("uniform_Weight", 0.5f); var r = sphereSo.AddComponent <MeshRenderable>(); r.Mesh = mesh; r.Material = material; }
private void AddDemo() { var cameraSO = new Node(Scene, "main camera"); //scene object that will host Camera and CameraManipulator components cameraSO.AddComponent <Camera>(); //adding Camera to scene cameraSO.AddComponent <CameraManipulator>(); //adding manipulator so you can control camera with (W, A, S, D and mouse Mid) around the scene. var sphereSO = new Node(Scene, "spheres"); //scene object that will host sphere mesh renderer component sphereSO.Transform.WorldPosition = new Vector3(0, 0, -1); //position object in world space var renderer = sphereSO.AddComponent <MeshRenderable>(); //adding component that can render 3D meshes var mesh = Icosahedron.Create(0.05f, 3); //generating Icosahedron mesh (sphere) renderer.Mesh = mesh; //assigning mesh to renderer var lightSO = new Node(Scene, "light0"); //scene object for light source component hosting lightSO.Transform.WorldPosition = new Vector3(0, 0, -0.5f); //setting its position lightSO.AddComponent <LightSource>(); //adding lightsource component }
protected override void OnStart() { base.OnStart(); _collider = this.SceneObject.AddComponent <SphereCollider>(); _collider.Radius = 0.1f; _pickerRenderer = this.SceneObject.AddComponent <MeshRenderable>(); _pickerRenderer.Mesh = Icosahedron.Create(0.02f, 1); _pickerRenderer.IsEnabled = false; _pickerRenderer.Material = new Material(MaterialType.FlatColor); _pickerRenderer.Material.Color = new Vector4(1, 1, 0, 1); _pickerRenderer.IsRaytracable = false; _selector = SceneObject.GetComponent <ObjectSelector>(); if (_selector != null) { _selector.Selected += ObjectSelected; } }
public override void OnValidate() { base.OnValidate(); var mb = IsSimple ? Icosahedron.CreateSimple() : Icosahedron.Create(); for (int i = 0; i < Subdivisions; i++) { mb.Subdivide(Steps); } if (IsSphere) { mb.Sphere(0.5f); } meshFilter.sharedMesh = mb.ToMesh(); meshFilter.sharedMesh.RecalculateNormals(); }
private void AddDeferredTest() { var planeSo = new Node(_scene, "plane"); planeSo.AddComponent <MeshRenderable>().Mesh = Plane.Create(10, 10); planeSo.Transform.LocalRotation = new Quaternion(Vector3.Left, MathF.PI / 2); var sphereMesh = Icosahedron.Create(0.01f, 2); var sphereMaterial = new Material(MaterialType.FlatColor); sphereMaterial.Color = Vector4.One; var lightsParent = new Node(_scene, "lights"); lightsParent.AddComponent <Rotator>().Rotation = new Vector3(0.7, 0, 0); var lightCount = 50; for (int i = 0; i < lightCount; i++) { var so = new Node(_scene); so.Transform.Parent = lightsParent.Transform; var light = so.AddComponent <LightSource>(); var color = new Vector3(RandomF.Float(), RandomF.Float(), RandomF.Float()); color /= MathF.Max(color.X, color.Y, color.Z); light.Diffuse = color; light.Attenuation = new Vector3(0, 4f, 0); var position = Vector3.Zero; while (position.LengthSquared < 0.05f) { position = RandomF.InsideUnitSphere(); } so.Transform.LocalPosition = position * 5; var meshRenderer = so.AddComponent <MeshRenderable>(); meshRenderer.Mesh = sphereMesh; meshRenderer.Material = sphereMaterial; } }
private void AddLights() { var material = new Material(MaterialType.FlatColor); material.Color = new Vector4(1, 1, 1, 1); var mesh = Icosahedron.Create(0.02f, 1); var light = new Node(Scene, "light0"); light.Transform.LocalPosition = new Vector3(0, 1.5f, 0); light.AddComponent <LightSource>(); var renderer = light.AddComponent <MeshRenderable>(); renderer.Mesh = mesh; renderer.Material = material; light = new Node(Scene, "light1"); light.Transform.LocalPosition = new Vector3(0, -1.5f, 0); light.AddComponent <LightSource>(); renderer = light.AddComponent <MeshRenderable>(); renderer.Mesh = mesh; renderer.Material = material; }
protected override void OnStart() { _control = Scene.Control; _control.MouseDown += Control_MouseDown; var material = new Material(MaterialType.FlatColor); material.Color = new Vector4(1, 1, 0, 1); _renderer = SceneObject.AddComponent <MeshRenderable>(); _renderer.Material = material; _renderer.IsEnabled = false; var mesh = new Mesh(); var buffer3 = new Vector3Buffer(2); buffer3.Usage = BufferUsage.DynamicDraw; mesh.Vertices = buffer3; mesh.Type = PrimitiveType.Lines; _renderer.Mesh = mesh; var hitPointSo = new Node(Scene); var sphere = Icosahedron.Create(0.01f, 1); _hitPointRenderer = hitPointSo.AddComponent <MeshRenderable>(); _hitPointRenderer.IsEnabled = false; _hitPointRenderer.Mesh = sphere; _hitPointRenderer.SceneObject.Layer = 2; _hitPointRenderer.Material = material; _hitPointTransform = hitPointSo.Transform; _selectedMaterial = new Material(MaterialType.DiffuseColor); _selectedMaterial.Color = new Vector4(1, 0, 0, 1); }