Jump to content

[Solved] Camera doesn't rotates around textured cube


8Observer8
 Share

Recommended Posts

Sorry for my stupid question but I don't know why the Camera doesn't rotate around my textured cube: 

https://8observer8.github.io/BabylonJS/TexturedCube/

 

function main()
{
    // Retrieve the canvas element
    var canvas = document.getElementById("renderCanvas");
    if (canvas == null)
    {
        console.log("Failed to retrieve the canvas element");
        return;
    }

    var engine = new BABYLON.Engine(canvas, true);

    var createScene = function ()
    {
        BABYLON.SceneLoader.Load("", "TexturedCube.babylon", engine, function (scene)
        {
            // Wait for textures and shaders to be ready
            scene.executeWhenReady(function ()
            {
                // Create a light
                var light = new BABYLON.PointLight("Omni", new BABYLON.Vector3(0, 5, -10), scene);
                //light.groundColor = new BABYLON.Color3(0.2, 0, 0.3);

                // Create Arc Rotate Camera
                var camera = new BABYLON.ArcRotateCamera("Camera", 0, Math.PI / 2, 12, BABYLON.Vector3.Zero(), scene);
                camera.attachControl(canvas, false);

                //console.log(scene.mesh[0]);

                // Once the scene is loaded, just register a renger loop to render it
                engine.runRenderLoop(function ()
                {
                    scene.render();
                });

                // Resize
                window.addEventListener("resize", function ()
                {
                    engine.resize();
                });
            });
        }, function (progress)
        {
            // ToDo: give progress feedback to user
        });

        return scene;
    };

    var scene = createScene();
}

 

Link to comment
Share on other sites

10 minutes ago, Deltakosh said:

it is far simpler for us to help you if you can create a playground repro.

I tryed but I cannot to upload .png file on the playgound. How to do this?

 

 

10 minutes ago, Deltakosh said:

can you confirm that your cube is centered at (0, 0, 0) ?

Yes, I can write to console by: console.log(scene.meshes[0].position);
 

  1. Quote

    i x:0 y:0 z:0

Link to comment
Share on other sites

Is the file you used for the "Texturedcube.babylon" the one I looked at above? And when you exported it, did you export the camera?

If so, open that TexturedCube.babylon in a text editor and look to see if it has made that camera the "active camera".

If it has, then add this line of code to your code:

scene.activeCamera = camera;

after the line that creates the camera, but before the line that attaches the camera to the canvas.

cheers, gryff :)

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...