private static void Init() { mediaPath = Path.GetFullPath("../../../../../js/r68/examples/"); texturesPath = Path.Combine(mediaPath, "textures"); renderer = new Renderer(); scene = new Scene() { Fog = new FogLinear(Color.Black, 1500,2100) }; camera = new PerspectiveCamera(renderer, 60, 1, 2100) { Position = new Vector3(0, 0, 1500) }; cameraOrtho = new OrthographicCamera(renderer, 1, 10000) { Position = new Vector3(0, 0, 150) }; sceneOrtho = new Scene(); //var amount = 200; //var radius = 500; sceneOrtho.Add(new Mesh(new SphereGeometry(100, 50, 50), new MeshBasicMaterial(renderer) { Diffuse = Color.Red})); var group = new Object3D(); var materialA = new SpriteMaterial(renderer) { DiffuseMap = new Texture(Path.Combine(texturesPath, "sprite0.png")), Diffuse = Color.White, UseFog = true, }; spriteTL = new Sprite(renderer, materialA) { Scale = new Vector3(materialA.DiffuseMap.Resolution.Width,materialA.DiffuseMap.Resolution.Height,1), }; sceneOrtho.Add(spriteTL); spriteTR = new Sprite(renderer, materialA) { Scale = new Vector3(materialA.DiffuseMap.Resolution.Width, materialA.DiffuseMap.Resolution.Height, 1), }; sceneOrtho.Add(spriteTR); spriteBL = new Sprite(renderer, materialA) { Scale = new Vector3(materialA.DiffuseMap.Resolution.Width, materialA.DiffuseMap.Resolution.Height, 1), }; sceneOrtho.Add(spriteBL); spriteBR = new Sprite(renderer, materialA) { Scale = new Vector3(materialA.DiffuseMap.Resolution.Width, materialA.DiffuseMap.Resolution.Height, 1), }; sceneOrtho.Add(spriteBR); spriteC = new Sprite(renderer, materialA) { Scale = new Vector3(materialA.DiffuseMap.Resolution.Width, materialA.DiffuseMap.Resolution.Height, 1), }; sceneOrtho.Add(spriteC); UpdateHUDSprites(); var materialB = new SpriteMaterial(renderer) { DiffuseMap = new Texture(Path.Combine(texturesPath, "sprite1.png")), Diffuse = Color.White, UseFog = true, }; var materialC = new SpriteMaterial(renderer) { DiffuseMap = new Texture(Path.Combine(texturesPath, "sprite2.png")), Diffuse = Color.White, UseFog = true, }; mediaPath = Path.Combine(mediaPath, "../../tests/"); }
static void Main(string[] args) { var mediaPath = Path.GetFullPath("../../../../../js/r68/examples/"); var texturesPath = Path.Combine(mediaPath, "textures"); var renderer = new Renderer(); var scene = new Scene() { //Fog = new FogExp2(Color.Blue, 0.24f) }; var camera = new OrthographicCamera(renderer, -1000, 1000) { Position = new Vector3(0, 0, 2) }; //// create a point light scene.Add(new DirectionalLight(Color.White) { Target = Vector3.UnitX }); var geometry = new BoxGeometry(20, 20, 20); for (var i = 0; i < 2000; i++) { var o = new Mesh(geometry, new MeshLambertMaterial(renderer) { Diffuse = Color.Random() }); o.Position = new Vector3(Mathf.RandomF(-400, 400), Mathf.RandomF(-400, 400), Mathf.RandomF(-400, 400)); o.Rotation = new Euler(Mathf.Tau * Mathf.RandomF(), Mathf.Tau * Mathf.RandomF(), Mathf.Tau * Mathf.RandomF()); o.Scale = new Vector3(Mathf.RandomF(0.5f, 1.5f), Mathf.RandomF(0.5f, 1.5f), Mathf.RandomF(0.5f, 1.5f)); scene.Add(o); } var raycaster = new Raycaster(); Object3D INTERSECTED = null; Color previousColor = Color.White; var radius = 100; var previousTime = 0f; var stopwatch = Stopwatch.StartNew(); while (!renderer.Done) { var now = (float)stopwatch.Elapsed.TotalSeconds; var deltaTime = now - previousTime; previousTime = now; var offset = now / 4; var sin = Mathf.Sin(offset) * radius; var cos = Mathf.Cos(offset) * radius; camera.Position = new Vector3(sin, sin, cos); camera.LookAt(Vector3.Zero); #region FindIntersections var vector = Projector.UnprojectVector(new Vector3(renderer.MousePositionNormalized,-1),camera.projectionMatrix, camera.matrixWorld); var direction = new Vector3(0, 0, -1); direction.TransformDirection(camera.matrixWorld); raycaster.Set(vector, direction); var intersects = raycaster.IntersectObjects(scene.Children); if (intersects != null && intersects.Count > 0) { var first = intersects[0]; if (INTERSECTED != first.Object) { if (INTERSECTED != null) { var basic = INTERSECTED.Material as MeshLambertMaterial; basic.Emissive = previousColor; } var firstMat = first.Object.Material as MeshLambertMaterial; INTERSECTED = first.Object; previousColor = firstMat.Emissive; firstMat.Emissive = Color.Red; } } else { if (INTERSECTED != null) { (INTERSECTED.Material as MeshLambertMaterial).Emissive = previousColor; } INTERSECTED = null; } #endregion renderer.RenderFrame(scene, camera); } }
private static void Init() { camera = new PerspectiveCamera(renderer, 30, 1, 10000 ) { Position = new Vector3(0,0,100) }; cameraRTT = new OrthographicCamera(renderer, -10000, 10000 ) { Position= new Vector3(0,0,100) }; scene = new Scene(); sceneRTT = new Scene(); sceneScreen = new Scene(); var light = new DirectionalLight( Color.White ) { Position = Vector3.UnitZ.Normalized() }; sceneRTT.Add( light ); light = new DirectionalLight(new Color(0xffaaaa)) { Position = Vector3.UnitNegativeZ.Normalized(), Intensity = 1.5f }; sceneRTT.Add( light ); rtTexture = new RenderTarget(renderer.Width, renderer.Height) { MinFilter = TextureMinFilter.Linear, MagFilter = TextureMagFilter.Nearest, Format = Three.Net.Renderers.PixelFormat.RGB }; var vertexShaderSource = @" varying vec2 vUv; void main() { vUv = uv; gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 ); }"; var fragment_shader_screenSource = @" varying vec2 vUv; uniform sampler2D tDiffuse; void main() { gl_FragColor = texture2D( tDiffuse, vUv ); }"; var fragment_shader_pass_1Source = @" varying vec2 vUv; uniform float time; void main() { float r = vUv.x; if( vUv.y < 0.5 ) r = 0.0; float g = vUv.y; if( vUv.x < 0.5 ) g = 0.0; gl_FragColor = vec4( r, g, time, 1.0 ); }"; material = new CustomShaderMaterial(renderer,vertexShaderSource,fragment_shader_pass_1Source, m => { }); var materialScreen = new CustomShaderMaterial(renderer, vertexShaderSource, fragment_shader_screenSource, m => {}) { ShouldDepthWrite = false }; var plane = new PlaneGeometry( renderer.Width, renderer.Height); var quad = new Mesh( plane, material ) { Position = new Vector3(0,0,-100) }; sceneRTT.Add( quad ); var geometry = new TorusGeometry( 100, 25, 15, 30 ); var mat1 = new MeshPhongMaterial(renderer) { Diffuse = new Color(0x555555), Specular = new Color(0xffaa00), Shininess = 5 }; var mat2 = new MeshPhongMaterial(renderer) { Diffuse = new Color(0x550000), Specular = new Color(0xff2200), Shininess = 5 }; zmesh1 = new Mesh( geometry, mat1 ) { Position = new Vector3( 0, 0, 100 ), Scale = new Vector3( 1.5f, 1.5f, 1.5f ) }; sceneRTT.Add( zmesh1 ); zmesh2 = new Mesh( geometry, mat2 ) { Position = new Vector3( 0, 150, 100 ), Scale = new Vector3( 0.75f, 0.75f, 0.75f) }; sceneRTT.Add( zmesh2 ); quad = new Mesh( plane, materialScreen ){ Position = new Vector3(0,0,-100) }; sceneScreen.Add( quad ); var n = 5; var sphereGeometry = new SphereGeometry( 10, 64, 32 ); var material2 = new MeshBasicMaterial(renderer) { Diffuse = Color.White, DiffuseMap = rtTexture }; for( var j = 0; j < n; j ++ ) { for( var i = 0; i < n; i ++ ) { var mesh = new Mesh(sphereGeometry, material2) { Position = new Vector3( ( i - ( n - 1 ) / 2 ) * 20, ( j - ( n - 1 ) / 2 ) * 20, 0), Rotation = new Euler(0,-Mathf.Pi / 2, 0) }; scene.Add( mesh ); } } renderer.ShouldAutoClear = false; }