improvement(viewer): removes hot try catch (keeps conversion stub as commented code)
This commit is contained in:
@@ -223,7 +223,7 @@ export default class Coverter {
|
||||
let v = this.PointToVector3( obj )
|
||||
console.log( 'Point to buffer', obj )
|
||||
let buf = new THREE.BufferGeometry().setFromPoints( [ v ] )
|
||||
|
||||
|
||||
delete obj.value
|
||||
delete obj.speckle_type
|
||||
delete obj.bbox
|
||||
@@ -244,7 +244,7 @@ export default class Coverter {
|
||||
delete object.end
|
||||
delete object.speckle_type
|
||||
delete object.bbox
|
||||
|
||||
|
||||
const geometry = new THREE.BufferGeometry().setFromPoints( [ this.PointToVector3( obj.start ), this.PointToVector3( obj.end ) ] )
|
||||
|
||||
return new ObjectWrapper( geometry, obj, 'line' )
|
||||
@@ -253,22 +253,22 @@ export default class Coverter {
|
||||
async PolylineToBufferGeometry( object ) {
|
||||
let obj = {}
|
||||
Object.assign( obj,object )
|
||||
|
||||
|
||||
delete object.value
|
||||
delete object.speckle_type
|
||||
delete object.bbox
|
||||
|
||||
let conversionFactor = getConversionFactor( obj.units )
|
||||
|
||||
|
||||
obj.value = await this.dechunk( obj.value )
|
||||
|
||||
|
||||
const points = []
|
||||
for ( let i = 0; i < obj.value.length; i+=3 ) {
|
||||
points.push( new THREE.Vector3( obj.value[i]* conversionFactor,obj.value[i+1]* conversionFactor,obj.value[i+2] * conversionFactor ) )
|
||||
}
|
||||
if ( obj.closed )
|
||||
points.push( points[0] )
|
||||
|
||||
|
||||
const geometry = new THREE.BufferGeometry().setFromPoints( points )
|
||||
|
||||
delete obj.value
|
||||
@@ -280,7 +280,7 @@ export default class Coverter {
|
||||
async PolycurveToBufferGeometry( object ) {
|
||||
let obj = {}
|
||||
Object.assign( obj,object )
|
||||
|
||||
|
||||
delete object.value
|
||||
delete object.speckle_type
|
||||
delete object.displayValue
|
||||
@@ -294,16 +294,16 @@ export default class Coverter {
|
||||
buffers.push( conv?.bufferGeometry )
|
||||
}
|
||||
let geometry = BufferGeometryUtils.mergeBufferGeometries( buffers )
|
||||
|
||||
|
||||
delete obj.segments
|
||||
delete obj.speckle_type
|
||||
delete obj.bbox
|
||||
|
||||
return new ObjectWrapper( geometry , obj, 'line' )
|
||||
}
|
||||
|
||||
|
||||
async CurveToBufferGeometry( object ) {
|
||||
|
||||
|
||||
let obj = {}
|
||||
Object.assign( obj,object )
|
||||
|
||||
@@ -316,64 +316,58 @@ export default class Coverter {
|
||||
obj.knots = await this.dechunk( object.knots )
|
||||
obj.points = await this.dechunk( object.points )
|
||||
|
||||
try {
|
||||
console.log( 'Curve to buffer', object, obj )
|
||||
// NOTE: We're currently falling back on the
|
||||
// throw new Error( 'Skipping nurbs for displayValue due to lack of support in THREE.js of some nurbs types' )
|
||||
|
||||
//TODO: This should be removed when we improve the nurbs curve's in THREE.js (or make our own).
|
||||
throw new Error( 'Skipping nurbs for displayValue due to lack of support in THREE.js of some nurbs types' )
|
||||
|
||||
let conversionFactor = getConversionFactor( obj.units )
|
||||
|
||||
// Convert points+weights to Vector4
|
||||
const points = []
|
||||
for ( let i = 0; i < obj.points.length; i+=3 ) {
|
||||
points.push( new THREE.Vector4( obj.points[ i ]* conversionFactor,obj.points[i+1]* conversionFactor,obj.points[i+2] * conversionFactor, obj.weights[i/3] ) )
|
||||
}
|
||||
// let conversionFactor = getConversionFactor( obj.units )
|
||||
|
||||
let knots = []
|
||||
if ( obj.knots.length != ( obj.points.length/3 + obj.degree + 1 ) ) {
|
||||
// Convert knots from rhino compact format to normal format.
|
||||
let knots = [ obj.knots[0] ]
|
||||
knots = knots.concat( obj.knots )
|
||||
knots.push( knots[knots.length -1] )
|
||||
}
|
||||
else {
|
||||
knots = obj.knots
|
||||
}
|
||||
// // Convert points+weights to Vector4
|
||||
// const points = []
|
||||
// for ( let i = 0; i < obj.points.length; i+=3 ) {
|
||||
// points.push( new THREE.Vector4( obj.points[ i ]* conversionFactor,obj.points[i+1]* conversionFactor,obj.points[i+2] * conversionFactor, obj.weights[i/3] ) )
|
||||
// }
|
||||
|
||||
// Create the nurbs curve
|
||||
const curve = new NURBSCurve( obj.degree, knots, points, null, null )
|
||||
|
||||
// Delete everything unnecessary from the metadata object.
|
||||
delete obj.speckle_type
|
||||
delete obj.displayValue
|
||||
delete obj.points
|
||||
delete obj.weights
|
||||
delete obj.knots
|
||||
|
||||
// Compute appropriate curve subdivisions
|
||||
let div = curve.getLength() / 0.1
|
||||
div = parseInt( div.toString() )
|
||||
if ( div < 20 ) div = 20
|
||||
if ( div > 4000 ) div = 4000
|
||||
// let knots = []
|
||||
// if ( obj.knots.length != ( obj.points.length/3 + obj.degree + 1 ) ) {
|
||||
// // Convert knots from rhino compact format to normal format.
|
||||
// let knots = [ obj.knots[0] ]
|
||||
// knots = knots.concat( obj.knots )
|
||||
// knots.push( knots[knots.length -1] )
|
||||
// }
|
||||
// else {
|
||||
// knots = obj.knots
|
||||
// }
|
||||
|
||||
// Divide the nurbs curve in points
|
||||
var pts = curve.getPoints( div )
|
||||
return new ObjectWrapper( new THREE.BufferGeometry().setFromPoints( pts ), obj, 'line' )
|
||||
// // Create the nurbs curve
|
||||
// const curve = new NURBSCurve( obj.degree, knots, points, null, null )
|
||||
|
||||
} catch ( e ) {
|
||||
console.warn( 'Error converting nurbs curve, falling back to displayValue', obj )
|
||||
const poly = await this.PolylineToBufferGeometry( obj.displayValue )
|
||||
// // Delete everything unnecessary from the metadata object.
|
||||
// delete obj.speckle_type
|
||||
// delete obj.displayValue
|
||||
// delete obj.points
|
||||
// delete obj.weights
|
||||
// delete obj.knots
|
||||
|
||||
delete obj.speckle_type
|
||||
delete obj.displayValue
|
||||
delete obj.points
|
||||
delete obj.weights
|
||||
delete obj.knots
|
||||
delete obj.bbox
|
||||
|
||||
return new ObjectWrapper( poly.bufferGeometry, obj, 'line' )
|
||||
}
|
||||
// // Compute appropriate curve subdivisions
|
||||
// let div = curve.getLength() / 0.1
|
||||
// div = parseInt( div.toString() )
|
||||
// if ( div < 20 ) div = 20
|
||||
// if ( div > 4000 ) div = 4000
|
||||
|
||||
// // Divide the nurbs curve in points
|
||||
// var pts = curve.getPoints( div )
|
||||
// return new ObjectWrapper( new THREE.BufferGeometry().setFromPoints( pts ), obj, 'line' )
|
||||
|
||||
const poly = await this.PolylineToBufferGeometry( obj.displayValue )
|
||||
|
||||
delete obj.speckle_type
|
||||
delete obj.displayValue
|
||||
delete obj.points
|
||||
delete obj.weights
|
||||
delete obj.knots
|
||||
delete obj.bbox
|
||||
|
||||
return new ObjectWrapper( poly.bufferGeometry, obj, 'line' )
|
||||
}
|
||||
|
||||
async CircleToBufferGeometry( obj ) {
|
||||
@@ -387,7 +381,7 @@ export default class Coverter {
|
||||
|
||||
return new ObjectWrapper( geometry, obj, 'line' )
|
||||
}
|
||||
|
||||
|
||||
|
||||
async ArcToBufferGeometry( obj ) {
|
||||
const points = this.getCircularCurvePoints( obj.plane, obj.radius, obj.startAngle, obj.endAngle )
|
||||
@@ -429,7 +423,7 @@ export default class Coverter {
|
||||
}
|
||||
|
||||
async EllipseToBufferGeometry( obj ) {
|
||||
|
||||
|
||||
const center = new THREE.Vector3( obj.plane.origin.value[0],obj.plane.origin.value[1],obj.plane.origin.value[2] )
|
||||
const xAxis = new THREE.Vector3( obj.plane.xdir.value[0],obj.plane.xdir.value[1],obj.plane.xdir.value[2] )
|
||||
const yAxis = new THREE.Vector3( obj.plane.ydir.value[0],obj.plane.ydir.value[1],obj.plane.ydir.value[2] )
|
||||
@@ -444,7 +438,7 @@ export default class Coverter {
|
||||
let y = Math.sin( t ) * obj.radius2
|
||||
const xMove = new THREE.Vector3( xAxis.x * x, xAxis.y * x, xAxis.z * x )
|
||||
const yMove = new THREE.Vector3( yAxis.x * y, yAxis.y * y, yAxis.z * y )
|
||||
|
||||
|
||||
let pt = new THREE.Vector3().addVectors( xMove, yMove ).add( center )
|
||||
points.push( pt )
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user