{
var scene = new THREE.Scene();
var wdth = 900
var hght = 900
var camera = new THREE.PerspectiveCamera( 60, wdth/hght, 1, 1000 );
camera.position.set( 20, -20, 20 );
var renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setSize( wdth, hght );
renderer.setPixelRatio( window.devicePixelRatio );
renderer.outputEncoding = THREE.sRGBEncoding;
console.log(window.innerHeight)
const controls = new oc.OrbitControls(camera, renderer.domElement);
var foot
let rhino
rhino3dm.default().then(async m => {
rhino = m
create()
})
const parent = new THREE.Object3D();
const manager = new THREE.LoadingManager();
/*
const loader = new THREE.OBJLoader( manager );
loader.load( obj_url, function ( obj ) {
foot = obj
})
*/
//foot.position.set(5,5,5)
const RLoader = new RL.Rhino3dmLoader();
//RLoader.setLibraryPath('https://cdn.jsdelivr.net/npm/rhino3dm@0.15.0-beta/')
RLoader.setLibraryPath('https://cdn.jsdelivr.net/npm/rhino3dm@0.15.0-beta/')
RLoader.load(rh_url,
function(object){
scene.add(object)
},function ( xhr ) {
console.log( ( xhr.loaded / xhr.total * 100 ) + '% loaded' );
},
)
const directionalLight = new THREE.DirectionalLight( 0xffffff, 2 );
directionalLight.position.set( 0, 0, 2 );
scene.add( directionalLight );
/*
RLoader.load(foot1,
function ( object ) {
scene.add( object );
},
/*function ( xhr ) {
console.log( ( xhr.loaded / xhr.total * 100 ) + '% loaded' );
},
// called when loading has errors
console.log("helllo"),
function ( error ) {
console.log( 'An error happened' );
}
)
*/
//const loader = new Rhino3dmLoader();
//loader.setLibraryPath( 'https://cdn.jsdelivr.net/npm/rhino3dm@0.15.0-beta/' );
function create () {
//doc = new rhino.File3dm()
const loader = new THREE.BufferGeometryLoader();
/*
// -- POINTS / POINTCLOUDS -- //
// POINTS
*/
let ptA = [2, 2, 0]
const geometry = new THREE.BufferGeometry()
const vertices = new Float32Array( ptA )
geometry.setAttribute( 'position', new THREE.BufferAttribute( vertices, 3 ) )
const pointsMaterial = new THREE.PointsMaterial( { color: 0x00ff00 } )
const threejsPoint = new THREE.Points( geometry, pointsMaterial )
scene.add(threejsPoint)
//doc.objects().addPoint(ptA)
//const ptA = [10, 10, 0]
const ptB = [10, 0, 0]
const ptC = [10, 10, 0]
const ptD = [0, 10, 0]
const ptE = [ 20, 20, 20]
const ptF = [30, 0, 0]
const ptG = [35, 5, 0]
const ptH = [40, -5, 0]
const ptI = [45, 5, 0]
const ptJ = [50, 0, 0]
/*
const red = { r: 255, g: 0, b: 0, a: 0 }
const pointCloud = new rhino.PointCloud()
pointCloud.add( ptA, red )
pointCloud.add( ptB, red )
pointCloud.add( ptC, red )
pointCloud.add( ptD, red )
pointCloud.add( ptE, red )
pointCloud.add( ptF, red )
pointCloud.add( ptG, red )
pointCloud.add( ptH, red )
pointCloud.add( ptI, red )
pointCloud.add( ptJ, red )
*/
//const threejsPointsGeometry = loader.parse ( pointCloud.toThreejsJSON() )
//const threejsPoints = new THREE.Points( threejsPointsGeometry, pointsMaterial )
//scene.add( threejsPoints )
const line = new rhino.LineCurve( [0,4,2], [5,0,0] )
//console.log(line.isPolyline())
const line4 = line.duplicate()
line4.translate([0,3,0])
const lineGeometry = new THREE.BufferGeometry()
const lineVertices = new Float32Array( line.line.from.concat( line.line.to ) )
lineGeometry.setAttribute( 'position', new THREE.BufferAttribute( lineVertices, 3 ) )
const lineMaterial = new THREE.LineBasicMaterial( { color: 0x00ff00 } )
const lineObject = new THREE.Line( lineGeometry, lineMaterial )
scene.add( lineObject )
const line2 = new rhino.LineCurve( [-5,4,2], [5,4,0] )
const lineGeometry2 = new THREE.BufferGeometry()
const lineVertices2 = new Float32Array( line2.line.from.concat( line2.line.to ) )
lineGeometry2.setAttribute( 'position', new THREE.BufferAttribute( lineVertices2, 3 ) )
const lineMaterial2 = new THREE.LineBasicMaterial( { color: 0x00ff00 } )
const lineObject2 = new THREE.Line( lineGeometry2, lineMaterial2 )
scene.add( lineObject2 )
const lineGeometry4 = new THREE.BufferGeometry()
const lineVertices4 = new Float32Array( line4.line.from.concat( line4.line.to ) )
lineGeometry4.setAttribute( 'position', new THREE.BufferAttribute( lineVertices4, 3 ) )
const lineMaterial4 = new THREE.LineBasicMaterial( { color: 0x00ff00 } )
const lineObject4 = new THREE.Line( lineGeometry4, lineMaterial4 )
scene.add( lineObject4 )
for (let i = .1; i < 1; i=i+.1) {
var line5 = line4.duplicate()
line5.translate([0,1*i,0])
const lineGeometry5 = new THREE.BufferGeometry()
const lineVertices5 = new Float32Array( line5.line.from.concat( line5.line.to ) )
lineGeometry5.setAttribute( 'position', new THREE.BufferAttribute( lineVertices5, 3 ) )
const lineMaterial5 = new THREE.LineBasicMaterial( { color: 0x00ff00 } )
const lineObject5 = new THREE.Line( lineGeometry5, lineMaterial5 )
scene.add( lineObject5 )
}
//console.log(Math.random())
var points = []
for (let i = 0; i < 5; i++) {
//console.log(i)
//var pt1 = new rhino.Point([5-(Math.random()*10),5-(Math.random()*10),0])
var pt1 = new rhino.Point([Math.random()*2,Math.random()*2,0])
//console.log(pt1.location[0])
points.push(pt1.location)
const geometry = new THREE.BufferGeometry()
const vertices = new Float32Array( pt1.location )
geometry.setAttribute( 'position', new THREE.BufferAttribute( vertices, 3 ) )
const pointsMaterial = new THREE.PointsMaterial( { color: 0x00ff00 } )
const threejsPoint = new THREE.Points( geometry, pointsMaterial )
scene.add(threejsPoint)
}
var lines = []
for (let i = 0; i < points.length; i++) {
for (let n = 0; n < points.length; n++) {
if(i!=n){
var dist = Distance(points[i],points[n])
//console.log(dist)
if(dist>1.5){
const line = new rhino.LineCurve(points[i], points[n] )
lines.push(line)
const lineGeometry = new THREE.BufferGeometry()
const lineVertices = new Float32Array( line.line.from.concat( line.line.to ) )
lineGeometry.setAttribute( 'position', new THREE.BufferAttribute( lineVertices, 3 ) )
const lineMaterial = new THREE.LineBasicMaterial( { color: 0x00ff00 } )
const lineObject = new THREE.Line( lineGeometry, lineMaterial )
scene.add( lineObject )
}
}
}
}
const circle = new rhino.Circle( 5 )
const circleGeometry = new THREE.RingGeometry( circle.radius, circle.radius, 32 )
const circleObject = new THREE.Line( circleGeometry, lineMaterial )
circleObject.position.fromArray( circle.center )
scene.add( circleObject )
/*
const mesh = new rhino.Mesh()
mesh.vertices().add( ptA[0], ptA[1], ptA[2] )
mesh.vertices().add( ptB[0], ptB[1], ptB[2] )
mesh.vertices().add( ptC[0], ptC[1], ptC[2] )
mesh.faces().addFace( 0, 1, 2 )
mesh.vertexColors().add( 255, 0, 255 )
mesh.vertexColors().add( 0, 255, 255 )
mesh.vertexColors().add( 255, 255, 255 )
mesh.normals().computeNormals()
const meshGeometry = loader.parse ( mesh.toThreejsJSON() )
const meshMaterial = new THREE.MeshBasicMaterial( { color: 0x00fff0 } );
const threejsMesh = new THREE.Mesh( meshGeometry, meshMaterial )
scene.add( threejsMesh )
*/
//rhino.Curve.LcoalClosestPoint(line, testPoint)
//var length = RhinoCompute.Curve.getLength(line)
//console.log(length)
//line.toJSON()
// Instantiate a loader to import from rhino
//const rhinoloader = new THREE.Rhino3dmLoader();
//const loader888 = new FontLoader();
//const loader6666 = new Rhino3dmLoader();
//const loader5 = new
//var cam = new THREE.Loader
//var rl = new THREE.LoadingManager
//loader6666.setLibraryPath( 'https://cdn.jsdelivr.net/npm/rhino3dm@0.15.0-beta/' );
/*
// Load a 3DM file
loader6666.load(
// resource URL
FileAttachment("import.3dm"),
// called when the resource is loaded
function ( object ) {
scene.add( object );
},
// called as loading progresses
function ( xhr ) {
console.log( ( xhr.loaded / xhr.total * 100 ) + '% loaded' );
},
// called when loading has errors
function ( error ) {
console.log( 'An error happened' );
}
);
*/
}
/*
var geometry = new THREE.BoxGeometry( 1, 1, 1 );
var material = new THREE.MeshBasicMaterial( { color: 0xf0ff00 } );
var cube = new THREE.Mesh( geometry, material );
scene.add( cube );
*/
//renderer.render( scene, camera );
//scene.add(foot)
var animate = function () {
requestAnimationFrame( animate );
//cube.rotation.x += 0.01;
//cube.rotation.y += 0.01;
renderer.render( scene, camera );
};
//camera.position.z = 60;
//renderer.render( scene, camera );
animate();
//yield renderer.domElement;
yield renderer.domElement;
//renderer.render( scene, camera );
}