我正在处理babylonjs-playground.com 上的“基本场景”示例,尝试对球体的颜色进行简单的修改。
这是我的尝试,可以交互运行:
https://www.babylonjs-playground.com/#95BNBS
这是代码:
var createScene = function () {
// The original example, without comments:
var scene = new BABYLON.Scene(engine);
var camera = new BABYLON.FreeCamera("camera1", new BABYLON.Vector3(0, 5, -10), scene);
camera.setTarget(BABYLON.Vector3.Zero());
camera.attachControl(canvas, true);
var light = new BABYLON.HemisphericLight("light1", new BABYLON.Vector3(0, 1, 0), scene);
light.intensity = 0.7;
var sphere = BABYLON.Mesh.CreateSphere("sphere1", 16, 2, scene);
sphere.position.y = 1;
var ground = BABYLON.Mesh.CreateGround("ground1", 6, 6, 2, scene);
// My attempt to color the sphere
var material = new BABYLON.StandardMaterial(scene); …Run Code Online (Sandbox Code Playgroud) 我正在使用 Nextjs 构建我的网站,导入 Bablyonjs 时出现以下错误。
syntaxError: Unexpected token 'export'
module.exports = require("@babylonjs/core")
Run Code Online (Sandbox Code Playgroud)
我正在使用带有 tsconfig.json 的标准 nextjs 设置我正在参考这个 Babylon 文档并逐字使用示例。
在 BabylonJs 中更改画布大小后,如何刷新场景或画布?我想要的只是重新渲染场景,因为当用户更改浏览器大小时纵横比会发生变化。
我在 StencilJS 应用程序中使用 BabylonJS,而且我似乎只能以非常特定的方式导入。
例如我不能这样做:
import { Engine, Scene } from "babylonjs";
Run Code Online (Sandbox Code Playgroud)
它说'Engine' is not exported by node_modules\babylonjs\babylon.js
但它是..
我可以:
import BABYLON from 'babylonjs';
Run Code Online (Sandbox Code Playgroud)
并像使用它一样
private _scene: BABYLON.Scene;
Run Code Online (Sandbox Code Playgroud)
我想让前者工作。有什么建议吗?
第一种方法是大多数教程是如何做到的,我拒绝相信 SencilJS 没有能力做到这一点。我肯定错过了什么
我想要一个事件,当相机触摸网格时,它会移动到其他地方,例如门户。
这是我的相机:
function MaCamera(scene, positionCx, positionCy, positionCz)
{
var freeCamera = new BABYLON.FreeCamera("FreeCamera", new BABYLON.Vector3(positionCx, positionCy, positionCz), scene);
freeCamera.rotation = new BABYLON.Vector3(0.5, 0, 0);
freeCamera.attachControl(canvas, true);
freeCamera.checkCollisions = true;
scene.activeCamera = freeCamera;
}
Run Code Online (Sandbox Code Playgroud)
这是我的网格:
var drawMirror = BABYLON.Mesh.CreateBox("rectangle", 1, scene);
drawMirror.scaling = new BABYLON.Vector3(12, 0.1, 20);
drawMirror.rotation.x = Math.PI / 2;
drawMirror.position = new BABYLON.Vector3(positionMx, positionMy, positionMz);
drawMirror.checkCollisions = true;
Run Code Online (Sandbox Code Playgroud) 我正在尝试使表面哑光,但没有成功。应用于它的StandardMaterial只有一个diffuseColor。我尝试使用“粗糙度”(0 到 7 之间),但表面总是有光泽的。
如何获得哑光表面?
我一直在看很多不同的教程,学习我一直在做的编码,我注意到了一个常见的区别.基本上,有些人纯粹使用HTML编写脚本,使用脚本标记,有些人使用JavaScript并引用脚本.我的问题在于两个代码.第一个:
<!DOCTYPE html>
<html>
<head>
<script src='babylon.js'></script>
<title>game or some shit</title>
<meta charset="utf-8">
<style>
.canvas {
height: 100%;
width: 100%;
padding:0;
margin:0;
overflow: hidden;
}
</style>
</head>
<body>
<canvas id='gamecanvas'></canvas>
<script>
var BABYLON;
var canvas = document.getElementById('gamecanvas');
var engine = new BABYLON.Engine(canvas, true);
var scene = new BABYLON.Scene(engine);
var camera = new BABYLON.ArcRotateCamera('camera', 1,2,20, new BABYLON.Vector3(0,0,0), scene);
var light = new BABYLON.PointLight('light', new BABYLON.Vector3(0,0,10), scene);
var ball = new BABYLON.Mesh.CreateSphere('ball', 10, 1.0, scene);
scene.activeCamera.attachControl(canvas);
engine.runRenderLoop(function()
{
scene.render();
});
canvas.height = …Run Code Online (Sandbox Code Playgroud) 我正在使用BabylonJS制作一个小游戏。
我正在使用此代码来构建相机:
this.cam = new BABYLON.FreeCamera("playerCamera", new BABYLON.Vector3(x, y, z), s);
this.cam.checkCollisions = true;
this.cam.applyGravity = false;
this.cam.keysUp = [90]; // Z
this.cam.keysDown = [83]; // S
this.cam.keysLeft = [81]; // Q
this.cam.keysRight = [68]; // D
this.cam.speed = v;
this.cam.ellipsoid = new BABYLON.Vector3(1, h, 1);
this.cam.angularSensibility = a;
Run Code Online (Sandbox Code Playgroud)
它可以工作,我有一个相机,我可以四处移动等等......
但我的问题在这里:默认情况下,当移动和改变相机的方向时,它们是一个平滑的动画。
让我解释一下:当我用箭头键移动(向左大约 20 像素)时,它将变为 25 像素(20 像素 + 5 平滑像素)。
我不想要它:/你知道如何禁用它吗?(移动和改变相机的方向)。
我正在寻找一种在巴比伦或 Threejs 中将文本环绕在球体周围的方法。我对改变 javascript 技术持开放态度