-
Notifications
You must be signed in to change notification settings - Fork 334
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
204 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import * as fs from 'fs' | ||
import rhino3dm from 'rhino3dm' | ||
|
||
const rhino = await rhino3dm() | ||
console.log('Loaded rhino3dm.') | ||
|
||
const model = new rhino.File3dm() | ||
model.applicationName = 'nodejs' | ||
model.applicationDetails = 'rhino-developer-samples' | ||
model.applicationUrl = 'https://rhino3d.com' | ||
model.startSectionComments = 'hello' | ||
|
||
const circle = new rhino.Circle(10.0) | ||
|
||
const bbox = new rhino.BoundingBox(-10,-10,0, 10,10,20) | ||
const box = new rhino.Box(bbox) | ||
const extrusion = rhino.Extrusion.createBoxExtrusion( box, false ) | ||
|
||
const objects = [] | ||
objects.push(circle.toNurbsCurve(), extrusion) | ||
|
||
const attributes = [] | ||
const oa = new rhino.ObjectAttributes() | ||
attributes.push(oa, oa) | ||
|
||
const point = [0,0,0] | ||
const index = model.instanceDefinitions().add('test', 'an idef', 'https://www.rhino3d.com', 'tag', point, objects, attributes) | ||
|
||
|
||
const idef = model.instanceDefinitions().findIndex(index) | ||
const xform = new rhino.Transform(100) | ||
const iref = new rhino.InstanceReference(idef.id, xform) | ||
model.objects().addInstanceObject(iref, null) | ||
|
||
let opts = new rhino.File3dmWriteOptions() | ||
opts.version = 8 | ||
let buffer = model.toByteArrayOptions(opts) | ||
fs.writeFileSync('idef_js.3dm', buffer) | ||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import * as fs from 'fs' | ||
import rhino3dm from 'rhino3dm' | ||
|
||
const rhino = await rhino3dm() | ||
console.log('Loaded rhino3dm.') | ||
|
||
//create model | ||
const model = new rhino.File3dm() | ||
|
||
const b = fs.readFileSync('./rhinologo.png'); | ||
const a = new Uint8Array(b) | ||
|
||
const ef = rhino.EmbeddedFile.fromByteArray(a) | ||
console.log(ef.length) | ||
|
||
const ef_fileName = 'rhinologo.png' | ||
ef.fileName = ef_fileName | ||
console.log('Filename: ' + ef.fileName) | ||
model.embeddedFiles().add(ef) | ||
|
||
console.log('how many embedded files: ' + model.embeddedFiles().count) | ||
|
||
const texture = new rhino.Texture() | ||
texture.fileName = ef_fileName | ||
|
||
const material = new rhino.Material() | ||
material.toPhysicallyBased() | ||
material.physicallyBased().baseColor = { r: 1, g: 0, b: 0, a: 0 } | ||
material.physicallyBased().metallic = 0.7 | ||
material.physicallyBased().roughness = 0.5 | ||
material.setBitmapTexture(texture) | ||
|
||
const index = model.materials().add(material) | ||
|
||
const sphere = rhino.Brep.createFromSphere( new rhino.Sphere( [ 0,0,0 ], 10 ) ) | ||
|
||
const oa = new rhino.ObjectAttributes() | ||
oa.materialSource = rhino.ObjectMaterialSource.MaterialFromObject | ||
oa.materialIndex = index | ||
|
||
model.objects().add(sphere, oa) | ||
|
||
//save model | ||
let opts = new rhino.File3dmWriteOptions() | ||
opts.version = 8 | ||
let buffer = model.toByteArrayOptions(opts) | ||
fs.writeFileSync('materialWithEmbeddedFile_js.3dm', buffer) |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{ | ||
"name": "samples", | ||
"version": "0.0.1", | ||
"description": "rhino3dm.js samples to run in node", | ||
"main": "index.js", | ||
"type": "module", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"keywords": [ | ||
"rhino3dm" | ||
], | ||
"author": "Luis E. Fraguada", | ||
"license": "MIT", | ||
"dependencies": { | ||
"rhino3dm": "8.6.0" | ||
} | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#requires rhino3dm.py >= 8.6.0 | ||
import rhino3dm | ||
|
||
model = rhino3dm.File3dm() | ||
model.ApplicationName = 'python' | ||
model.ApplicationDetails = 'rhino-developer-samples' | ||
model.ApplicationUrl = 'https://rhino3d.com' | ||
|
||
# create objects to be in instance definition | ||
circle = rhino3dm.Circle(10) | ||
|
||
bbox = rhino3dm.BoundingBox(-10,-10,0, 10,10,20) | ||
box = rhino3dm.Box(bbox) | ||
extrusion = rhino3dm.Extrusion.CreateBoxExtrusion(box, False) #this extrusion is fine | ||
|
||
objects = [circle.ToNurbsCurve(), extrusion] #objects need to derive from GeometryBase, hence circle.ToNurbsCurve() | ||
|
||
#create the instance definition | ||
oa = rhino3dm.ObjectAttributes() | ||
attributes = [oa, oa] | ||
p1 = rhino3dm.Point3d(0,0,0) | ||
#index = model.InstanceDefinitions.AddInstanceDefinition('test', 'an idef', 'https://www.rhino3d.com', 'tag', p1, objects, attributes) | ||
|
||
index = model.InstanceDefinitions.AddInstanceDefinition2( 'test', 'an idef', 'https://www.rhino3d.com', 'tag', p1,(circle.ToNurbsCurve(), extrusion), (oa, oa) ) | ||
|
||
#add a reference to the Instance Definition to the model | ||
idef = model.InstanceDefinitions.FindIndex(index) | ||
xform = rhino3dm.Transform(100) | ||
iref = rhino3dm.InstanceReference(idef.Id, xform) | ||
model.Objects.AddInstanceObject(iref) | ||
|
||
model.Write("idef_py.3dm", 0) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import rhino3dm | ||
|
||
model = rhino3dm.File3dm() | ||
|
||
ef = rhino3dm.EmbeddedFile.Read2('./rhinologo.png') | ||
print('FileName: ' + ef.Filename) | ||
ef.Filename = 'rhinologo.png' | ||
print('FileName: ' + ef.Filename) | ||
model.EmbeddedFiles.Add(ef) | ||
|
||
print('How many embedded files: ' + str(len(model.EmbeddedFiles))) | ||
|
||
material = rhino3dm.Material() | ||
material.SetBitmapTexture('rhinologo.png') | ||
index = model.Materials.Add(material) | ||
|
||
oa = rhino3dm.ObjectAttributes() | ||
oa.MaterialSource = rhino3dm.ObjectMaterialSource.MaterialFromObject | ||
oa.MaterialIndex = index | ||
|
||
sphere = rhino3dm.Sphere(rhino3dm.Point3d(0,0,0), 10) | ||
brep = rhino3dm.Brep.CreateFromSphere(sphere) | ||
model.Objects.Add(brep, oa) | ||
|
||
model.Write("material.3dm", 0) |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.