Question about using triangles to draw a 3D shape

Hi! I am new to Cesium and the questin may be naive. I have a list of vertices of a 3D model I wish to draw, and what I am currently trying is to fetch out all the triangles and draw the triangles to enclose the shape. The model I am dealing with end up having over 60 thousand trangles, and adding them all to entities one by one become extremely slow. I then tried to create geometry instance and add them to the scene. Here is my code snippet, I basically clipped it from documentations:

The input triangle_list is an array of triangles, where each triangle is represented by an array of three Cartesian3, represeting the positions of the three vertices of the triangle.

const scene = viewer.scene;
const positions = new Float64Array([triangle_list.flat(4)]);
const geometry = new Cesium.Geometry({
  attributes: {
    position: new Cesium.GeometryAttribute({
      componentDatatype: Cesium.ComponentDatatype.DOUBLE,
      componentsPerAttribute: 3,
      values: positions,
    }),
  },
  primitiveType: Cesium.PrimitiveType.TRIANGLES,
  boundingSphere: Cesium.BoundingSphere.fromVertices(positions),
});
const geo_instance = new Cesium.GeometryInstance({
  geometry: geometry,
});

scene.primitives.add(
  new Cesium.Primitive({
    geometryInstances: [geo_instance],

    appearance: new Cesium.DebugAppearance({ attributeName: "some name" }),
  })
);

Executing above code gave me following error:

I have check the Max Vertex Attributes:

Here are my questions:

  1. Is there an efficient way to render this shape other than the method I took?
  2. How do I render many triangles efficiently?
  3. What did I do wrong in above code caused this error?

Hi @Xiaoyang_Guo,

Typically, geometries are not individual triangles, but one of several geometry classes.

Can you tell us a little more about what your are trying to render?

Likely the best solution would be to implement your own custom geometry class.

Can you tell us a little more about what your are trying to render?

That’s the important point here, and one could go even further and ask whether this data really has to be assmebled at runtime. Otherwise, it could be stored as a pre-built model (e.g. a glTF model), where even a million triangles should not cause to much of a performance issue…

1 Like

Thank you for your reply. We were acutally able to solve the vertex texture issue by reinstalling cesium. The issue occur again after couple days, and then we change the import to another version of Cesium (currently we import cesium from Mars3D). The problem went away and haven’t appears again yet. We were not sure about why it happened and how it went away, but since our project need Mars3D anyway, so I guess we are ok with this(?).

Regarding the triangles and geomentries, we did have a rather complex custom geometry. Our solution was following:

  1. Compute the positions of all vertices and compute triangle indices from the vertices
  2. Add all vertex positons to a position attribute; use the attribute and the indices to create a geometry.
  3. Create a single instance from the geometry and create a primitive with the instance.
  4. Render the primitive.

To have some basic shading on the primitive, we called Cesium.GeometryPipeline.computeNormal() to add normals to the geometry (which is actually taking the largest portion of loading time now). The procedures above were learnt from the github wiki:

Which is a very good tutorial. Our first try failed due to the vertex texture error, but then the second try succeeded after reinstalling Cesium. I wish there are more good tutorials like this, as I almost thought Cesium was not capable for my task (My apology as I just started to learn Cesium since about two weeks ago, so 3-4 days when I post the initial question) before I found the tutorial.There is another post on forum from me, which is also about this task; I saw you mentioned using gltf. Someone else in our team tried it, but the structure we want to display are very long (the longest one is about 22 km), so according to him the earth curvature causes some dislocations between structures.

Anyway, our problem was solved and we are temporarily happy with the current solution. Thank you again for your reply.

I saw you mentioned using gltf. Someone else in our team tried it, but the structure we want to display are very long (the longest one is about 22 km), so according to him the earth curvature causes some dislocations between structures.

Ah yes. You may actually benefit from using 3D Tiles, which is a format that builds on glTF specifically for rendering massive geospatial datasets.