Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed #1272 #1288

Merged
merged 1 commit into from
Jan 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion packages/viewer-sandbox/src/Sandbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -678,7 +678,8 @@ export default class Sandbox {
Area: 'parameters.HOST_AREA_COMPUTED.value',
SpeckleType: 'speckle_type',
DisplayName: 'DisplayName',
EmbodiedCarbon: 'EmbodiedCarbon'
EmbodiedCarbon: 'EmbodiedCarbon',
Floor: 'Floor'
}
})

Expand Down
2 changes: 1 addition & 1 deletion packages/viewer/src/modules/batching/MeshBatch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ export default class MeshBatch implements Batch {
let maxGradientIndex = 0
for (let k = 0; k < sortedRanges.length; k++) {
if (sortedRanges[k].materialOptions) {
if (sortedRanges[k].materialOptions.rampIndex) {
if (sortedRanges[k].materialOptions.rampIndex !== undefined) {
const start = sortedRanges[k].offset
const len = sortedRanges[k].offset + sortedRanges[k].count
/** The ramp indices specify the *begining* of each ramp color. When sampling with Nearest filter (since we don't want filtering)
Expand Down
61 changes: 60 additions & 1 deletion packages/viewer/src/modules/batching/PointBatch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,16 @@ export default class PointBatch implements Batch {
if (k === 0) {
if (sortedRanges[k].start > 0) {
this.geometry.addGroup(0, sortedRanges[k].start, 0)
continue
}
if (
sortedRanges.length === 1 &&
sortedRanges[k].start + sortedRanges[k].count < this.getCount()
) {
this.geometry.addGroup(
sortedRanges[k].start + sortedRanges[k].count,
this.getCount() - sortedRanges[k].start + sortedRanges[k].count,
0
)
}
} else if (k === sortedRanges.length - 1) {
if (sortedRanges[k].start + sortedRanges[k].count < this.getCount()) {
Expand Down Expand Up @@ -192,6 +201,56 @@ export default class PointBatch implements Batch {
console.error(`DrawRange autocomplete failed! ${count}vs${this.getCount()}`)
}

/** We're flattening sequential groups to avoid redundant draw calls.
* ! Not thoroughly tested !
*/
const materialOrder = []
this.geometry.groups.reduce((previousValue, currentValue) => {
if (previousValue.indexOf(currentValue.materialIndex) === -1) {
previousValue.push(currentValue.materialIndex)
}
return previousValue
}, materialOrder)
const grouped = []
for (let k = 0; k < materialOrder.length; k++) {
grouped.push(
this.geometry.groups.filter((val) => {
return val.materialIndex === materialOrder[k]
})
)
}
this.geometry.groups = []
for (let matIndex = 0; matIndex < grouped.length; matIndex++) {
const matGroup = grouped[matIndex]
for (let k = 0; k < matGroup.length; ) {
let offset = matGroup[k].start
let count = matGroup[k].count
let runningCount = matGroup[k].count
let n = k + 1
for (; n < matGroup.length; n++) {
if (offset + count === matGroup[n].start) {
offset = matGroup[n].start
count = matGroup[n].count
runningCount += matGroup[n].count
} else {
this.geometry.addGroup(
matGroup[k].start,
runningCount,
matGroup[k].materialIndex
)
break
}
}
if (n === matGroup.length) {
this.geometry.addGroup(
matGroup[k].start,
runningCount,
matGroup[k].materialIndex
)
}
k = n
}
}
// console.warn(
// `Batch ID ${this.id} Group count ${this.geometry.groups.length} AUTOCOMPLETE`
// )
Expand Down