toNonIndexed method
BufferGeometry
toNonIndexed()
inherited
Return a non-index version of an indexed BufferGeometry.
Implementation
BufferGeometry toNonIndexed() {
Float32BufferAttribute convertBufferAttribute(BufferAttribute attribute, indices) {
console.info("BufferGeometry.convertBufferAttribute todo");
final array = attribute.array;
final itemSize = attribute.itemSize;
final normalized = attribute.normalized;
final array2 = Float32List(indices.length * itemSize);
int index = 0, index2 = 0;
for (int i = 0, l = indices.length; i < l; i++) {
if (attribute is InterleavedBufferAttribute) {
index = indices[i] * attribute.data!.stride + attribute.offset;
} else {
index = indices[i] * itemSize;
}
for (int j = 0; j < itemSize; j++) {
array2[index2++] = array[index++].toDouble();
}
}
return Float32BufferAttribute.fromList(array2, itemSize, normalized);
}
//
if (index == null) {
console.info('BufferGeometry.toNonIndexed(): Geometry is already non-indexed.');
return this;
}
final geometry2 = BufferGeometry();
final indices = index!.array;
final attributes = this.attributes;
// attributes
for (String name in attributes.keys) {
final attribute = attributes[name];
final newAttribute = convertBufferAttribute(attribute, indices);
geometry2.setAttributeFromString(name, newAttribute);
}
// morph attributes
final morphAttributes = this.morphAttributes;
for (String name in morphAttributes.keys) {
List<BufferAttribute> morphArray = [];
List<BufferAttribute> morphAttribute = morphAttributes[name]!; // morphAttribute: array of Float32BufferAttributes
for (int i = 0; i < morphAttribute.length; i++) {
final attribute = morphAttribute[i];
final newAttribute = convertBufferAttribute(attribute, indices);
morphArray.add(newAttribute);
}
geometry2.morphAttributes[name] = morphArray;
}
geometry2.morphTargetsRelative = morphTargetsRelative;
// groups
List<Map<String,dynamic>> groups = this.groups;
for (int i = 0, l = groups.length; i < l; i++) {
final group = groups[i];
geometry2.addGroup(group["start"], group["count"], group["materialIndex"]);
}
return geometry2;
}