Skip to content

Commit dac514b

Browse files
committed
updating examples and view endpoint to use latest rhino3dm 7.14
1 parent cc5aac9 commit dac514b

File tree

8 files changed

+146
-25
lines changed

8 files changed

+146
-25
lines changed

src/examples/bendy/index.html

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,14 +57,14 @@
5757
</div>
5858

5959
<script type="module">
60-
import * as THREE from 'https://cdn.jsdelivr.net/npm/three@0.126.0/build/three.module.js'
61-
import { OrbitControls } from 'https://cdn.jsdelivr.net/npm/three@0.126.0/examples/jsm/controls/OrbitControls.js'
62-
import { Rhino3dmLoader } from 'https://cdn.jsdelivr.net/npm/three@0.126.0/examples/jsm/loaders/3DMLoader.js'
63-
import rhino3dm from 'https://cdn.jsdelivr.net/npm/rhino3dm@0.15.0-beta/rhino3dm.module.js'
60+
import * as THREE from 'three'
61+
import { OrbitControls } from 'three/examples/jsm/controls/OrbitControls'
62+
import { Rhino3dmLoader } from 'three/examples/jsm/loaders/3DMLoader'
63+
import rhino3dm from 'https://cdn.jsdelivr.net/npm/rhino3dm@7.14.0/rhino3dm.module.js'
6464

6565
// set up loader for converting the results to threejs
6666
const loader = new Rhino3dmLoader()
67-
loader.setLibraryPath( 'https://cdn.jsdelivr.net/npm/rhino3dm@0.15.0-beta/' )
67+
loader.setLibraryPath( 'https://cdn.jsdelivr.net/npm/rhino3dm@7.14.0/rhino3dm.module.js' )
6868

6969
// initialise 'data' object that will be used by compute()
7070
const data = {

src/examples/convert/app.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
import * as THREE from 'three'
22
import { OrbitControls } from 'three/examples/jsm/controls/OrbitControls'
33
import { Rhino3dmLoader } from 'three/examples/jsm/loaders/3DMLoader'
4-
import rhino3dm from 'https://cdn.jsdelivr.net/npm/[email protected]/rhino3dm.module.js'
5-
import { RhinoCompute } from 'https://cdn.jsdelivr.net/npm/[email protected]/compute.rhino3d.module.js'
4+
import rhino3dm from 'rhino3dm'
5+
6+
//console.log(await import.meta.resolve('rhino3dm'))
7+
8+
// set up loader for converting the results to threejs
9+
const loader = new Rhino3dmLoader()
10+
loader.setLibraryPath( 'https://cdn.jsdelivr.net/npm/[email protected]/' )
611

712
let data = {}
813
data.definition = 'SampleGHConvertTo3dm.gh'
@@ -123,10 +128,6 @@ async function compute() {
123128
// load rhino doc into three.js scene
124129
const buffer = new Uint8Array(doc.toByteArray()).buffer
125130

126-
// set up loader for converting the results to threejs
127-
const loader = new Rhino3dmLoader()
128-
loader.setLibraryPath( 'https://cdn.jsdelivr.net/npm/[email protected]/' )
129-
130131
loader.parse( buffer, function ( object )
131132
{
132133
///////////////////////////////////////////////////////////////////////////

src/examples/convert/index.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@
5050
"imports": {
5151
"three": "https://unpkg.com/[email protected]/build/three.module.js",
5252
"three/examples/jsm/controls/OrbitControls": "https://unpkg.com/[email protected]/examples/jsm/controls/OrbitControls.js",
53-
"three/examples/jsm/loaders/3DMLoader": "https://unpkg.com/[email protected]/examples/jsm/loaders/3DMLoader.js"
53+
"three/examples/jsm/loaders/3DMLoader": "https://unpkg.com/[email protected]/examples/jsm/loaders/3DMLoader.js",
54+
"rhino3dm":"https://cdn.jsdelivr.net/npm/[email protected]/rhino3dm.module.js"
5455
}
5556
}
5657
</script>

src/examples/index.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ <h1>AppServer Examples</h1>
4949
<td><a href="./upload/">upload</a></td>
5050
<td>Example which shows how upload a file as input.</td>
5151
</tr>
52+
<tr>
53+
<td><a href="./valueList/">valueList</a></td>
54+
<td>Example which shows how to work with a value list as input.</td>
55+
</tr>
5256
</table>
5357
</body>
5458
</html>

src/examples/panels/script.js

Lines changed: 107 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
/* eslint no-undef: "off", no-unused-vars: "off" */
2-
import * as THREE from 'https://cdn.jsdelivr.net/npm/[email protected]/build/three.module.js'
3-
import { OrbitControls } from 'https://cdn.jsdelivr.net/npm/[email protected]/examples/jsm/controls/OrbitControls.js'
2+
import * as THREE from 'https://cdn.jsdelivr.net/npm/[email protected]/build/three.module.js'
3+
import { OrbitControls } from 'https://cdn.jsdelivr.net/npm/[email protected]/examples/jsm/controls/OrbitControls.js'
4+
import { Rhino3dmLoader } from 'https://cdn.jsdelivr.net/npm/[email protected]/examples/jsm/loaders/3DMLoader.js'
45
import rhino3dm from 'https://cdn.jsdelivr.net/npm/[email protected]/rhino3dm.module.js'
56

7+
// set up loader for converting the results to threejs
8+
const loader = new Rhino3dmLoader()
9+
loader.setLibraryPath( 'https://cdn.jsdelivr.net/npm/[email protected]/' )
10+
611
const definition = 'srf_kmeans.gh'
712

813
// setup input change events
@@ -67,9 +72,7 @@ async function compute(){
6772

6873
// Request finished. Do processing here.
6974

70-
// hide spinner
71-
document.getElementById('loader').style.display = 'none'
72-
75+
/*
7376
// process mesh
7477
let mesh_data = JSON.parse(responseJson.values[0].InnerTree['{0}'][0].data)
7578
let mesh = rhino.CommonObject.decode(mesh_data)
@@ -80,7 +83,7 @@ async function compute(){
8083
let threeMesh = meshToThreejs(mesh, _threeMaterial)
8184
mesh.delete()
8285
replaceCurrentMesh(threeMesh)
83-
86+
*/
8487
//process data
8588
//console.log(responseJson.values[1])
8689
let cluster_data = responseJson.values[1].InnerTree['{0;0}'].map(d=>d.data)
@@ -191,3 +194,101 @@ function meshToThreejs (mesh, material) {
191194
var geometry = loader.parse(mesh.toThreejsJSON())
192195
return new THREE.Mesh(geometry, material)
193196
}
197+
198+
/**
199+
* Parse response
200+
*/
201+
function collectResults(responseJson) {
202+
203+
const values = responseJson.values
204+
205+
// clear doc
206+
if( doc !== undefined)
207+
doc.delete()
208+
209+
//console.log(values)
210+
doc = new rhino.File3dm()
211+
212+
// for each output (RH_OUT:*)...
213+
for ( let i = 0; i < values.length; i ++ ) {
214+
// ...iterate through data tree structure...
215+
for (const path in values[i].InnerTree) {
216+
const branch = values[i].InnerTree[path]
217+
// ...and for each branch...
218+
for( let j = 0; j < branch.length; j ++) {
219+
// ...load rhino geometry into doc
220+
const rhinoObject = decodeItem(branch[j])
221+
if (rhinoObject !== null) {
222+
doc.objects().add(rhinoObject, null)
223+
}
224+
}
225+
}
226+
}
227+
228+
if (doc.objects().count < 1) {
229+
console.error('No rhino objects to load!')
230+
showSpinner(false)
231+
return
232+
}
233+
234+
// hack (https://github.com/mcneel/rhino3dm/issues/353)
235+
const sphereAttrs = new rhino.ObjectAttributes()
236+
sphereAttrs.mode = rhino.ObjectMode.Hidden
237+
doc.objects().addSphere(new rhino.Sphere([0,0,0], 0.001), sphereAttrs)
238+
239+
// load rhino doc into three.js scene
240+
const buffer = new Uint8Array(doc.toByteArray()).buffer
241+
loader.parse( buffer, function ( object )
242+
{
243+
// debug
244+
/*
245+
object.traverse(child => {
246+
if (child.material !== undefined)
247+
child.material = new THREE.MeshNormalMaterial()
248+
}, false)
249+
*/
250+
251+
// clear objects from scene. do this here to avoid blink
252+
scene.traverse(child => {
253+
if (!child.isLight && child.name !== 'context') {
254+
scene.remove(child)
255+
}
256+
})
257+
258+
// add object graph from rhino model to three.js scene
259+
scene.add( object )
260+
261+
// hide spinner and enable download button
262+
showSpinner(false)
263+
downloadButton.disabled = false
264+
265+
// zoom to extents
266+
zoomCameraToSelection(camera, controls, scene.children)
267+
})
268+
}
269+
270+
/**
271+
* Attempt to decode data tree item to rhino geometry
272+
*/
273+
function decodeItem(item) {
274+
const data = JSON.parse(item.data)
275+
if (item.type === 'System.String') {
276+
// hack for draco meshes
277+
try {
278+
return rhino.DracoCompression.decompressBase64String(data)
279+
} catch {} // ignore errors (maybe the string was just a string...)
280+
} else if (typeof data === 'object') {
281+
return rhino.CommonObject.decode(data)
282+
}
283+
return null
284+
}
285+
286+
/**
287+
* Shows or hides the loading spinner
288+
*/
289+
function showSpinner(enable) {
290+
if (enable)
291+
document.getElementById('loader').style.display = 'block'
292+
else
293+
document.getElementById('loader').style.display = 'none'
294+
}

src/examples/spikyThing/index.html

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,20 @@
5353
<p>Open the dev tools console to see example timings.</p>
5454
</div>
5555
</div>
56+
57+
<!-- Import maps polyfill -->
58+
<!-- Remove this when import maps will be widely supported -->
59+
<script async src="https://unpkg.com/[email protected]/dist/es-module-shims.js"></script>
60+
<script type="importmap">
61+
{
62+
"imports": {
63+
"three": "https://unpkg.com/[email protected]/build/three.module.js",
64+
"three/examples/jsm/controls/OrbitControls": "https://unpkg.com/[email protected]/examples/jsm/controls/OrbitControls.js",
65+
"three/examples/jsm/loaders/3DMLoader": "https://unpkg.com/[email protected]/examples/jsm/loaders/3DMLoader.js"
66+
}
67+
}
68+
</script>
69+
5670
<script type="module" src="./script.js"></script>
5771
</body>
5872
</html>

src/examples/spikyThing/script.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
import * as THREE from 'https://cdn.jsdelivr.net/npm/three@0.126.0/build/three.module.js'
2-
import { OrbitControls } from 'https://cdn.jsdelivr.net/npm/three@0.126.0/examples/jsm/controls/OrbitControls.js'
3-
import { Rhino3dmLoader } from 'https://cdn.jsdelivr.net/npm/three@0.126.0/examples/jsm/loaders/3DMLoader.js'
4-
import rhino3dm from 'https://cdn.jsdelivr.net/npm/rhino3dm@0.15.0-beta/rhino3dm.module.js'
1+
import * as THREE from 'three'
2+
import { OrbitControls } from 'three/examples/jsm/controls/OrbitControls'
3+
import { Rhino3dmLoader } from 'three/examples/jsm/loaders/3DMLoader'
4+
import rhino3dm from 'https://cdn.jsdelivr.net/npm/rhino3dm@7.14.0/rhino3dm.module.js'
55

66
/* eslint no-undef: "off", no-unused-vars: "off" */
77

88
const loader = new Rhino3dmLoader()
9-
loader.setLibraryPath( 'https://cdn.jsdelivr.net/npm/rhino3dm@0.15.0-beta/' )
9+
loader.setLibraryPath( 'https://cdn.jsdelivr.net/npm/rhino3dm@7.14.0/' )
1010

1111
const definition = 'BranchNodeRnd.gh'
1212

src/views/definition.hbs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,11 @@
6060
import * as THREE from 'https://cdn.jsdelivr.net/npm/[email protected]/build/three.module.js'
6161
import { OrbitControls } from 'https://cdn.jsdelivr.net/npm/[email protected]/examples/jsm/controls/OrbitControls.js'
6262
import { Rhino3dmLoader } from 'https://cdn.jsdelivr.net/npm/[email protected]/examples/jsm/loaders/3DMLoader.js'
63-
import rhino3dm from 'https://cdn.jsdelivr.net/npm/rhino3dm@0.15.0-beta/rhino3dm.module.js'
63+
import rhino3dm from 'https://cdn.jsdelivr.net/npm/rhino3dm@7.14.0/rhino3dm.module.js'
6464
6565
// set up loader for converting the results to threejs
6666
const loader = new Rhino3dmLoader()
67-
loader.setLibraryPath( 'https://cdn.jsdelivr.net/npm/rhino3dm@0.15.0-beta/' )
67+
loader.setLibraryPath( 'https://cdn.jsdelivr.net/npm/rhino3dm@7.14.0/' )
6868
6969
// initialise 'data' object that will be used by compute()
7070
const data = {

0 commit comments

Comments
 (0)