From 7a8e6f05428736d152745f2fe1364f273587b93f Mon Sep 17 00:00:00 2001 From: fraguada Date: Tue, 15 Oct 2024 16:42:43 +0200 Subject: [PATCH] rhino3dm.js sample - change brep cylinder to extrusion --- rhino3dm/js/SampleJSMakeBrep/script.js | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/rhino3dm/js/SampleJSMakeBrep/script.js b/rhino3dm/js/SampleJSMakeBrep/script.js index 4ed9db80..d25273f6 100644 --- a/rhino3dm/js/SampleJSMakeBrep/script.js +++ b/rhino3dm/js/SampleJSMakeBrep/script.js @@ -126,7 +126,7 @@ function createObject(objectType) { downloadButton.disabled = false let geometry - let rhinoObject, rhinoMesh, result, xform + let rhinoObject, rhinoMesh, result const oa = new rhino.ObjectAttributes() oa.materialSource = rhino.ObjectMaterialSource.MaterialFromLayer @@ -139,6 +139,7 @@ function createObject(objectType) { const x = Math.random() * xDim * (Math.random() > 0.5 ? 1 : - 1) const y = Math.random() * yDim * (Math.random() > 0.5 ? 1 : - 1) const z = Math.random() * zDim * (Math.random() > 0.5 ? 1 : - 1) + const xform = rhino.Transform.translationXYZ(x, y, z) console.log( [ x, y, z ] ) @@ -150,10 +151,10 @@ function createObject(objectType) { geometry = new THREE.SphereGeometry( dim, 32, 32 ) geometry.translate( x, z, -y ) - rhinoMesh = rhino.Mesh.createFromThreejsJSON( { data: geometry } ) - const sphere = new rhino.Sphere( [ x, y, z ], dim ) rhinoObject = rhino.Brep.createFromSphere( sphere ) + + rhinoMesh = rhino.Mesh.createFromThreejsJSON( { data: geometry } ) result = rhinoObject.faces().get(0).setMesh( rhinoMesh, rhino.MeshType.Render ) oa.layerIndex = brep_layer_index @@ -169,8 +170,6 @@ function createObject(objectType) { const rhinoBox = new rhino.Box( new rhino.BoundingBox( [ -halfDim, -halfDim, -halfDim ], [ halfDim, halfDim, halfDim ] ) ) rhinoObject = rhino.Extrusion.createBoxExtrusion( rhinoBox, true ) - - xform = rhino.Transform.translationXYZ(x, y, z) rhinoObject.transform( xform ) rhinoMesh = rhino.Mesh.createFromThreejsJSON( { data: geometry } ) @@ -189,10 +188,11 @@ function createObject(objectType) { const circle = new rhino.Circle([ x, y, z ], dim) const cylinder = new rhino.Cylinder(circle, dim) - rhinoObject = rhino.Brep.createFromCylinder( cylinder, true, true ) + rhinoObject = rhino.Extrusion.createCylinderExtrusion( cylinder, true, true ) + rhinoObject.transform( xform ) rhinoMesh = rhino.Mesh.createFromThreejsJSON( { data: geometry } ) - result = rhinoObject.faces().get(0).setMesh( rhinoMesh, rhino.MeshType.Render ) + result = rhinoObject.setMesh( rhinoMesh, rhino.MeshType.Render ) oa.layerIndex = cyl_layer_index @@ -201,14 +201,11 @@ function createObject(objectType) { break } - - const mesh = new THREE.Mesh(geometry, material) scene.add(mesh) doc.objects().add( rhinoObject, oa) - } // #endregion CREATE // @@ -221,8 +218,6 @@ function createObject(objectType) { function init() { - THREE.Object3D.DEFAULT_UP = new THREE.Vector3(0,0,1) - renderer = new THREE.WebGLRenderer({ antialias: true }) renderer.setPixelRatio(window.devicePixelRatio) renderer.setSize(window.innerWidth, window.innerHeight)