场景渲染在Babylonjs中很奇怪 [英] Scene rendering strangely in babylonjs

查看:412
本文介绍了场景渲染在Babylonjs中很奇怪的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,我已将在Blender中制作的场景加载到Babylonjs中,并且产生了一些有趣的效果.基本上,我正在尝试将重力等应用于场景,将播放器移动到适当的位置,并使整个场景明亮可见,但是这些都没有用.这是脚本:

So, I've loaded my scene I made in Blender into Babylonjs, and it's producing some interesting effects. Basically, I am trying to apply gravity and such to the scene, move the player to it's proper location, and make the entire scene lit and visible, but none of that is working. This is the script:

var BABYLON;
var canvas = document.getElementById('gamecanvas');
var engine = new BABYLON.Engine(canvas, true);
var player_height = 2;
var player_speed = 1;
var player_inertia = 0.9;

function INIT_GAME(){
    BABYLON.SceneLoader.Load('Scenes/', 'zombie_map.babylon', engine, function(newScene){
        var scene = newScene; 
        var light = new BABYLON.PointLight('light', new BABYLON.Vector3(0,0,10), scene);
        var player = new BABYLON.FreeCamera('player', new BABYLON.Vector3(1,1,1), scene);
        scene.activeCamera = player;
        scene.activeCamera.attachControl(canvas, true);
        scene.enablePhysics();
        scene.setGravity(new BABYLON.Vector3(0, -10, 0));
        player.ellipsoid = new BABYLON.Vector3(1, player_height, 1);
        player.checkCollisions = true;
        player.applyGravity = true;
        player.keysUp = [87];
        player.keysDown = [83];
        player.keysLeft = [65];
        player.keysRight = [68];
        player.inertia = player_inertia;
        player.speed = player_speed;
        newScene.executeWhenReady(function(){
            engine.runRenderLoop(function(){
                newScene.render();
            });
        });
    });

canvas.height = window.innerHeight;
canvas.width = window.innerWidth;
canvas.requestPointerLock = canvas.requestPointerLock || canvas.mozRequestPointerLock;
canvas.requestPointerLock();

window.addEventListener('resize', function(){
    engine.resize();
});

}

我的问题是:

  1. 如何提高渲染距离,以便可以查看 整个场景?
  2. 为什么我的所有场景属性都不起作用(重力,运动等)?
  1. How do I make the render distance higher, so that I can view the whole scene?
  2. Why are none of my scene properties working (gravity, movement, etc.)?

推荐答案

您的player摄像机应设置为活动摄像机:

Your player camera should be set as the active camera:

var player = new BABYLON.FreeCamera('player', new BABYLON.Vector3(1,1,1), scene);
scene.activeCamera = player;
scene.activeCamera.attachControl(canvas, true);

这篇关于场景渲染在Babylonjs中很奇怪的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