babylonjs|动态字幕纹理

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;

};

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值