question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Clarify attribute indexing documentation

See original GitHub issue

The current documentation around the indicesPerMaterial attribute is very confusing as many different terms are used interchangeably.

The Readme states that the indices can be used to index into the attribute component arrays such like

submeshIndices = indicesPerMaterial[0];
attributeIndex = submeshIndices[0];
vertices[attributeIndex];
normals[attributeIndex];
textures[attributeIndex];

However the attribute arrays themselves are flattened so that each element stores an attribute component rather than a vertex full attribute. Therefore to store information for a full vertex one must index the attribute arrays once for each component of the vertex attribute (so 3 times for a position and 2 times for a texture coordinate). But it isn’t clear which is the correct method of doing this either:

attributeIndex0 = submeshIndices[0];
attributeIndex1 = submeshIndices[1];
attributeIndex2 = submeshIndices[2];
Vector3 actualVertexPosition;
actualVertexPosition.x = vertices[attributeIndex0];
actualVertexPosition.y = vertices[attributeIndex1];
actualVertexPosition.z = vertices[attributeIndex2];

or

attributeIndex = submeshIndices[0];
Vector3 actualVertexPosition;
actualVertexPosition.x = vertices[attributeIndex];
actualVertexPosition.y = vertices[attributeIndex + 1];
actualVertexPosition.z = vertices[attributeIndex + 2];

I’m guessing the latter otherwise it wouldn’t work with attributes of different sizes, but that’s just my guess. The documentation should be clearer to specify which is correct.

What also doesn’t help is the naming of the vertices attribute which is in fact vertex positions and so should be named positions, but maybe I should make a separate issue for that?

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
frenchtoast747commented, Jan 13, 2019

Will do for adding a note on vertices being position.

I will also add the following snippet for correctly indexing the individual components on the JS side:

// there are 3 components for a geometric vertex: X, Y, and Z
const NUM_COMPONENTS_FOR_VERTS = 3;
elementIdx = mesh.indices[SOME_IDX]; // e.g. 38
// in order to get the X component of the vertex component of element "38"
elementVertX = mesh.vertices[(elementIdx * NUM_COMPONENTS_FOR_VERTS) + 0]
// in order to get the Y component of the vertex component of element "38"
elementVertY = mesh.vertices[(elementIdx * NUM_COMPONENTS_FOR_VERTS) + 1]
// in order to get the Z component of the vertex component of element "38"
elementVertZ = mesh.vertices[(elementIdx * NUM_COMPONENTS_FOR_VERTS) + 2]

which is doing roughly what the shader compiler does for you when you say vert.x, vert.y, vert.z.

And likewise, to iterate over the each vertex

for (let i = 0; i < mesh.vertices.length; i += 3) {
    const x = mesh.vertices[i];
    const y = mesh.vertices[i+ 1];
    const z = mesh.vertices[i + 2];
}
0reactions
frenchtoast747commented, Jan 17, 2019

Hi @abcthomas, I have updated the README based on the points from the discussion here. Could you have a quick look at it and let me know what you think?

I used the same diagram but included an additional description underneath it that should hopefully describe the boxes and why X, Y, and Z are labeled with the 38th index.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Index Basics | Indexing | Manual | ArangoDB Documentation
The primary index allows quick selection of documents in the collection using either the _key or _id attributes. It will be used from...
Read more >
Attribute Indexing Walkthrough - YouTube
In this video, we'll explain what attribute indexing is, how it helps reduce the memory usage of Insight, and how you can decide...
Read more >
Attribute indexes in the geodatabase—ArcGIS Pro
An attribute index is an alternate path used by ArcGIS to retrieve a record from a table. For most types of attribute queries,...
Read more >
Working with Indexes | Macrometa
Top-level as well as nested attributes can be indexed. For attributes at the top level, the attribute names alone are required. To index...
Read more >
Indexing in MarkLogic (Concepts Guide) - Documentation
The Universal Index; Other Types of Indexes; Index Size; Fields; Reindexing; Relevance; Indexing Document Metadata; Fragmentation of XML Documents. The ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found