Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GeometryPipeline.splitLongitudeTriangles() doesn't preserve color attributes #4739

Closed
movestill opened this issue Dec 11, 2016 · 3 comments
Closed

Comments

@movestill
Copy link

When using custom geometry with color attributes assigned to vertices, the color attributes aren't copied when splitting triangles that cross the -180|180 longitude degree boundary. Specifically, the GeometryPipeline.computeTriangleAttributes() function doesn't take color as an input parameter.

My use case is drawing heat maps on the globe. For heat maps, I want a specific color assigned to each vertex. Below is sandcastle code that will throw a render error due to the color attributes not being copied when the triangle is split.

var viewer = new Cesium.Viewer('cesiumContainer', {
    selectionIndicator: false,
    infoBox: false
});

var p0 = Cesium.Cartesian3.fromDegrees(-179.0, 37.0);
var p1 = Cesium.Cartesian3.fromDegrees(179.0, 32.0);
var p2 = Cesium.Cartesian3.fromDegrees(-179.0, 33.0);

var positions = new Float64Array([
  p0.x, p0.y, p0.z,
  p1.x, p1.y, p1.z,
  p2.x, p2.y, p2.z
]);

var triColors = new Uint8Array([
    255, 0, 0, 128,
    0, 255, 0, 128,
    0, 0, 255, 128
]);

var geometry = new Cesium.Geometry({
  attributes : {
    position : new Cesium.GeometryAttribute({
      componentDatatype : Cesium.ComponentDatatype.DOUBLE,
      componentsPerAttribute : 3,
      values : positions
    }),
    color: new Cesium.GeometryAttribute({
        componentDatatype: Cesium.ComponentDatatype.UNSIGNED_BYTE,
        componentsPerAttribute: 4,
        values: triColors,
        normalize: true
    })
  },
  indices : new Uint16Array([0, 1, 2]),
  primitiveType : Cesium.PrimitiveType.TRIANGLES,
  boundingSphere : Cesium.BoundingSphere.fromVertices(positions)
});

var geometryInstance = new Cesium.GeometryInstance({
    geometry: geometry
});

var prim = new Cesium.Primitive({
    asynchronous: false,
    geometryInstances : geometryInstance,
    appearance: new Cesium.PerInstanceColorAppearance()
});
viewer.scene.primitives.add(prim);
@hpinkos
Copy link
Contributor

hpinkos commented Dec 11, 2016

Thanks for reporting this @movestill

Related #1894

@likangning93
Copy link
Contributor

@movestill if this is something you're still working on and you don't need Columbus View or 2D, you can also set scene3DOnly to true. You'll also need to indicate Cesium.PerInstanceColorAppearance({flat : true}), since otherwise the appearance expects compressed normals.

var viewer = new Cesium.Viewer('cesiumContainer', {
    selectionIndicator: false,
    infoBox: false,
    scene3DOnly : true
});

var p0 = Cesium.Cartesian3.fromDegrees(-179.0, 37.0);
var p1 = Cesium.Cartesian3.fromDegrees(179.0, 32.0);
var p2 = Cesium.Cartesian3.fromDegrees(-179.0, 33.0);

var positions = new Float64Array([
  p0.x, p0.y, p0.z,
  p1.x, p1.y, p1.z,
  p2.x, p2.y, p2.z
]);

var triColors = new Uint8Array([
    255, 0, 0, 128,
    0, 255, 0, 128,
    0, 0, 255, 128
]);

var geometry = new Cesium.Geometry({
  attributes : {
    position : new Cesium.GeometryAttribute({
      componentDatatype : Cesium.ComponentDatatype.DOUBLE,
      componentsPerAttribute : 3,
      values : positions
    }),
    color: new Cesium.GeometryAttribute({
        componentDatatype: Cesium.ComponentDatatype.UNSIGNED_BYTE,
        componentsPerAttribute: 4,
        values: triColors,
        normalize: true
    })
  },
  indices : new Uint16Array([0, 1, 2]),
  primitiveType : Cesium.PrimitiveType.TRIANGLES,
  boundingSphere : Cesium.BoundingSphere.fromVertices(positions)
});

var geometryInstance = new Cesium.GeometryInstance({
    geometry: geometry
});

var prim = new Cesium.Primitive({
    asynchronous: false,
    geometryInstances : geometryInstance,
    appearance: new Cesium.PerInstanceColorAppearance({
        flat : true
    })
});
viewer.scene.primitives.add(prim);

I'm looking at getting this to work in 2D/CV as well though.

@movestill
Copy link
Author

Thanks for the update. We're not currently using Cesium for the project, but we may return to it at some point. Good to know it's getting addressed!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants