@@ -22,6 +22,7 @@ import { TransformControls } from 'three/examples/jsm/controls/TransformControls
22
22
import { GLTFExporter } from 'three/examples/jsm/exporters/GLTFExporter.js' ;
23
23
import { STLLoader } from 'three/examples/jsm/loaders/STLLoader' ;
24
24
import { ViewHelper } from 'three/examples/jsm/helpers/ViewHelper' ;
25
+ import { IParsedShape } from '@jupytercad/schema' ;
25
26
26
27
import { FloatingAnnotation } from '../annotation' ;
27
28
import { getCSSVariableColor , throttle } from '../tools' ;
@@ -996,38 +997,65 @@ export class MainView extends React.Component<IProps, IStates> {
996
997
postResult : IPostResult
997
998
) : Promise < void > {
998
999
const { binary, format, value } = postResult ;
999
- let obj : THREE . BufferGeometry | undefined = undefined ;
1000
- if ( format === 'STL' ) {
1001
- let buff : string | ArrayBuffer ;
1002
- if ( binary ) {
1003
- const str = `data:application/octet-stream;base64,${ value } ` ;
1004
- const b = await fetch ( str ) ;
1005
- buff = await b . arrayBuffer ( ) ;
1006
- } else {
1007
- buff = value ;
1008
- }
1009
- const loader = new STLLoader ( ) ;
1010
- obj = loader . parse ( buff ) ;
1000
+ if ( format !== 'STL' ) {
1001
+ return ;
1002
+ }
1003
+ let buff : string | ArrayBuffer ;
1004
+ if ( binary ) {
1005
+ const str = `data:application/octet-stream;base64,${ value } ` ;
1006
+ const b = await fetch ( str ) ;
1007
+ buff = await b . arrayBuffer ( ) ;
1008
+ } else {
1009
+ buff = value ;
1011
1010
}
1011
+ const loader = new STLLoader ( ) ;
1012
+ const geometry = loader . parse ( buff ) ;
1012
1013
1013
- if ( ! obj ) {
1014
+ if ( ! geometry ) {
1014
1015
return ;
1015
1016
}
1016
1017
1017
- const material = new THREE . MeshPhongMaterial ( {
1018
- color : DEFAULT_MESH_COLOR ,
1019
- wireframe : this . state . wireframe
1018
+ const parsedShape : IParsedShape = {
1019
+ jcObject : { name : 'example' , visible : true } ,
1020
+ faceList : [ ] ,
1021
+ edgeList : [ ]
1022
+ } ;
1023
+
1024
+ const obj = this . _model . sharedModel . getObjectByName ( name ) ;
1025
+ const objColor = obj ?. parameters ?. Color ;
1026
+ const isWireframe = this . state . wireframe ;
1027
+
1028
+ const output = buildShape ( {
1029
+ objName : name ,
1030
+ data : parsedShape ,
1031
+ clippingPlanes : this . _clippingPlanes ,
1032
+ isSolid : true ,
1033
+ isWireframe,
1034
+ objColor
1020
1035
} ) ;
1021
- const mesh = new THREE . Mesh ( obj , material ) ;
1022
-
1023
- const lineGeo = new THREE . WireframeGeometry ( mesh . geometry ) ;
1024
- const mat = new THREE . LineBasicMaterial ( { color : 'black' } ) ;
1025
- const wireframe = new THREE . LineSegments ( lineGeo , mat ) ;
1026
- mesh . add ( wireframe ) ;
1027
- mesh . name = name ;
1028
- if ( this . _meshGroup ) {
1029
- this . _meshGroup . add ( mesh ) ;
1030
- this . _boundingGroup ?. expandByObject ( mesh ) ;
1036
+
1037
+ if ( output ) {
1038
+ const { meshGroup, mainMesh, edgesMeshes } = output ;
1039
+
1040
+ if ( meshGroup . userData . jcObject . visible ) {
1041
+ this . _boundingGroup ?. expandByObject ( meshGroup ) ;
1042
+ }
1043
+
1044
+ if ( mainMesh . material ?. color ) {
1045
+ const originalMeshColor = new THREE . Color (
1046
+ objColor || DEFAULT_MESH_COLOR
1047
+ ) ;
1048
+ mainMesh . material . color = originalMeshColor ;
1049
+ mainMesh . userData . originalColor = originalMeshColor . clone ( ) ;
1050
+ }
1051
+
1052
+ edgesMeshes . forEach ( edgeMesh => {
1053
+ this . _edgeMaterials . push ( edgeMesh . material ) ;
1054
+ const edgeColor = new THREE . Color ( objColor || DEFAULT_EDGE_COLOR ) ;
1055
+ edgeMesh . material . color = edgeColor ;
1056
+ } ) ;
1057
+
1058
+ this . _meshGroup ?. add ( meshGroup ) ;
1031
1059
}
1032
1060
this . _updateRefLength ( true ) ;
1033
1061
}
0 commit comments