Scene rendering strangely in babylonjs

久未见 提交于 2019-12-13 04:28:09

问题


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();
});

}

The questions I have are:

  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.)?

回答1:


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);


来源:https://stackoverflow.com/questions/36379819/scene-rendering-strangely-in-babylonjs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!