Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Branch/terrain #164

Open
wants to merge 3 commits into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 75 additions & 0 deletions public/adl/terrain/index.vwf.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
# Copyright 2012 United States Government, as represented by the Secretary of Defense, Under
# Secretary of Defense (Personnel & Readiness).
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
# in compliance with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software distributed under the License
# is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
# or implied. See the License for the specific language governing permissions and limitations under
# the License.

---
extends: http://vwf.example.com/scene.vwf
properties:
navmode: none
rotationSpeed: 10
translationSpeed: .001
methods:
initializeCamera:
children:
duck:
extends: http://vwf.example.com/terrain.vwf
# # 2: Uncomment to apply the spin-on-click behavior
# # ... located in public/types/spin-on-click.vwf.yaml
properties:
DisplayName: "terrain1"
terrainType: "heightmapTerrainAlgorithm"
type: "Terrain"
url: "./terrain/11743-hm.jpg"
Extents: 2048
minTileSize: 16
tileRes: 16
maxTileSize: 8192
terrainParams:
DisplayName: "terrain1"
addNoise: true
bUrl: "./terrain/snow.jpg"
baseUrl: "./terrain/dirt.JPG"
cubic: true
gUrl: "./terrain/ground.jpg"
mixUrl: "./terrain/mixmap.png"
rUrl: "./terrain/cliff.jpg"
terrainType: "heightmapTerrainAlgorithm"
texture: "checker.jpg"
type: "Terrain"
url: "./terrain/11743-hm.jpg"
worldLength: 2000
worldWidth: 2000
diffuseUrl: "./terrain/deathvallydiffuse.jpeg"
heightScale: 1
point2:
extends: http://vwf.example.com/light.vwf
properties:
lightType: "directional"
enable: true
distance: 2000
intensity: 2
color: [ 155, 155, 128 ]
translation: [ 400, 400, 190 ]
scripts:
- |
this.initialize = function()
{
this.camera.translation = [0,0,150]
this.camera.translationSpeed = .3;
this.ambientColor = [75,75,75];
this.translationSpeed = .001;
this.camera.far = 5000;
this.camera.near = 1;
this.camera.FOV = 70;
this.backgroundColor = [200,200,255]
}

