xeolabs / xeogl

A WebGL-based 3D engine for technical visualization. Not actively maintained.
http://xeogl.org
Other
1.14k stars 264 forks source link

CameraControl with default constructed Scene doesn't behave like default scene #235

Closed weshoke closed 6 years ago

weshoke commented 6 years ago
Description of the problem

When I create a default constructed scene new xeogl.Scene() and add a camera control new xeogl.CameraControl(); I see nothing. When I do so with the built-in xeogl.scene, I see my objects. This seems really counter intuitive and I have absolutely no idea how to diagnose or what's going on.

<!DOCTYPE html>
<html lang="en">
<head>
    <title>xeogl Example</title>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
    <script src="xeogl.min.js"></script>
<body>
<script>
    var scene = new xeogl.Scene();
    var geometry = new xeogl.TorusGeometry(scene, {
        radius: 1.0,
        tube: 0.3,
        radialSegments: 120,
        tubeSegments: 60
    });
    var material = new xeogl.PhongMaterial(scene, {
        diffuse: [ 0.6, 0.6, 0.7 ]
    });
    var entity = new xeogl.Entity(scene, {
        geometry: geometry,
        material: material
    });
    new xeogl.CameraControl();
</script>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
    <title>xeogl Example</title>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
    <script src="xeogl.min.js"></script>
<body>
<script>
    var scene = xeogl.scene;
    var geometry = new xeogl.TorusGeometry(scene, {
        radius: 1.0,
        tube: 0.3,
        radialSegments: 120,
        tubeSegments: 60
    });
    var material = new xeogl.PhongMaterial(scene, {
        diffuse: [ 0.6, 0.6, 0.7 ]
    });
    var entity = new xeogl.Entity(scene, {
        geometry: geometry,
        material: material
    });
    new xeogl.CameraControl();
</script>
</body>
</html>
xeogl version
Browser
OS
Hardware Requirements
xeolabs commented 6 years ago

In the first example, you've created your Entity in a custom scene, while falling back on the default Scene for your CameraControl, so that would give strange results.

The second example should work, and after quick debug (console did have diagnostic messages and stack trace for that) I found that a Material component within the CameraControl is not created in the same Scene - I fixed this, and so the second example is working now.