// UNCLASSIFIED

extends base
append base_parms
	- tech = "scene"

append base_help
	:markdown
		Can I get some help here?

append base_body

	script.
		var scene = SceneJS.createScene({
			nodes:[{
				// Mouse-orbited camera, implemented by plugin at
				// http://scenejs.org/api/latest/plugins/node/cameras/orbit.js
				type:"cameras/orbit",
				yaw:30,
				pitch:-30,
				zoom:100,
				zoomSensitivity:10.0,

				nodes:[{
					// Don't need backfaces for this demo
					type:"flags",
					backfaces:false,
					nodes:[

						// Optional physics system configs, implemented by plugin at
						// http://scenejs.org/api/latest/plugins/node/physics/system.js
						{
							type:"physics/system",
							gravity:[0, -9, 0, 0],
							solver:"ACCUMULATED" // Options are "ACCUMULATED" (default) or "FAST", "NORMAL"
						},

						// Ground plane

						// Physics body, implemented by plugin at
						// http://scenejs.org/api/latest/plugins/node/physics/body.js
						{
							type:"physics/body",
							shape:"plane",

							// Points upwards
							dir:[0, 1, 0],
							width:100,
							depth:100,
							height:0,

							// Fixed at origin
							pos:[0, 0, 0],

							// Ground does not move
							velocity:[0, 0, 0],

							// Mass not relevant for unmoving object?
							mass:0.0,

							// The coefficient of restitution (COR) of two colliding objects is a
							// fractional value representing the ratio of speeds after and before
							// an impact, taken along the line of the impact.
							restitution:0.9,

							friction:0.3,

							// Specify that this body is not able to move
							movable:false,

							// Child nodes will be translated and rotated according to
							// the body's behaviour within the physics system

							nodes:[{
								// Blue color for ground plane
								type:"material",
								color:{ r:0.8, g:0.8, b:1.0 },
								nodes:[
									// Grid ground plane geometry, implemented by plugin at
									// http://scenejs.org/api/latest/plugins/node/prims/grid.js
									{
										type:"prims/grid",
										size:{ x:1000, z:1000 },
										xSegments:100,
										zSegments:100
									}
								]}
							]
						},

						// Falling balls

						// A bunch of physics bodies wrapping colored spheres
						{
							type:"node",
							nodes:makeBodies(100)
						}
					]
				}]
			}]
		});

		// Returns a bunch of "prims/sphere" nodes, each wrapped by a spherical "physics/body" node
		function makeBodies(numBodies) {
			var nodes = [];

			for (var i = 0; i < numBodies; i++) {
				nodes.push({
					// Physics body primitive, implemented by plugin at
					// http://scenejs.org/api/latest/plugins/node/physics/body.js
					type:"physics/body",
					shape:"sphere",

					// Sphere radius
					radius:1.0,

					pos:[
						Math.random() * 5 - 2.5,
						Math.random() * 200 + 50,
						Math.random() * 5 - 2.5
					],

					// Body is just passively falling from a height
					velocity:[0, 0, 0],

					//
					mass:1.0,

					// Specify that this body is able to move
					movable:true,

					// The coefficient of restitution (COR) of two colliding objects is a
					// fractional value representing the ratio of speeds after and before
					// an impact, taken along the line of the impact.
					//
					// This body will be bouncy.
					restitution:1.0,

					// Low friction
					friction:0.1,

					// Child node will be translated and rotated according to
					// the body's behaviour within the physics system
					nodes:[{
						type:"material",
						color:{ r:Math.random(), g:Math.random(), b:Math.random() },
						nodes:[
							// Sphere primitive, implemented by plugin at
							// http://scenejs.org/api/latest/plugins/node/prims/sphere.js
							{
								type:"prims/sphere",
								radius:1,
								latitudeBands:16, // A fairly low-rez sphere
								longitudeBands:16
							}
						]
					}]
				});
			}
			return nodes;
		}

		/*
		// Stats
		var stats = new Stats();
		stats.domElement.style.position = 'absolute';
		stats.domElement.style.top = '0px';
		stats.domElement.style.right = '0px';
		stats.domElement.style.zIndex = 100;
		document.body.appendChild( stats.domElement );
		scene.on("tick", function() {
			stats.end();
			stats.begin();
		});
		*/

// UNCLASSIFIED
