var createScene = function () {
var scene = new BABYLON.Scene(engine);
var camera = new BABYLON.ArcRotateCamera("Camera", 3 * Math.PI / 2, Math.PI / 8, 250, BABYLON.Vector3.Zero(), scene);
camera.attachControl(canvas, true);
var light = new BABYLON.HemisphericLight("light1", new BABYLON.Vector3(0, 1, 0), scene);
// Default intensity is 1. Let's dim the light a small amount
light.intensity = 0.7;
var baseObj = new BABYLON.TransformNode();
var txtTiles = [];
var box=[
new BABYLON.Vector3(0,0.5,0),
new BABYLON.Vector3(1.4,0.5,0),
new BABYLON.Vector3(1.4,0.5,1.4),
new BABYLON.Vector3(0,0.5,1.4),
];
// var box = BABYLON.MeshBuilder.ExtrudePolygon("box",{shape:box, depth: 0.2,sideOrientation: BABYLON.Mesh.DOUBLESIDE,updatable:true}, scene);
// box.position=new BABYLON.Vector3(0,1,-5)
// box.scaling = new BABYLON.Vector3(3, 1, 3);
// box.isPickable=false;
// box.rotation = new BABYLON.Vector3(0, Math.PI*3/4,0);
function createTxtTiles(){
var txtTilePositions = [
{x:18,z:18}
// ,{x:-18,z:18},{x:18,z:-18},{x:-18,z:-18}, //deca
// {x:48,z:48},{x:-48,z:48},{x:48,z:-48},{x:-48,z:-48}
];
var txtTile;
for (var i=0;i<txtTilePositions.length;i++) {
txtTile = BABYLON.MeshBuilder.CreateBox("txtTile"+i, {width:32,height:1,depth:32}, scene);
// txtTile=BABYLON.MeshBuilder.ExtrudePolygon("box",{shape:box, depth: 0.2,sideOrientation: BABYLON.Mesh.DOUBLESIDE,updatable:true}, scene);
txtTile.parent = baseObj;
//Create dynamic texture
var textureResolution = 512;
var textureGround = new BABYLON.DynamicTexture("dynamic texture", {width:512, height:256}, scene);
var textureContext = textureGround.getContext();
var materialGround = new BABYLON.StandardMaterial("Mat", scene);
materialGround.diffuseTexture = textureGround;
// ground.material = materialGround;
txtTile.material = materialGround;
//Add text to dynamic texture
var font = "124px fantasy";
textureGround.drawText('正方形', 100, 175, font, "steelblue", "white", true, true);
txtTile.position.y = 1;
txtTile.position.x = txtTilePositions[i].x;
txtTile.position.z = txtTilePositions[i].z;
txtTile.rotation.y = Math.PI/2;
console.log('f: '+txtTile.position)
txtTiles.push(txtTile)
}
}
createTxtTiles()
scene.beforeRender = function(){
// txtTiles[0].material.diffuseTexture.wAng = -camera.alpha - Math.PI/2;
for (tile in txtTiles) {
txtTiles[tile].material.diffuseTexture.wAng = -camera.alpha - Math.PI/2;
}
}
return scene;
};