Skip to content

Commit

Permalink
place trees on top of ground, and only on top of ground
Browse files Browse the repository at this point in the history
  • Loading branch information
capnmidnight committed Feb 22, 2017
1 parent 779c576 commit 19ff15f
Show file tree
Hide file tree
Showing 9 changed files with 90 additions and 60 deletions.
58 changes: 29 additions & 29 deletions demos/forest.html
Expand Up @@ -53,45 +53,45 @@ <h2>Source</h2>
var env = new Primrose.BrowserEnvironment({
font: &quot;../shared_assets/fonts/helvetiker_regular.typeface.json&quot;,
backgroundColor: 0xC9E6EE,
groundTexture: &quot;../shared_assets/images/grass.png&quot;,
groundModel: &quot;Ground.obj&quot;,
useFog: true,
enableShadows: true,
shadowRadius: 3,
fullScreenButtonContainer: &quot;#fullScreenButtonContainer&quot;,
progress: Preloader.thunk
});

var treeReady = Primrose.Graphics.ModelFactory.loadModel(&quot;tree.obj&quot;);
var MF = Primrose.Graphics.ModelFactory,
treeReady = MF.loadModel(&quot;tree.obj&quot;),
waterReady = MF.loadObject(&quot;Water.obj&quot;);

env.addEventListener(&quot;ready&quot;, function() {
treeReady.then(function(treeModel) {
treeModel.template.castShadow = true;
treeModel.template.receiveShadow = true;
for(var i = 0; i &lt; 100; ++i) {
treeModel.clone()
.named(&quot;tree&quot; + i)
.addTo(env.scene)
.at(
Primrose.Random.number(-25, 25),
0,
Primrose.Random.number(-25, 25))
.rot(
0,
Primrose.Random.number(0, Math.PI),
0)
.scl(
1,
Primrose.Random.number(0.7, 1.3),
1);
}
Preloader.hide();
});
Promise.all([
treeReady.then(function(treeFactory) {
treeFactory.template.castShadow = true;
treeFactory.template.receiveShadow = true;
for(var i = 0; i &lt; 100; ++i) {
treeFactory.clone()
.named(&quot;tree&quot; + i)
.addTo(env.scene)
.at(
Primrose.Random.number(-25, 25),
0,
Primrose.Random.number(-25, 25))
.rot(
0,
Primrose.Random.number(0, Math.PI),
0)
.scl(
1,
Primrose.Random.number(0.7, 1.3),
1);
}
}),

env.displays[0].enableMotion = true;
});

env.addEventListener(&quot;motioncontrollerfound&quot;, function(ctrl){
env.displays[0].motionDevice = ctrl;
waterReady.then(function(waterModel) {
waterModel.addTo(env.scene);
})]).then(Preloader.hide);
});
</pre>
</main><!-- end main.pug main block -->
Expand Down
Binary file added demos/forest/Ground.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 13 additions & 0 deletions demos/forest/Ground.mtl
@@ -0,0 +1,13 @@
# Blender MTL File: 'None'
# Material Count: 1

newmtl Ground
Ns 94.117647
Ka 1.000000 1.000000 1.000000
Kd 0.640000 0.640000 0.640000
Ks 0.000000 0.000000 0.000000
Ke 0.000000 0.000000 0.000000
Ni 1.000000
d 1.000000
illum 1
map_Kd GroundMobile.jpg
Binary file added demos/forest/GroundMobile.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed demos/forest/Tree Bake Tex.png
Binary file not shown.
Binary file added demos/forest/Water.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 13 additions & 0 deletions demos/forest/Water.mtl
@@ -0,0 +1,13 @@
# Blender MTL File: 'Assets Ver B.blend'
# Material Count: 1

newmtl Water
Ns 96.078431
Ka 1.000000 1.000000 1.000000
Kd 0.640000 0.640000 0.640000
Ks 0.500000 0.500000 0.500000
Ke 0.000000 0.000000 0.000000
Ni 1.000000
d 1.000000
illum 2
map_Kd Water.jpg
64 changes: 35 additions & 29 deletions demos/forest/app.js
@@ -1,43 +1,49 @@
var env = new Primrose.BrowserEnvironment({
font: "../shared_assets/fonts/helvetiker_regular.typeface.json",
backgroundColor: 0xC9E6EE,
groundTexture: "../shared_assets/images/grass.png",
groundModel: "Ground.obj",
useFog: true,
enableShadows: true,
shadowRadius: 3,
fullScreenButtonContainer: "#fullScreenButtonContainer",
progress: Preloader.thunk
});

var treeReady = Primrose.Graphics.ModelFactory.loadModel("tree.obj");
var MF = Primrose.Graphics.ModelFactory;

env.addEventListener("ready", function() {
treeReady.then(function(treeModel) {
treeModel.template.castShadow = true;
treeModel.template.receiveShadow = true;
for(var i = 0; i < 100; ++i) {
treeModel.clone()
.named("tree" + i)
.addTo(env.scene)
.at(
Primrose.Random.number(-25, 25),
0,
Primrose.Random.number(-25, 25))
.rot(
0,
Primrose.Random.number(0, Math.PI),
0)
.scl(
1,
Primrose.Random.number(0.7, 1.3),
1);
}
Preloader.hide();
});

env.displays[0].enableMotion = true;
});
Promise.all([

MF.loadObject("Water.obj").then(function(waterModel) {
waterModel.addTo(env.scene);
}),

MF.loadModel("tree.obj").then(function(treeFactory) {
treeFactory.template.castShadow = true;
treeFactory.template.receiveShadow = true;
for(var i = 0; i < 100; ++i) {

var tree = treeFactory.clone()
.named("tree" + i)
.addTo(env.scene)
.rot(
0,
Primrose.Random.number(0, Math.PI),
0)
.scl(
1,
Primrose.Random.number(0.7, 1.3),
1);


do {
tree.position.set(
Primrose.Random.number(-25, 25),
0,
Primrose.Random.number(-25, 25));
tree.position.y = env.ground.getHeightAt(tree.position);
} while(tree.position.y === undefined);

env.addEventListener("motioncontrollerfound", function(ctrl){
env.displays[0].motionDevice = ctrl;
}
})]).then(Preloader.hide);
});
2 changes: 0 additions & 2 deletions src/Primrose/Controls/Ground.js
Expand Up @@ -98,7 +98,5 @@ export default class Ground extends Entity {
return 100 - hit.distance;
}
}

return 0;
}
};

0 comments on commit 19ff15f

Please sign in to comment.