Skip to content

Commit

Permalink
rhino3dm.js sample - change brep cylinder to extrusion
Browse files Browse the repository at this point in the history
  • Loading branch information
fraguada committed Oct 15, 2024
1 parent 083bca9 commit 7a8e6f0
Showing 1 changed file with 7 additions and 12 deletions.
19 changes: 7 additions & 12 deletions rhino3dm/js/SampleJSMakeBrep/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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 ] )

Expand All @@ -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
Expand All @@ -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 } )
Expand All @@ -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

Expand All @@ -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 //
Expand All @@ -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)
Expand Down

0 comments on commit 7a8e6f0

Please sign in to comment.