@@ -109,7 +109,7 @@ function parse(gltf, { fileName = 'model', ...options } = {}) {
109
109
const types = [ ...new Set ( [ ...meshes , ...bones ] . map ( ( o ) => getType ( o ) ) ) ]
110
110
const contextType = `type ContextType = Record<string, React.ForwardRefExoticComponent<
111
111
${ types . map ( ( type ) => `JSX.IntrinsicElements['${ type } ']` ) . join ( ' | ' ) }
112
- >>` ;
112
+ >>`
113
113
114
114
return `\ntype GLTFResult = GLTF & {
115
115
nodes: {
@@ -339,7 +339,7 @@ function parse(gltf, { fileName = 'model', ...options } = {}) {
339
339
}
340
340
341
341
// Bail out on lights and bones
342
- if ( type === 'bone' ) {
342
+ if ( ! options . bones && type === 'bone' ) {
343
343
return `<primitive object={${ node } } />`
344
344
}
345
345
@@ -356,7 +356,8 @@ function parse(gltf, { fileName = 'model', ...options } = {}) {
356
356
result = `<instancedMesh args={[${ geo } , ${ mat } , ${ ! obj . count ? `${ node } .count` : obj . count } ]} `
357
357
} else {
358
358
// Form the object in JSX syntax
359
- result = `<${ type } `
359
+ if ( type === 'bone' ) result = `<primitive object={${ node } } `
360
+ else result = `<${ type } `
360
361
}
361
362
}
362
363
@@ -374,7 +375,10 @@ function parse(gltf, { fileName = 'model', ...options } = {}) {
374
375
result += `${ children . length ? '>' : '/>' } \n`
375
376
376
377
// Add children and return
377
- if ( children . length ) result += children + `</${ type } >`
378
+ if ( children . length ) {
379
+ if ( type === 'bone' ) result += children + `</primitive>`
380
+ else result += children + `</${ type } >`
381
+ }
378
382
return result
379
383
}
380
384
@@ -445,8 +449,8 @@ ${parseExtras(gltf.parser.json.asset && gltf.parser.json.asset.extras)}*/`
445
449
const result = `${ options . types ? `\nimport * as THREE from 'three'` : '' }
446
450
import React, { useRef ${ hasInstances ? ', useMemo, useContext, createContext' : '' } } from 'react'
447
451
import { useGLTF, ${ hasInstances ? 'Merged, ' : '' } ${
448
- scene . includes ( 'PerspectiveCamera' ) ? 'PerspectiveCamera,' : ''
449
- }
452
+ scene . includes ( 'PerspectiveCamera' ) ? 'PerspectiveCamera,' : ''
453
+ }
450
454
${ scene . includes ( 'OrthographicCamera' ) ? 'OrthographicCamera,' : '' }
451
455
${ hasAnimations ? 'useAnimations' : '' } } from '@react-three/drei'
452
456
${ options . types ? 'import { GLTF } from "three-stdlib"' : '' }
@@ -458,16 +462,18 @@ ${parseExtras(gltf.parser.json.asset && gltf.parser.json.asset.extras)}*/`
458
462
const context = createContext(${ options . types ? '{} as ContextType' : '' } )
459
463
export function Instances({ children, ...props }${ options . types ? ': JSX.IntrinsicElements["group"]' : '' } ) {
460
464
const { nodes } = useGLTF('${ url } '${ options . draco ? `, ${ JSON . stringify ( options . draco ) } ` : '' } )${
461
- options . types ? ' as GLTFResult' : ''
462
- }
465
+ options . types ? ' as GLTFResult' : ''
466
+ }
463
467
const instances = useMemo(() => ({
464
468
${ Object . values ( duplicates . geometries )
465
469
. map ( ( v ) => `${ v . name } : ${ v . node } ` )
466
470
. join ( ', ' ) }
467
471
}), [nodes])
468
472
return (
469
473
<Merged meshes={instances} {...props}>
470
- {(instances${ options . types ? ': ContextType' : '' } ) => <context.Provider value={instances} children={children} />}
474
+ {(instances${
475
+ options . types ? ': ContextType' : ''
476
+ } ) => <context.Provider value={instances} children={children} />}
471
477
</Merged>
472
478
)
473
479
}
@@ -476,17 +482,17 @@ ${parseExtras(gltf.parser.json.asset && gltf.parser.json.asset.extras)}*/`
476
482
}
477
483
478
484
export ${ options . exportdefault ? 'default' : '' } function Model(props${
479
- options . types ? ": JSX.IntrinsicElements['group']" : ''
480
- } ) {
485
+ options . types ? ": JSX.IntrinsicElements['group']" : ''
486
+ } ) {
481
487
${ hasInstances ? 'const instances = useContext(context);' : '' } ${
482
- hasAnimations ? `const group = ${ options . types ? 'useRef<THREE.Group>()' : 'useRef()' } ;` : ''
483
- } ${
484
- ! options . instanceall
485
- ? `const { nodes, materials${ hasAnimations ? ', animations' : '' } } = useGLTF('${ url } '${
486
- options . draco ? `, ${ JSON . stringify ( options . draco ) } ` : ''
487
- } )${ options . types ? ' as GLTFResult' : '' } `
488
- : ''
489
- } ${ printAnimations ( animations ) }
488
+ hasAnimations ? `const group = ${ options . types ? 'useRef<THREE.Group>()' : 'useRef()' } ;` : ''
489
+ } ${
490
+ ! options . instanceall
491
+ ? `const { nodes, materials${ hasAnimations ? ', animations' : '' } } = useGLTF('${ url } '${
492
+ options . draco ? `, ${ JSON . stringify ( options . draco ) } ` : ''
493
+ } )${ options . types ? ' as GLTFResult' : '' } `
494
+ : ''
495
+ } ${ printAnimations ( animations ) }
490
496
return (
491
497
<group ${ hasAnimations ? `ref={group}` : '' } {...props} dispose={null}>
492
498
${ scene }
0 commit comments