toNonIndexed method
Implementation
BufferGeometry toNonIndexed() {
convertBufferAttribute(attribute, indices) {
print("BufferGeometry.convertBufferAttribute todo ");
var array = attribute.array;
var itemSize = attribute.itemSize;
var normalized = attribute.normalized;
var array2 = Float32Array(indices.length * itemSize);
var index = 0, index2 = 0;
for (var 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 (var j = 0; j < itemSize; j++) {
array2[index2++] = array[index++].toDouble();//gl
}
}
return Float32BufferAttribute(array2, itemSize, normalized);
}
//
if (index == null) {
print(
'THREE.BufferGeometry.toNonIndexed(): Geometry is already non-indexed.');
return this;
}
var geometry2 = BufferGeometry();
var indices = index!.array;
var attributes = this.attributes;
// attributes
for (var name in attributes.keys) {
var attribute = attributes[name];
var newAttribute = convertBufferAttribute(attribute, indices);
geometry2.setAttribute(name, newAttribute);
}
// morph attributes
var morphAttributes = this.morphAttributes;
for (var name in morphAttributes.keys) {
List<BufferAttribute> morphArray = [];
List<BufferAttribute> morphAttribute = morphAttributes[
name]!; // morphAttribute: array of Float32BufferAttributes
for (var i = 0, il = morphAttribute.length; i < il; i++) {
var attribute = morphAttribute[i];
var newAttribute = convertBufferAttribute(attribute, indices);
morphArray.add(newAttribute);
}
geometry2.morphAttributes[name] = morphArray;
}
geometry2.morphTargetsRelative = morphTargetsRelative;
// groups
var groups = this.groups;
for (var i = 0, l = groups.length; i < l; i++) {
var group = groups[i];
geometry2.addGroup(
group["start"], group["count"], group["materialIndex"]);
}
return geometry2;
}