(function r(f){/in/(document.readyState)?setTimeout(r,9,f):f()})(function(){
var stage, stats, timer, sprite, light;
var frameRate = 60;
var m,t,cubeMaterials = [];
var el = document.getElementById("three-stage");
var isDown, dragPoint, startAngle, tween;
//ステージ
var stage = new FieldStage(el, 520, 390, {x:21, y:7, z:21}, false);
stage.distance = 1000;
//get material
function getMaterial(texture){
if(stage.useWebgl()){
return new THREE.MeshLambertMaterial({map: texture});
}
return new THREE.MeshBasicMaterial({map: texture});
};
//cycle engine
function update(){
TWEEN.update();
stage.update();
stats.update();
stage.getRenderer().render(stage.getScene(), stage.getCamera());
};
//Cubeの各面のマテリアル
//No.1
m = getMaterial(THREE.ImageUtils.loadTexture(\'images/texture001.png\'));
t = getMaterial(THREE.ImageUtils.loadTexture(\'images/texture001_top.png\'));
cubeMaterials.push([
m, // right
m, // left
t, // top
m, // bottom
m, // back
m // front
]);
//No.2
t = getMaterial(THREE.ImageUtils.loadTexture(\'images/texture002_top.png\'));
cubeMaterials.push([
m, // right
m, // left
t, // top
m, // bottom
m, // back
m // front
]);
//No.3
t = getMaterial(THREE.ImageUtils.loadTexture(\'images/texture003_top.png\'));
cubeMaterials.push([
m, // right
m, // left
t, // top
m, // bottom
m, // back
m // front
]);
//フィールドデータ生成
var mtx = new FieldGenerator(11, 11)
.add("h", [0.5, 0.4, 0.08, 0.02])
.add("t", [0.3, 0.5, 0.2])
.get();
stage.makeWalls(mtx, cubeMaterials);
//ライティング (webgl only)
var defLight = new THREE.AmbientLight(0x333333);
stage.getScene().addLight(defLight);
light = new THREE.PointLight(0xFFFFFF, 3, 250);
light.position.set(0, 150, 0);
stage.getScene().addLight(light);
//mouse events
$(el).mousedown(function(e){
e.preventDefault();
dragPoint = new THREE.Vector2(e.pageX, e.pageY);
startAngle = stage.cameraAngle3.clone();
if(tween) tween.stop();
isDown = true;
});
$(el).mousewheel(function(e, delta){
e.preventDefault();
stage.distance += delta * 100;
stage.distance = Math.max(Math.min(stage.distance, 1800), 400);
});
$(document).mouseup(function(e){
isDown = false;
var xx = stage.cameraAngle3.x + 45;
xx = Math.round(xx/90) * 90 - 45;
var yy = Math.floor(stage.cameraAngle3.y/5) * 5;
yy = Math.min(Math.max(yy, 15), 50);
tween = new TWEEN.Tween(stage.cameraAngle3)
.to({
x: xx,
y: yy,
z: xx
}, 1000)
.easing(TWEEN.Easing.Elastic.EaseOut)
.start();
});
$(document).mousemove(function(e){
if(isDown){
stage.cameraAngle3.x = (dragPoint.x - e.pageX) / 5 + startAngle.x;
stage.cameraAngle3.y = (e.pageY - dragPoint.y) / 10 + startAngle.y;
stage.cameraAngle3.y = Math.min(Math.max(stage.cameraAngle3.y, 10), 55);
stage.cameraAngle3.z = (dragPoint.x - e.pageX) / 5 + startAngle.z;
}
});
//Stats SetUp
stats = new Stats();
stats.domElement.style.position = \'absolute\';
stats.domElement.style.top = \'0px\';
stats.domElement.style.zIndex = 100;
el.appendChild(stats.domElement);
document.getElementById("renderer").innerHTML = stage.useWebgl() ? "WebGLRenderer" : "CanvasRenderer" ;
//cycle engine start
timer = setInterval(update, 1000 / frameRate);
});