CesiumGS / cesium

An open-source JavaScript library for world-class 3D globes and maps :earth_americas:
https://cesium.com/cesiumjs/
Apache License 2.0
13.01k stars 3.51k forks source link

Don't throw when working with already created geometry #2488

Open mramato opened 9 years ago

mramato commented 9 years ago

When using asynchronous Primitive, if you pass it a geometry that is already created, it will through because of lack of _workerName. We should detect already created geometry and handle it accordingly and only throw if the Geometry isn't created.

forum post

var viewer = new Cesium.Viewer('cesiumContainer');
var scene = viewer.scene;

var length = 400000.0;
var positionOnEllipsoid = Cesium.Cartesian3.fromDegrees(-100.0, 40.0);
var modelMatrix = Cesium.Matrix4.multiplyByTranslation(
    Cesium.Transforms.eastNorthUpToFixedFrame(positionOnEllipsoid),
    new Cesium.Cartesian3(0.0, 0.0, length * 0.5), new Cesium.Matrix4()
);
var cylinderGeometry = Cesium.CylinderGeometry.createGeometry(new Cesium.CylinderGeometry({
    length : length,
    topRadius : 200000.0,
    bottomRadius : 200000.0,
    vertexFormat : Cesium.PerInstanceColorAppearance.VERTEX_FORMAT
}));
var greenCylinder = new Cesium.GeometryInstance({
    geometry : cylinderGeometry,
    modelMatrix : modelMatrix,
    attributes : {
        color : Cesium.ColorGeometryInstanceAttribute.fromColor(Cesium.Color.GREEN)
    }
});

scene.primitives.add(new Cesium.Primitive({
    geometryInstances : [greenCylinder],
    appearance : new Cesium.PerInstanceColorAppearance({
        closed : true,
        translucent: false
    })
}));
esparano commented 7 years ago

I ran into this bug today. Took a while to find the solution.