Binary file added public/adl/terrain/terrain/11743-hm.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/adl/terrain/terrain/3091-normal.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/adl/terrain/terrain/4979-normal.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/adl/terrain/terrain/Cliff.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/adl/terrain/terrain/bestnoise.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/adl/terrain/terrain/deathvallydiffuse.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/adl/terrain/terrain/dirt.JPG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/adl/terrain/terrain/grassnorm.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/adl/terrain/terrain/ground.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/adl/terrain/terrain/mixmap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/adl/terrain/terrain/snow 1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/adl/terrain/terrain/snow.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/adl/terrain/terrain/stone 1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/adl/terrain/textures/waternormal.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
74 changes: 71 additions & 3 deletions support/client/lib/vwf/model/threejs.js
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,21 @@ define( [ "module", "vwf/model", "vwf/utility", "vwf/utility/color", "jquery" ],
node.threeObject = new THREE.MeshPhongMaterial();
SetMaterial( parentNode.threeObject, node.threeObject, childName );
}
} else if ( protos && isTerrainDefinition.call( this, protos ) ) {

node = this.state.nodes[childID] = {
name: childName,
threeObject: null,
ID: childID,
parentID: nodeID,
type: childExtendsID,
sourceType: childType,
};

if(!node.threeObject)
{
CreateTerrain.call(this,nodeID,childID,childName);
}
} else if ( protos && isParticleDefinition.call( this, protos ) ) {

node = this.state.nodes[childID] = {
Expand Down Expand Up @@ -405,6 +420,11 @@ define( [ "module", "vwf/model", "vwf/utility", "vwf/utility/color", "jquery" ],
if ( myNode && !( myNode.threeObject instanceof THREE.Material ) ) {
generateNodeMaterial.call( this, childID, myNode );//Potential node, need to do node things!
}

if ( myNode && myNode.terrain) {

myNode.terrain.initializingNode();
}
},

// -- deletingNode -------------------------------------------------------------------------
Expand All @@ -415,6 +435,11 @@ define( [ "module", "vwf/model", "vwf/utility", "vwf/utility/color", "jquery" ],
this.logger.infox( "deletingNode", nodeID );
}

if ( myNode && myNode.terrain) {
debugger;
myNode.terrain.deletingNode();
}

if(nodeID)
{
var childNode = this.state.nodes[nodeID];
Expand Down Expand Up @@ -552,10 +577,16 @@ define( [ "module", "vwf/model", "vwf/utility", "vwf/utility/color", "jquery" ],

//There is not three object for this node, so there is nothing this driver can do. return
if(!threeObject) return value;

if ( propertyValue !== undefined )
{
self = this;
if ( node && node.terrain) {

node.terrain.settingProperty(propertyName, propertyValue );
}


if ( threeObject instanceof THREE.Object3D )
{
// Function to make the object continuously look at a position or node
Expand Down Expand Up @@ -1492,6 +1523,11 @@ define( [ "module", "vwf/model", "vwf/utility", "vwf/utility/color", "jquery" ],
//There is not three object for this node, so there is nothing this driver can do. return
if(!threeObject) return value;

if ( node && node.terrain) {
debugger;
return node.terrain.gettingProperty(propertyName);
}

if(threeObject instanceof THREE.Object3D)
{
if(propertyName == 'transform' && node.transform)
Expand Down Expand Up @@ -2011,8 +2047,16 @@ define( [ "module", "vwf/model", "vwf/utility", "vwf/utility/color", "jquery" ],

return foundSystem;
}


function isTerrainDefinition( prototypes ) {
var foundTerrain = false;
if ( prototypes ) {
for ( var i = 0; i < prototypes.length && !foundTerrain; i++ ) {
foundTerrain = ( prototypes[i] == "http-vwf-example-com-terrain-vwf" );
}
}

return foundTerrain;
}
function isNodeDefinition( prototypes ) {
var foundNode = false;
if ( prototypes ) {
Expand Down Expand Up @@ -3060,6 +3104,30 @@ define( [ "module", "vwf/model", "vwf/utility", "vwf/utility/color", "jquery" ],
return vwfColor;
}

function loadScript (url)
{

var xhr = $.ajax(url,{async:false});
return eval(xhr.responseText);

}

function CreateTerrain(nodeID, childID, childName )
{
var child = this.state.nodes[childID];
if ( child )
{
var factory = loadScript( "vwf/model/threejs/terrain/terrain.js");
var terrain = new factory(childID, null, childName);
child.terrain = terrain;
child.threeObject = terrain.getRoot();
child.threeObject.vwfID = childID;
}

child.threeObject.name = childName;
child.name = childName;
addThreeChild.call( this, nodeID, childID );
}
function CreateParticleSystem(nodeID, childID, childName )
{

Expand Down
127 changes: 127 additions & 0 deletions support/client/lib/vwf/model/threejs/terrain/NoiseTerrainAlgorithm.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
function NoiseTerrainAlgorithm()
{


this.init = function(data)
{

console.log(data);
this.importScript('terrain/simplexNoise.js');
this.importScript('terrain/Rc4Random.js');
}
//This can generate data on the main thread, and it will be passed to the coppies in the thread pool
this.poolInit = function()
{
return 65;
}
//This is the settings data, set both main and pool side
this.setAlgorithmData = function(seed)
{
this.SimplexNoise = new SimplexNoise((new Rc4Random(seed +"")).random);
}
this.setAlgorithmDataPool = function(seed)
{
this.SimplexNoise = new SimplexNoise((new Rc4Random(seed +"")).random);
}
this.getAlgorithmDataPool = function(seed)
{
return this.seed;
}
this.forceTileRebuildCallback = function()
{
return true;
}
this.getEditorData = function()
{

}
this.getMaterialUniforms = function(mesh,matrix)
{
var uniforms_default = {
grassSampler: { type: "t", value: _SceneManager.getTexture( "terrain/grass.jpg",true ) },
cliffSampler: { type: "t", value: _SceneManager.getTexture( "terrain/cliff.jpg",true ) },
dirtSampler: { type: "t", value: _SceneManager.getTexture( "terrain/dirt.jpg",true ) },
snowSampler: { type: "t", value: _SceneManager.getTexture( "terrain/snow.jpg",true ) }
};

uniforms_default.grassSampler.value.wrapS = uniforms_default.grassSampler.value.wrapT = THREE.RepeatWrapping;
uniforms_default.cliffSampler.value.wrapS = uniforms_default.cliffSampler.value.wrapT = THREE.RepeatWrapping;
uniforms_default.dirtSampler.value.wrapS = uniforms_default.dirtSampler.value.wrapT = THREE.RepeatWrapping;
uniforms_default.snowSampler.value.wrapS = uniforms_default.snowSampler.value.wrapT = THREE.RepeatWrapping;
return uniforms_default;
}
this.getDiffuseFragmentShader = function(mesh,matrix)
{
return (
"uniform sampler2D grassSampler;\n"+
"uniform sampler2D cliffSampler;\n"+
"uniform sampler2D dirtSampler;\n"+
"uniform sampler2D snowSampler;\n"+
"uniform sampler2D noiseSampler;\n"+
"vec4 getMix(vec3 norm)" +
"{"+
"float side = min(1.0,pow(1.0-abs(dot(norm,(viewMatrix * vec4(0.0,0.0,1.0,0.0)).xyz)),3.0) * 10.0);\n"+
"float bottom = 1.0-smoothstep(-20.0,60.0,npos.z);\n"+
"float top = clamp(0.0,1.0,(smoothstep(100.0,140.0,npos.z)));\n"+
"float middle = clamp(0.0,1.0,(1.0 - bottom - top));\n"+
"bottom = clamp(0.0,1.0,mix(bottom,0.0,npos.z/100.0));\n"+
"vec4 mixvec = normalize(vec4(bottom,middle,side* 4.0,top)) ;\n"+
"return mixvec;\n"+
"}"+
"vec4 getTexture(vec3 coords, vec3 norm, vec2 uv)" +
"{"+
//"coords /= 100.0;\n"+
"vec4 noiseMain = texture2D(noiseSampler,(npos.xy/10.0)/2.0);\n"+
"vec4 mixvec = getMix(norm + (noiseMain.rgb - .5)/10.0) ;\n"+
"vec2 c0 = (coords.xy/10.0)/2.0 ;\n"+
"vec2 c1 = (coords.xy/10.0)/2.0 ;\n"+
"c1.y /= .5;\n"+
"vec2 c2 = (coords.xy/10.0)/2.0 ;\n"+
"vec2 c3 = (coords.xy/30.0)/2.0 ;\n"+
"vec2 c0a = (coords.xy/20.0)/2.0 ;\n"+
"vec2 c1a = (coords.xy/100.0)/2.0 ;\n"+
"vec2 c2a = (coords.xy/100.0)/2.0 ;\n"+
"vec2 c3a = (coords.xy/300.0)/2.0 ;\n"+
"vec4 grass =.5*texture2D(grassSampler,c0) + .5*texture2D(grassSampler,c0a);\n"+
"vec4 cliff =.5*texture2D(cliffSampler,c1) + .5*texture2D(cliffSampler,c1a);\n"+
"vec4 dirt = .5*texture2D(dirtSampler,c2) + .5*texture2D(dirtSampler,c2a);\n"+
"vec4 snow = .5*texture2D(snowSampler,c3) + .5*texture2D(snowSampler,c3a);\n"+
"vec4 noise = texture2D(noiseSampler,c0);\n"+

"vec4 grass1 = mix(grass,cliff/4.0,noise.r*noise.r*noise.r);"+
"snow = mix(snow,dirt/4.0,noise.g*noise.r*noise.b);"+

"return mixvec.r * grass1 + mixvec.g * grass1 + (mixvec.b) * cliff/2.0 + mixvec.a * snow;\n"+
"}")
}
this.displace= function(vert)
{
var z = 0;
z = this.SimplexNoise.noise2D((vert.x)/10000,(vert.y)/1000) * 15;
z = z*z;
z += this.SimplexNoise.noise2D((vert.x)/100000,(vert.y)/100000) * 450;
z += this.SimplexNoise.noise2D((vert.x)/10000,(vert.y)/100000) * 250;
z += this.SimplexNoise.noise2D((vert.x)/1000,(vert.y)/100) * 25;
z += this.SimplexNoise.noise2D((vert.x)/1000,(vert.y)/5000) * 50;
z += this.SimplexNoise.noise2D((vert.x)/500,(vert.y)/50) * 10;
z += this.SimplexNoise.noise2D((vert.x)/100,(vert.y)/100) * 5.0;
z += this.SimplexNoise.noise2D((vert.x)/20,(vert.y)/20) * 1.5;
z += this.SimplexNoise.noise2D((vert.x)/5,(vert.y)/5) * .25;

var canynon = this.SimplexNoise.noise2D((vert.x)/2000,(vert.y)/10000) * -50;
if(canynon < -30)
{
canynon += 30;
canynon *= canynon;
}
else
canynon = 0;
z-= canynon;
if(z < 0)
{
z/=5;

}
return z + 30;
}
}
45 changes: 45 additions & 0 deletions support/client/lib/vwf/model/threejs/terrain/Rc4Random.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
function Rc4Random(seed)
{
var keySchedule = [];
var keySchedule_i = 0;
var keySchedule_j = 0;

function init(seed) {
for (var i = 0; i < 256; i++)
keySchedule[i] = i;

var j = 0;
for (var i = 0; i < 256; i++)
{
j = (j + keySchedule[i] + seed.charCodeAt(i % seed.length)) % 256;

var t = keySchedule[i];
keySchedule[i] = keySchedule[j];
keySchedule[j] = t;
}
}
init(seed);

function getRandomByte() {
keySchedule_i = (keySchedule_i + 1) % 256;
keySchedule_j = (keySchedule_j + keySchedule[keySchedule_i]) % 256;

var t = keySchedule[keySchedule_i];
keySchedule[keySchedule_i] = keySchedule[keySchedule_j];
keySchedule[keySchedule_j] = t;

return keySchedule[(keySchedule[keySchedule_i] + keySchedule[keySchedule_j]) % 256];
}

this.getRandomNumber = function() {
var number = 0;
var multiplier = 1;
for (var i = 0; i < 8; i++) {
number += getRandomByte() * multiplier;
multiplier *= 256;
}
return number / 18446744073709551616;
}.bind(this);
this.Random = this.getRandomNumber;
this.random = this.getRandomNumber;
}
Loading