Skip to content

Commit

Permalink
Merge pull request #161 from AltspaceVR/feature/fullscreen
Browse files Browse the repository at this point in the history
Test for fullspace API
  • Loading branch information
brianpeiris committed Nov 22, 2016
2 parents c27ea0c + 1763e94 commit a85a1c5
Show file tree
Hide file tree
Showing 3 changed files with 159 additions and 6 deletions.
12 changes: 6 additions & 6 deletions README.md.template
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ THIS FILE IS GENERATED FROM README.md.template. EDIT THAT INSTEAD

## Resources

**[Getting Started] - If you're new to the SDK, start here!**
**[API Reference] - Reference for built in API functions, utilities, and more**
**[Developer Portal] - Tutorials, projects, initiative program, and app submission**
**[Local Dev Setup] - Instructions for setting up a local dev environment**
**[App Guidelines] - Suggestions for building apps that work well in Altspace and Gear VR**
**[Slack] - Chat with other members of the community and AltspaceVR devs. [Register for Slack](http://altspacevr-slackin.herokuapp.com)**
- **[Getting Started] - If you're new to the SDK, start here!**
- **[API Reference] - Reference for built in API functions, utilities, and more**
- **[Developer Portal] - Tutorials, projects, initiative program, and app submission**
- **[Local Dev Setup] - Instructions for setting up a local dev environment**
- **[App Guidelines] - Suggestions for building apps that work well in Altspace and Gear VR**
- **[Slack] - Chat with other members of the community and AltspaceVR devs. [Register for Slack](http://altspacevr-slackin.herokuapp.com)**


## altspace.js
Expand Down
152 changes: 152 additions & 0 deletions examples/tests/fullspace.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
<!DOCTYPE html>
<html lang="en">
<head>
<title>Fullspace</title>
<meta charset="utf-8">
<script src="https://cdn.rawgit.com/mrdoob/three.js/r74/build/three.min.js"></script>
<script src="../../dist/altspace.js"></script>
<style>
html, body { width: 100%; height: 100%; margin: 0; padding: 0; }
body{ display: flex; align-items: center; justify-content: center; }
div { display: none; }
#pixel { display: block; width: 300px; height: 300px; background-color: black; }
</style>
</head>
<body>
<div id="pixel">&nbsp;</div>
<script>
var sim = new altspace.utilities.Simulation(), controls;

var boxSize = 0.5;
var boxGeo = new THREE.BoxGeometry(boxSize, boxSize, boxSize);
var boxMat = new THREE.MeshBasicMaterial({color: 'green'});

function makeBox(x, y, z) {
var boxMesh = new THREE.Mesh(boxGeo, boxMat.clone());
boxMesh.userData.altspace = {collider: {enabled: false}};
boxMesh.position.set(x, y, z);
sim.scene.add(boxMesh);
return boxMesh;
}

function makeMovingBox(x, y, z) {
var boxMesh = makeBox(x, y, z);
boxMesh.addBehavior({
awake: function (obj) {
this.obj = obj;
this.origX = obj.position.x;
this.time = 0;
},
update: function (delta) {
this.time += delta;
this.obj.position.x = this.origX + Math.sin(this.time / 1000) * 3;
}
});
return boxMesh;
}

function makeFlippingBox(x, y, z) {
var boxMesh = makeBox(x, y, z);
boxMesh.addBehavior({
awake: function (obj) {
this.obj = obj;
this.time = 0;
this.flip = true;
},
update: function (delta) {
this.time += delta;
if (this.time > 2000) {
if (this.flip) {
this.obj.position.set(0, 0, 0);
}
else {
this.obj.position.set(x, y, z);
}
this.time = 0;
this.flip = !this.flip;
}
}
});
return boxMesh;
}

function makePulsingSphere() {
var sphere = new THREE.Mesh(
new THREE.SphereGeometry(1, 6, 6),
new THREE.MeshBasicMaterial({color: 'white'})
);
sphere.userData.altspace = {collider: {enabled: false}};
sphere.addBehavior({
awake: function (obj) {
this.obj = obj;
this.time = 0;
this.size = 1;
},
update: function (delta) {
this.time += delta;
var x = Math.max(0.00000001, Math.abs((Math.cos(this.time / 1000) - 1) / 2 * this.size));
this.obj.scale.set(x, x, x);
},
type: 'pulsingSphereBehavior'
});
sim.scene.add(sphere);
return sphere;
}

function adjustToFullspace(enclosure, button, doc) {
var ppm = enclosure.pixelsPerMeter;
sim.scene.scale.set(ppm, ppm, ppm);
doc.scale.set(1/ppm, 1/ppm, 1/ppm);
button.material.color.setStyle(enclosure.fullspace ? 'red' : 'white');
pulsingSphere.getBehaviorByType('pulsingSphereBehavior').size = enclosure.fullspace ? 50 : 4;
}

Promise.all([altspace.getEnclosure(), altspace.getDocument()]).then(function (results) {
var enclosure = results.shift();

var doc = results.shift();
doc.position.set(0, 0, 1.5);
doc.rotateY(Math.PI / 4);
sim.scene.add(doc);

var button = makeBox(0, boxSize * 1.5, 0);
button.userData.altspace.collider.enabled = true;
adjustToFullspace(enclosure, button, doc);
button.addEventListener('cursordown', function () {
if (enclosure.fullspace) {
enclosure.exitFullspace();
}
else {
enclosure.requestFullspace();
}
});
enclosure.addEventListener('fullspacechange', function () {
adjustToFullspace(enclosure, button, doc);
});
});

var spacing = 0.9;
var offset = 2;
var num = 8;
for (var x = 0; x < num; x++) {
for (var y = 0; y < num; y++) {
for (var z = 0; z < num; z++) {
var box = makeMovingBox(
((x / (num - 1)) - 0.5) * num * spacing,
((y / (num - 1)) - 0.5) * num * spacing,
((z / (num - 1)) - 0.5) * num * spacing + offset)
box.material.color.r = x / num;
box.material.color.g = y / num;
box.material.color.b = z / num;
box.userData.altspace.collider.enabled = Math.random() > 0.5;
}
}
}

makeFlippingBox(3, 3, 3);

var pulsingSphere = makePulsingSphere();
</script>
</body>
</html>

1 change: 1 addition & 0 deletions examples/tests/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
'transparency-stress.html',
'canvas-update.html',
'document.html',
'fullspace.html',
'texture-repeat-offset.html',
'texture-batching.html',
'texture-reuse.html',
Expand Down

0 comments on commit a85a1c5

Please sign in to comment.