-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c75a544
commit d6e2d38
Showing
2 changed files
with
70 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<title>Behavior Tests</title> | ||
<meta charset="utf-8"> | ||
<script src="https://cdn.rawgit.com/mrdoob/three.js/r74/build/three.min.js"></script> | ||
<script src="https://cdn.rawgit.com/mrdoob/three.js/r74/examples/js/controls/OrbitControls.js"></script> | ||
<script src="../../dist/altspace.js"></script> | ||
</head> | ||
<body> | ||
<select id="behaviorSelector"> | ||
<option>none</option> | ||
<option data-config='{"x": 0.1, "y": 0.2}'>Bob</option> | ||
<option>Spin</option> | ||
<option data-config='{"x": true, "z": true}'>Drag</option> | ||
<option>ButtonStateStyle</option> | ||
<option>HoverColor</option> | ||
<option>HoverScale</option> | ||
</select> | ||
<script> | ||
var sim = new altspace.utilities.Simulation(); | ||
sim.scene.scale.multiplyScalar(200); | ||
|
||
var container = new THREE.Group(); | ||
container.scale.multiplyScalar(0.5); | ||
container.rotation.x = Math.PI * 0.25; | ||
container.position.y = -1; | ||
|
||
var boxSize = 1; | ||
|
||
var boxTex = new THREE.TextureLoader().load('../images/UV_Grid_Sm.jpg'); | ||
var boxMesh = new THREE.Mesh( | ||
new THREE.BoxGeometry(boxSize, boxSize, boxSize), | ||
new THREE.MeshBasicMaterial({color: 'green', map: boxTex})); | ||
boxMesh.position.set(0.5, -0.3, 0.5); | ||
container.add(boxMesh); | ||
|
||
sim.scene.add(container); | ||
|
||
var behaviorSelector = document.getElementById('behaviorSelector') | ||
|
||
var behaviorConfigs = Array.from(behaviorSelector.options).reduce(function (configs, opt) { | ||
if (opt.dataset.config) { | ||
configs[opt.value] = JSON.parse(opt.dataset.config); | ||
} | ||
return configs; | ||
}, {}); | ||
|
||
behaviorSelector.addEventListener('change', function () { | ||
var behaviorName = this.value; | ||
if (behaviorName === 'none') { return; } | ||
boxMesh.removeAllBehaviors(); | ||
var behavior = altspace.utilities.behaviors[behaviorName]; | ||
var config = behaviorConfigs[behaviorName]; | ||
boxMesh.addBehavior(new behavior(config)); | ||
}); | ||
|
||
if (location.search) { | ||
var behaviorName = location.search.substr(1); | ||
var behavior = altspace.utilities.behaviors[behaviorName]; | ||
var config = behaviorConfigs[behaviorName]; | ||
boxMesh.addBehavior(new behavior(config)); | ||
behaviorSelector.selectedIndex = Array.from(behaviorSelector.options). | ||
map(function (opt) { return opt.value; }).indexOf(behaviorName); | ||
} | ||
</script> | ||
</body> | ||
</html> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters