I've created a custom primitive with a couple of hundred thousand triangles.
Something like:
var triangles = 2000000;
var positions = new Float64Array(triangles * 3 * 3);
var normals = new Float32Array(triangles * 3 * 3);
var colors = new Float32Array(triangles * 3 * 3);
/// ... fill in the buffers
var instance = new GeometryInstance({
geometry : new Geometry({
attributes : {
position : new GeometryAttribute({
componentDatatype : ComponentDatatype.DOUBLE,
componentsPerAttribute : 3,
values : positions,
normalize: false
}),
color : new GeometryAttribute({
componentDatatype : ComponentDatatype.FLOAT,
componentsPerAttribute : 3,
values : colors,
normalize: false
}),
normal : new GeometryAttribute({
componentDatatype : ComponentDatatype.FLOAT,
componentsPerAttribute : 3,
values : normals,
normalize: false
})
},
primitiveType : PrimitiveType.TRIANGLES,
boundingSphere : BoundingSphere.fromVertices(positions),
})
});
var primitive = new Primitive({
geometryInstances : instance,
appearance : new PerInstanceColorAppearance({
translucent : false
})
});
viewer.scene.primitives.add(primitive);
At a later time, I am in need of updating the color buffer to a different set of colors.
So I go:
var triangles = 2000000;
var colors = new Float32Array(triangles * 3 * 3);
/// ... fill in the color buffer with new colors
primitive._vaAttributes[0][primitive._attributeLocations.color].vertexBuffer.copyFromArrayView(colors.buffer, 0);
And it does not work.
Any help appreciated.