NatLabRockies / NatLabRockies/OpenStudio
modelToThreeJS super slow for some models (a wall with many subsurfaces)
Nobody has claimed this yet.
- Dominant language
- C++
- Stars
- 646
- Forks
- 237
- Avg merge
- 3d 11h
- Merged PRs (30d)
- 10
Description
Issue overview
User reported issue with OpenStudioApplication loading the Geometry Preview, turns out it's actually happening in the OS SDK.
I slimmed down the model so I could backport it to 3.2.0.
| Version | Real (s) |
|---|---|
| 3.2.0 | 309 |
| 3.3.0 | 309 |
| 3.4.0 | 122 |
| 3.5.0 | 112 |
Current Behavior
It takes two minutes to load it. Geometry is not that complicated.

Investigation 1: surfaces with high number of vertices => NO
Seems like there are several surfaces with a way too high number of vertices to begin with, could be related.
m.getSurfaces.map(&:vertices).map(&:size).sort.reverse.first(5)
=> [14, 14, 10, 10, 6]
But apparently it's not: m.getSurfaces.filter{|s| s.vertices.size >= 10}.each(&:remove) then scene = ft.modelToThreeJS(m, true) still takes for ever.
Investigation 2: Surface with a high number of subSurfaces => Yes
There are a few surfaces with a very high number of sub surfaces on it.
m.getSurfaces.map(&:subSurfaces).map(&:size).sort.reverse.first(10)
=> [24, 18, 15, 8, 4, 2, 2, 0, 0, 0]
If I remove the one with 24 surfaces (and it's subSurfaces), then the result is immediate.
[35] Temp(main)>m = osload('modelToThreeJS_slow.osm')
=> #<OpenStudio::Model::Model:0x000055c154b60e70 @__swigtype__="_p_openstudio__model__Model">
[36] Temp(main)> m.getSurfaces.size + m.getSubSurfaces.size
=> 143
[37] Temp(main)> m.getSurfaces.filter{|s| s.subSurfaces.size >= 24}.each(&:remove)
=> [#<OpenStudio::Model::Surface:0x000055c1548c01e8 @__swigtype__="_p_openstudio__model__Surface">]
[38] Temp(main)> m.getSurfaces.size + m.getSubSurfaces.size
=> 118
[40] Temp(main)> s = Time.now; scene = ft.modelToThreeJS(m, true); puts "#{(Time.now - s).round(2)} seconds"
3.73 seconds
I then did this
m = osload('modelToThreeJS_slow.osm')
s = m.getSurfaces.filter{|s| s.subSurfaces.size >= 24}.first
15.times do |i|
s.subSurfaces.first.remove
st = Time.now
scene = ft.modelToThreeJS(m, true)
puts "#{s.subSurfaces.size} subSurfaces - #{(Time.now - st).round(2)} seconds"
end
23 subSurfaces - 103.25 seconds && LOTS of "[utilities.geometry.computeTriangulation] <1> Failed to partition polygon"
22 subSurfaces - 43.25 seconds
21 subSurfaces - 26.18 seconds
20 subSurfaces - 17.3 seconds
19 subSurfaces - 10.98 seconds
18 subSurfaces - 8.14 seconds
17 subSurfaces - 6.12 seconds
16 subSurfaces - 5.23 seconds
15 subSurfaces - 4.71 seconds
14 subSurfaces - 4.31 seconds
13 subSurfaces - 4.07 seconds
12 subSurfaces - 3.97 seconds
11 subSurfaces - 3.89 seconds
10 subSurfaces - 3.85 seconds
9 subSurfaces - 3.82 seconds
8 subSurfaces - 3.85 seconds
Details
Environment
Some additional details about your environment for this issue (if relevant):
- Platform (Operating system, version): All
- Version of OpenStudio (if using an intermediate build, include SHA): 3.2.0 to 3.5.0
Context
cf https://github.com/openstudiocoalition/OpenStudioApplication/issues/579#issuecomment-1359365507
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing modelToThreeJS with the attached modelToThreeJS_slow.osm.txt file and measure the runtime as subSurfaces are removed. Inspect the modelToThreeJS path and the reported utilities.geometry.computeTriangulation failures. Done means the model loads without the extreme slowdown and the existing geometry preview behavior remains intact.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- computer-graphics, performance
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100