如何在运行时从Babylon.js中的场景中删除网格?试图搜索,没找到,也试图在调试器中查看场景方法,也找不到.
我想使用Babylon.js加载一个由用户上传的文件.我环顾四周但只能找到加载巴比伦场景文件的例子.
有没有办法直接用Babylon.js加载.obj和/或.stl文件而不必将它们转换为.babylon文件?
谢谢.
在我准备上学的游戏演示中,我需要使用 WASD 键和箭头键移动我的角色。我设置了一个函数并设置了一个开关盒来监听任何按键。这是我的代码片段:
//Handles the player's movement
var PlayerMovement = (function () {
//Constructor
function PlayerMovement() {
this.gameObject = null;
this.movementSpeed = 0;
this.rotationSpeed = 0;
}
PlayerMovement.prototype.awake = function () {
console.log("Awake");
};
PlayerMovement.prototype.update = function () {
//console.log(Tools.getFps());
}
PlayerMovement.prototype.onKeyPressed = function (key) {
switch(key)
{
case KeyType.W:
case KeyType.UpArrow:
console.log("Moving up");
this.gameObject.meshObject.position.z += (BABYLON.Vector3.Up() * this.movementSpeed * Tools.getDeltaTime());
break;
case KeyType.A:
case KeyType.LeftArrow:
//TODO: Do stuff
break;
case KeyType.S:
case KeyType.DownArrow:
//TODO: Do stuff
break;
case KeyType.D: …Run Code Online (Sandbox Code Playgroud) 我正在尝试编写GLSL片段着色器,该着色器在平坦的地平面上呈现参考网格。我正在使用BabylonJS创建一个WebGL应用程序。
可以在此处查看代码:
http://www.babylonjs.com/cyos/#IBHRN#2
#extension GL_OES_standard_derivatives : enable
precision highp float;
varying vec2 vUV;
void main(void) {
float divisions = 10.0;
float thickness = 0.01;
float delta = 0.05 / 2.0;
float x = fract(vUV.x / (1.0 / divisions));
float xdelta = fwidth(x) * 2.5;
x = smoothstep(x - xdelta, x + xdelta, thickness);
float y = fract(vUV.y / (1.0 / divisions));
float ydelta = fwidth(y) * 2.5;
y = smoothstep(y - ydelta, y + ydelta, thickness);
float c = clamp(x …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用 babel 模块,babylon, babel-traverse。当我试图替换一个节点时,程序崩溃了Maximum call stack size exceeded。这是我的代码
import * as babylon from 'babylon'
import traverse from 'babel-traverse'
import generate from 'babel-generator'
import * as t from 'babel-types'
const code = `
import a from 'b'
n === 3
`
const ast = babylon.parse(code, {
sourceType: 'module'
})
const visitor = {
BinaryExpression(path) {
console.log((path.node))
path.replaceWith(t.binaryExpression('**', t.numericLiteral(3), t.numericLiteral(4)))
}
}
traverse(ast, visitor)
let generated = generate(ast, null, code)
console.log(generated.code)
Run Code Online (Sandbox Code Playgroud)
我正在使用以下 babel 依赖项,知道吗?
"dependencies": {
"babel-generator": …Run Code Online (Sandbox Code Playgroud) 我正在使用BabylonJS V3和Blender 2.79来创建产品可视化.很多时候,有必要在JS代码中定义更复杂的着色器.我正在使用像
scene.meshes[1].material.emissiveColor = new BABYLON.Color3(1, 0, 0);Run Code Online (Sandbox Code Playgroud)
导出后定义着色器.通常,每个网格都可以通过这种方式获得自己的着色器.不幸的是,在一种情况下,多个网格的着色器被覆盖.有人有类似的问题吗?所有网格都是单独命名的,它们都有一个来自blender的基本(单个)着色器.他们不共享任何数据块,没有进行实例化或重复.我很感激每一个提示.
看起来,新版本(3.0)出现错误,更新到3.1修复了问题,但是引入了弧旋转相机的错误.单击画布后,要旋转视图,就不能再释放鼠标了.最新的稳定版本是否有问题?
经过一些深入的故障排除我们得出结论,3.0和3.1版本和/或他们的导出插件是错误的.即使在最简单的测试中,也会发生此错误.除了其他问题,如破碎的相机和移位的几何形状.
我目前在 Angular9 应用程序的上下文中面临Babylon4.1.0 的编译问题。检查员似乎无法导入内部使用的"react"模块。该问题可以通过以下方式重现: * 使用 CLI 创建引导 Angular9 应用程序 * 添加 @babylon/* 依赖项到package.json
* 添加import '@babylonjs/inspector';到app.component.ts
我玩过几个module设置target,但tsconfig.json没有运气。坦率地说,我在这里也有点无能为力,因为我认为npm应该下载所需的依赖项(例如react)。有什么想法可能导致这些问题吗?
以下是相关文件,但正如前面提到的,这基本上只是一个新引导的准系统 Angular9 应用程序。用于重现问题。设置几乎都是出厂默认值。
错误日志
$ npm run start
> angular9-babylon41@0.0.0 start D:\repos\angular9-babylon41
> ng serve
chunk {main} main.js, main.js.map (main) 1.99 kB [initial] [rendered]
chunk {polyfills} polyfills.js, polyfills.js.map (polyfills) 673 bytes [initial] [rendered]
chunk {runtime} runtime.js, runtime.js.map (runtime) 6.15 kB [entry] …Run Code Online (Sandbox Code Playgroud) 我是 Babylonjs 的新手,我想使用 BabylonJs 显示/显示图像,而且我想使用带有碰撞检测的键盘(如左箭头键、右箭头键、上箭头键和下箭头键)移动图像,我也想要禁用所有鼠标事件。
我写了下面的代码来显示图像,但我认为这不是正确的方法..
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;
Run Code Online (Sandbox Code Playgroud)
有人可以帮我怎么做吗(如果你能分享源代码,可能会有更好的帮助)?
谢谢拉维兰詹
当我尝试使用Babylon.js将图像添加到3d球体时,我收到错误 Uncaught SecurityError: Failed to execute 'texImage2D' on 'WebGLRenderingContext': Tainted canvases may not be loaded.
这就是我编写代码的方式.我已经按照这里的教程,一切都完美地工作,直到我尝试更改纹理.
//Creation of spheres
var sphere1 = BABYLON.Mesh.CreateSphere("Sphere1", 10.0, 6.0, scene);
var sphere2 = BABYLON.Mesh.CreateSphere("Sphere2", 2.0, 7.0, scene);
var sphere3 = BABYLON.Mesh.CreateSphere("Sphere3", 10.0, 8.0, scene);
//Positioning the meshes
sphere1.position.x = 10;
sphere3.position.x = -10;
//Textures
var sphere1texture = new BABYLON.StandardMaterial("sphere1texture", scene);
var sphere2texture = new BABYLON.StandardMaterial("sphere2texture", scene);
var sphere3texture = new BABYLON.StandardMaterial("sphere3texture", scene);
sphere1texture.alpha = 0.75
sphere2texture.diffuseTexture = new BABYLON.Texture("./texture1.jpg", scene);
Run Code Online (Sandbox Code Playgroud)
sphere2 (我试图加载图像的那个)没有出现在程序中,但其他一切都运行正常. …
如何在 Babylon.js 中消除球体的(点)光反射?
// Point light.
const light = new BABYLON.PointLight('myLight', new BABYLON.Vector3(0, 1, 0), scene)
// Sphere with size 100.
const newBox = BABYLON.Mesh.CreateSphere('mySphere', 64, 100, scene)
Run Code Online (Sandbox Code Playgroud)
我想照亮一半球体,但不要在红色圆圈中反射:
babylonjs ×10
javascript ×5
angular ×1
assets ×1
babeljs ×1
blender ×1
glsl ×1
light ×1
shader ×1
stack-size ×1
textures ×1
typescript ×1
webgl ×1