/// <summary> /// /// </summary> /// <param name="control"></param> public override void Load(Control control) { base.Load(control); // camera = new PerspectiveCamera(27, control.Width / (float)control.Height, 1, 4000); this.camera.Position.Z = 2750; scene = new Scene(); const int segments = 10000; var geometry = new BufferGeometry(); var material = new LineBasicMaterial { VertexColors = 2 }; var positions = new float[segments * 3]; var colors = new float[segments * 3]; const float r = 800.0f; for (var i = 0; i < segments; i++) { var x = Mat.Random() * r - r / 2; var y = Mat.Random() * r - r / 2; var z = Mat.Random() * r - r / 2; // positions positions[i * 3 + 0] = x; positions[i * 3 + 1] = y; positions[i * 3 + 2] = z; // colors colors[i * 3 + 0] = (x / r) + 0.5f; colors[i * 3 + 1] = (y / r) + 0.5f; colors[i * 3 + 2] = (z / r) + 0.5f; } geometry.AddAttribute("position", new BufferAttribute <float>(positions, 3)); geometry.AddAttribute("color", new BufferAttribute <float>(colors, 3)); geometry.ComputeBoundingSphere(); mesh = new Line(geometry, material); scene.Add(mesh); renderer.gammaInput = true; renderer.gammaOutput = true; }
/// <summary> /// /// </summary> /// <param name="control"></param> public override void Load(Control control) { base.Load(control); camera = new PerspectiveCamera(27, control.Width / (float)control.Height, 5, 3500); this.camera.Position.Z = 2750; scene = new Scene(); scene.Fog = new Fog((Color)colorConvertor.ConvertFromString("#050505"), 2000, 3500); // const int Particles = 500000; var positions = new float[Particles * 3]; var colors = new float[Particles * 3]; var n = 1000; var n2 = n / 2; // particles spread in the cube for (var i = 0; i < positions.Length; i += 3) { // positions var x = Mat.Random() * n - n2; var y = Mat.Random() * n - n2; var z = Mat.Random() * n - n2; positions[i + 0] = x; positions[i + 1] = y; positions[i + 2] = z; // colors var vx = (x / n) + 0.5f; var vy = (y / n) + 0.5f; var vz = (z / n) + 0.5f; colors[i + 0] = vx; colors[i + 1] = vy; colors[i + 2] = vz; } var geometry = new BufferGeometry(); geometry.AddAttribute("position", new BufferAttribute <float>(positions, 3)); geometry.AddAttribute("color", new BufferAttribute <float>(colors, 3)); geometry.ComputeBoundingSphere(); // var material = new PointCloudMaterial() { Size = 15, VertexColors = Three.VertexColors }; particleSystem = new PointCloud(geometry, material); scene.Add(particleSystem); // renderer.SetClearColor(scene.Fog.Color); }
/// <summary> /// /// </summary> /// <param name="control"></param> public override void Load(Control control) { base.Load(control); // camera = new PerspectiveCamera(50, control.Width / (float)control.Height, 1, 4000); // new OrthographicCamera(-control.Width/20, control.Width / 20, -control.Height / 20, control.Height / 20);// this.camera.Position.Z = 50; camera.LookAt(new Vector3(0, 0, 0)); controls = new CamControl(control, camera); controls.RotateSpeed = 5; controls.ZoomSpeed = 5; controls.PanSpeed = 2; controls.StaticMoving = true; controls.DynamicDampingFactor = 0.4f; scene = new Scene(); scene.Add(camera); var material = new LineBasicMaterial { VertexColors = ThreeCs.Three.VertexColors }; if (dataList != null) { foreach (var data in dataList) { int segments = data.Count; var geometry = new BufferGeometry(); var positions = new float[segments * 3]; var colors = new float[segments * 3]; for (int i = 0; i < segments; i++) { positions[i * 3 + 0] = data[i].X; positions[i * 3 + 1] = data[i].Y; positions[i * 3 + 2] = data[i].Z * 5; colors[i * 3 + 0] = 0.5f; colors[i * 3 + 1] = 0.5f; colors[i * 3 + 2] = 0.5f; } geometry.AddAttribute("position", new BufferAttribute <float>(positions, 3)); geometry.AddAttribute("color", new BufferAttribute <float>(colors, 3)); geometry.ComputeBoundingSphere(); mesh = new Line(geometry, material); scene.Add(mesh); } } renderer.gammaInput = true; renderer.gammaOutput = true; }
/// <summary> /// /// </summary> /// <param name="control"></param> public override void Load(Control control) { base.Load(control); camera = new PerspectiveCamera(27, control.Width / (float)control.Height, 1, 3500); this.camera.Position.Z = 2750; scene = new Scene(); scene.Fog = new Fog((Color)colorConvertor.ConvertFromString("#050505"), 2000, 3500); scene.Add(new AmbientLight((Color)colorConvertor.ConvertFromString("#444444"))); var light1 = new DirectionalLight(Color.White, 0.5f); light1.Position = new Vector3(1, 1, 1); scene.Add(light1); var light2 = new DirectionalLight(Color.White, 1.5f); light2.Position = new Vector3(0, -1, 0); scene.Add(light2); const int triangles = 160000; var geometry = new BufferGeometry(); var indices = new uint[triangles * 3]; for (uint i = 0; i < indices.Length; i++) { indices[i] = i; } var positions = new float[triangles * 3 * 3]; var normals = new float[triangles * 3 * 3]; var colors = new float[triangles * 3 * 3]; var color = Color.White; const int n = 800; var n2 = n / 2; // triangles spread in the cube const int d = 12; var d2 = d / 2; // individual triangle size for (var i = 0; i < positions.Length; i += 9) { // positions var x = Mat.Random() * n - n2; var y = Mat.Random() * n - n2; var z = Mat.Random() * n - n2; var ax = x + Mat.Random() * d - d2; var ay = y + Mat.Random() * d - d2; var az = z + Mat.Random() * d - d2; var bx = x + Mat.Random() * d - d2; var by = y + Mat.Random() * d - d2; var bz = z + Mat.Random() * d - d2; var cx = x + Mat.Random() * d - d2; var cy = y + Mat.Random() * d - d2; var cz = z + Mat.Random() * d - d2; positions[i + 0] = ax; positions[i + 1] = ay; positions[i + 2] = az; positions[i + 3] = bx; positions[i + 4] = by; positions[i + 5] = bz; positions[i + 6] = cx; positions[i + 7] = cy; positions[i + 8] = cz; // flat face normals var pA = new Vector3(ax, ay, az); var pB = new Vector3(bx, by, bz); var pC = new Vector3(cx, cy, cz); var cb = new Vector3().SubtractVectors(pC, pB); var ab = new Vector3().SubtractVectors(pA, pB); cb.Cross(ab).Normalize(); var nx = cb.X; var ny = cb.Y; var nz = cb.Z; normals[i + 0] = nx; normals[i + 1] = ny; normals[i + 2] = nz; normals[i + 3] = nx; normals[i + 4] = ny; normals[i + 5] = nz; normals[i + 6] = nx; normals[i + 7] = ny; normals[i + 8] = nz; // colors var vx = (x / n) + 0.5; var vy = (y / n) + 0.5; var vz = (z / n) + 0.5; color = Color.FromArgb(255, (int)(vx * 255), (int)(vy * 255), (int)(vz * 255)); colors[i + 0] = color.R / 255.0f; colors[i + 1] = color.G / 255.0f; colors[i + 2] = color.B / 255.0f; colors[i + 3] = color.R / 255.0f; colors[i + 4] = color.G / 255.0f; colors[i + 5] = color.B / 255.0f; colors[i + 6] = color.R / 255.0f; colors[i + 7] = color.G / 255.0f; colors[i + 8] = color.B / 255.0f; } geometry.AddAttribute("index", new BufferAttribute <uint>(indices, 1)); geometry.AddAttribute("position", new BufferAttribute <float>(positions, 3)); geometry.AddAttribute("normal", new BufferAttribute <float>(normals, 3)); geometry.AddAttribute("color", new BufferAttribute <float>(colors, 3)); geometry.ComputeBoundingSphere(); var material = new MeshPhongMaterial { Color = (Color)colorConvertor.ConvertFromString("#aaaaaa"), Ambient = (Color)colorConvertor.ConvertFromString("#aaaaaa"), Specular = (Color)colorConvertor.ConvertFromString("#ffffff"), Shininess = 250, Side = Three.DoubleSide, VertexColors = Three.VertexColors, }; this.mesh = new Mesh(geometry, material); scene.Add(mesh); renderer.SetClearColor(scene.Fog.Color); renderer.gammaInput = true; renderer.gammaOutput = true; }
/// <summary> /// /// </summary> /// <param name="control"></param> public override void Load(Control control) { base.Load(control); camera = new PerspectiveCamera(27, control.Width / (float)control.Height, 1, 3500); camera.Position.Z = 2750; scene = new Scene(); scene.Fog = new Fog((Color)colorConvertor.ConvertFromString("#050505"), 2000, 3500); scene.Add(new AmbientLight((Color)colorConvertor.ConvertFromString("#444444"))); var light1 = new DirectionalLight(Color.White, 0.5f); light1.Position = new Vector3(1, 1, 1); scene.Add(light1); var light2 = new DirectionalLight(Color.White, 1.5f); light2.Position = new Vector3(0, -1, 0); scene.Add(light2); // const int Triangles = 5000; var geometry = new BufferGeometry(); var positions = new float[Triangles * 3 * 3]; var normals = new float[Triangles * 3 * 3]; var colors = new float[Triangles * 3 * 3]; var color = new Color(); const int n = 800; const int n2 = n / 2; // triangles spread in the cube const int d = 120; const int d2 = d / 2; // individual triangle size for (var i = 0; i < positions.Length; i += 9) { // positions var r = 0.5f; var x = getRandom() * n - n2; var y = getRandom() * n - n2; var z = getRandom() * n - n2; var ax = x + getRandom() * d - d2; var ay = y + getRandom() * d - d2; var az = z + getRandom() * d - d2; var bx = x + getRandom() * d - d2; var by = y + getRandom() * d - d2; var bz = z + getRandom() * d - d2; var cx = x + getRandom() * d - d2; var cy = y + getRandom() * d - d2; var cz = z + getRandom() * d - d2; positions[i] = ax; positions[i + 1] = ay; positions[i + 2] = az; positions[i + 3] = bx; positions[i + 4] = by; positions[i + 5] = bz; positions[i + 6] = cx; positions[i + 7] = cy; positions[i + 8] = cz; // flat face normals var pA = new Vector3(ax, ay, az); var pB = new Vector3(bx, by, bz); var pC = new Vector3(cx, cy, cz); var cb = pC - pB; var ab = pA - pB; cb.Cross(ab).Normalize(); var nx = cb.X; var ny = cb.Y; var nz = cb.Z; normals[i] = nx; normals[i + 1] = ny; normals[i + 2] = nz; normals[i + 3] = nx; normals[i + 4] = ny; normals[i + 5] = nz; normals[i + 6] = nx; normals[i + 7] = ny; normals[i + 8] = nz; // colors var vx = (x / n) + 0.5; var vy = (y / n) + 0.5; var vz = (z / n) + 0.5; color = Color.FromArgb(255, (int)(vx * 255), (int)(vy * 255), (int)(vz * 255)); colors[i] = color.R / 255.0f; colors[i + 1] = color.G / 255.0f; colors[i + 2] = color.B / 255.0f; colors[i + 3] = color.R / 255.0f; colors[i + 4] = color.G / 255.0f; colors[i + 5] = color.B / 255.0f; colors[i + 6] = color.R / 255.0f; colors[i + 7] = color.G / 255.0f; colors[i + 8] = color.B / 255.0f; } geometry.AddAttribute("position", new BufferAttribute <float>(positions, 3)); geometry.AddAttribute("normal", new BufferAttribute <float>(normals, 3)); geometry.AddAttribute("color", new BufferAttribute <float>(colors, 3)); geometry.ComputeBoundingSphere(); var material = new MeshPhongMaterial() { Color = (Color)colorConvertor.ConvertFromString("#aaaaaa"), Ambient = (Color)colorConvertor.ConvertFromString("#aaaaaa"), Specular = Color.White, Shininess = 250, Side = Three.DoubleSide, VertexColors = Three.VertexColors, }; mesh = new Mesh(geometry, material); scene.Add(mesh); // projector = new Projector(); raycaster = new Raycaster(); mouse = new Vector2(); var geometry2 = new BufferGeometry(); geometry2.AddAttribute("position", new BufferAttribute <float>(new float[4 * 3], 3)); var material2 = new LineBasicMaterial() { Color = Color.White, Linewidth = 2, Transparent = true }; line = new Line(geometry2, material2); scene.Add(line); renderer.SetClearColor(scene.Fog.Color); }