首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用babylonjs显示图像

使用babylonjs显示图像
EN

Stack Overflow用户
提问于 2014-12-05 19:33:35
回答 1查看 2.8K关注 0票数 4

我是Babylonjs的新手,我想使用BabylonJs显示/显示图像,我还想使用带有碰撞检测的键盘(如左箭头键、右箭头键、上箭头键和下箭头键)移动图像,我还想禁用所有鼠标事件。

我已经写了下面的代码来显示图像,但我认为这不是正确的方式。

代码语言:javascript
复制
  var playerMaterial = new BABYLON.StandardMaterial("ground", scene);
    playerMaterial.diffuseTexture = new BABYLON.Texture("/images/mail.png", scene);
    playerMaterial.specularColor = new BABYLON.Color3(0, 0, 0);
    player.material = playerMaterial;
    player.position.y = 1;
    player.position.x = -84;
    player.size = 20;

有没有人能教我怎么做(如果你能分享源代码,可能会更有帮助)?

谢谢

拉维兰扬

EN

回答 1

Stack Overflow用户

发布于 2015-04-08 01:33:22

假设您还有一个相机和光源,那么您的代码看起来基本上是正确的。这是a playground entry

对于后人来说,代码是这样的:

代码语言:javascript
复制
var scene = new BABYLON.Scene(engine);

//Create a light
var light = new BABYLON.PointLight("Omni", new BABYLON.Vector3(-60, 60, 80), scene);

//Create an Arc Rotate Camera - aimed negative z this time
var camera = new BABYLON.ArcRotateCamera("Camera", Math.PI / 2, 1.0, 210, BABYLON.Vector3.Zero(), scene);
camera.attachControl(canvas, true);

//Creation of a repeated textured material
var materialPlane = new BABYLON.StandardMaterial("texturePlane", scene);
materialPlane.diffuseTexture = new BABYLON.Texture("textures/grass.jpg", scene);
materialPlane.specularColor = new BABYLON.Color3(0, 0, 0);
materialPlane.backFaceCulling = false;//Allways show the front and the back of an element

//Creation of a plane
var plane = BABYLON.Mesh.CreatePlane("plane", 120, scene);
plane.rotation.x = Math.PI / 2;
plane.material = materialPlane;

我从他们的一个演示开始,然后删掉了大部分东西,得到了最小的示例。我留在backFaceCulling = false中(否则图像只能从一个方向可见),并添加到您的specularColor设置中。

另一种方法是用emissiveTexture替换diffuseTexture

代码语言:javascript
复制
materialPlane.emissiveTexture = new BABYLON.Texture("textures/grass.jpg", scene);

然后,您可以注释掉灯光,但它仍然可见。(事实上,如果让灯光指向它,它将被过度曝光。)

(我建议您针对键盘控制和碰撞检测问题开始一个新问题。或者学习巴比伦示例和教程视频。)

票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/27315008

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档