javascript - Change background colour, add a pointlight in three.js -
I'm playing with three.js. I have created a cube inside a wireframe cube. How do I change the background color? I know that I have to do something about creating Skybacks and / or a point light source, but it appears to be just making a black screen.
Here is the codename:
My code:
var width = window.innerWidth; Var height = window.white; Var scene, camera, renderer; Var Cube; Var fov = 30, isUserInteracting = false, cameraDistance = 100, onMouseDownMouseX = 0, onMouseDownMouseY = 0, loan = 0, onMouseDownLon = 0, lat = 0, onMouseDownLat = 0, PHI = 0, theta = 0; $ (Function () {init ();}); Function init () {view = new three. Camera = new three. Percy Camera (FOV, window winner width / window winherhit, 1, 1000); Camera.position.set (0, 0, 100); Renderer = New three. Webgil renderer ({antilius: true}); Renderer.setSize (window.innerWidth, window.innerHeight); $ ('# Container'). Append (renderer. Dome element); Cube = new three. Aries (New Three Box Glomptary (23, 33, 18), New Three. Messaging Content ({Color: 0xFF6600, Wireframe: True}); Scene.add (cube); Cube2 = New three. Aries (New Three Box Glometry (10, 10, 10), New Three. Messaging Content ({color: 0xFF6600,}); Scene.add (cube2); Cube = new three. Aries (New Three Box Glomptary (23, 33, 18), New Three. Messaging Content ({Color: 0xFF6600, Wireframe: True}); Scene.add (cube); $ (Document) .on ('mosudown', onmoddown); $ (Document) .on ('mouse wheel', onmos volume); $ (Window) .on ('resize', resize onverts); Chetan (); } Function animate () {requestAnimationFrame (animate); to present(); } Function render () {lon + = .15; Lat = Math.max (- 85, Math.Min (85, latitude)); Phi = THREE.Math.degToRad (90 - latitude); Theta = three Math.Degtoord (loan); Camera.position.x = cameraDistance * Math.sin (phi) * Math Kos (Theta); Camera.position.y = cameraDistance * Math.cos (phi); Camera.position.z = cameraDistance * Math.sin (phi) * MathC (theta); Camera.look.position; Renderer Render (view, camera); } Function onMouseWheel (event) {cameraDistance + = event.originalEvent.deltaY * 0.1; CameraDistance = Math.min (cameraDisthan, camera.fare); CameraDistance = Math.max (CameraDisthan, Camera.Near); } Ceremony onMouseDown (event) {event.preventDefault (); OnPointerDownPointerX = event.clientX; OnPointerDownPointerY = event.clientY; OnPointerDownLon = lon; OnPointerDownLat = lat; $ (Document) .on ('mousemove', onMouseMove); $ (Document) .on ('mouseup', onMouseUp); } Function onMouseMove (event) {lon = (event.clientX - onPointerDownPointerX) * 0.1 + onPointerDownLon; Lat = (event.clientY - onPointerDownPointerY) * 0.1 + on pointerdownlot; } Function onMouseUp (event) {$ (document) .off ('mousemove'); $ (Document) .off ('mouseup'); } Window resize on function () {renderer.setSize (window.internalWidth, window.innerHeight); Camera.projectionMatrix.makePerspective (fov, window.innerWidth / window.innerHeight, 1, 1000); }
Any help is greatly appreciated.
Renderer.setClearColor (0xffffff, 1);
The first argument you should do is background color in RGB, and the second argument is alpha for example:
renderer.setClearColor (0xff0000, .5) );
This should set your rendered background in red, with 50% transparency. I have just started playing with three, so I hope this works for you.
EDIT: Now I have more than a second, I have tried to put it out in your codepan. I put the above line in my init () function immediately after starting your renderer and it worked.
Comments
Post a Comment