Comments (8)
oh, that's interesting. would you make a PR? im not too familiar with TS but would definitively approve of it.
it's just this file: https://github.com/react-spring/gltfjsx/blob/master/gltfjsx.js
it concatenates text basically. you would add types in there.
from gltfjsx.
@drcmda I will definitely submit a PR once all the problems are solved. For now, the timeline of another project is quite tight so I need to focus on that. I will come to this maybe next week.
My suspicion is that the typing of 3 is lacking some not-commonly-used types. But I haven't got time to verify it yet.
from gltfjsx.
it's done :-)
/*
auto-generated by: https://github.com/react-spring/gltfjsx
*/
import * as THREE from 'three'
import React, { useRef } from 'react'
import { useLoader } from 'react-three-fiber'
import { GLTFLoader, GLTF } from 'three/examples/jsm/loaders/GLTFLoader'
type GLTFResult = GLTF & {
nodes: {
Circle011_EyeFire_0: THREE.Mesh
Circle011_SerpentBake_0: THREE.Mesh
Hide003_EyeFire_0: THREE.Mesh
Hide003_Boat2Bake_0: THREE.Mesh
Keel002_EyeFire_0: THREE.Mesh
Keel002_Boat1Bake_0: THREE.Mesh
Plane044_WaterBake_0: THREE.Mesh
Rock021_RockBake_0: THREE.Mesh
VikingShipObjects001_Objects_0: THREE.Mesh
VikingShipObjects001_Objects_0001: THREE.Mesh
}
materials: {
EyeFire: THREE.MeshStandardMaterial
SerpentBake: THREE.MeshStandardMaterial
Boat2Bake: THREE.MeshStandardMaterial
Boat1Bake: THREE.MeshStandardMaterial
WaterBake: THREE.MeshStandardMaterial
RockBake: THREE.MeshStandardMaterial
Objects: THREE.MeshStandardMaterial
}
}
export default function Model(props: JSX.IntrinsicElements['group']) {
const group = useRef()
const { nodes, materials } = useLoader<GLTFResult>(GLTFLoader, '/scene_draco.glb')
return (
<group ref={group} {...props} dispose={null}>
<group rotation={[-Math.PI / 2, 0, 0]} scale={[0.01, 0.01, 0.01]}>
<group rotation={[Math.PI / 2, 0, 0]}>
<group rotation={[-Math.PI / 2, 0, 0]} scale={[100, 100, 100]}>
<mesh material={materials.EyeFire} geometry={nodes.Circle011_EyeFire_0.geometry} />
<mesh material={materials.SerpentBake} geometry={nodes.Circle011_SerpentBake_0.geometry} />
</group>
<group position={[-1018.2, -380.53, 1332.67]} rotation={[-1.05, 0.72, -0.08]} scale={[100, 100, 100]}>
<mesh material={materials.EyeFire} geometry={nodes.Hide003_EyeFire_0.geometry} />
<mesh material={materials.Boat2Bake} geometry={nodes.Hide003_Boat2Bake_0.geometry} />
</group>
<group position={[349.57, 32.32, 176.64]} rotation={[-1.73, -0.23, -2.65]} scale={[100, 100, 100]}>
<mesh material={materials.EyeFire} geometry={nodes.Keel002_EyeFire_0.geometry} />
<mesh material={materials.Boat1Bake} geometry={nodes.Keel002_Boat1Bake_0.geometry} />
</group>
<group position={[0, 27.07, 0]} rotation={[-Math.PI / 2, 0, 0]} scale={[100, 100, 170.02]}>
<mesh material={materials.WaterBake} geometry={nodes.Plane044_WaterBake_0.geometry} />
</group>
<group rotation={[-Math.PI / 2, 0, 0]} scale={[100, 100, 100]}>
<mesh material={materials.RockBake} geometry={nodes.Rock021_RockBake_0.geometry} />
</group>
<group scale={[100, 100, 100]}>
<mesh material={materials.Objects} geometry={nodes.VikingShipObjects001_Objects_0.geometry} />
<mesh material={materials.Objects} geometry={nodes.VikingShipObjects001_Objects_0001.geometry} />
</group>
</group>
</group>
</group>
)
}
from gltfjsx.
@drcmda thx. Are nodes
and materials
defined in three or react-three-fiber or neither?
from gltfjsx.
they are normally not defined because they are dependent on the gltf.
from gltfjsx.
I mean the existence of these fields should be shipped in the typing of a package for more convenient usage if possible.
For example, the nodes
may be defined as {[key: string]: THREE.Mesh} | undefined
. So that the user can use the default typing in simple cases, whereas the specific field names can still be overwritten by the user if needed.
My question is which package the default typing of these fields should reside in: three, react-three-fiber or neither? In case of neither, I guess nothing can be done. But for the other 2 cases, we can add the default typing to the corresponding package because apparently such typing does not exist anywhere yet.
from gltfjsx.
that makes sense, im still learning about ts. it would be in r3f/src/hooks.tsx i guess. but useLoader can be used with ANY loader, imageloader, textureloader etc. nodes/materials is something i add to the gltfloader.
but it could still export a type that you could plugin in useLoader<GLTF>(...)
edit: just tried, but i think this goes over my head. types were made by contribution, dont know how it works tbh
from gltfjsx.
I just looked at r3f/src/hooks.tsx and found many any
s related to the loaders, which is generally considered as a bad practice. I guess a more ts-ish refactorization may be required before more specific issues can be addressed.
Thx for your great work! I will try to learn the codebase of r3f and contribute when it is necessary.
from gltfjsx.
Related Issues (20)
- TypeError: objectInfluences is undefined HOT 5
- Application error: a client-side exception has occurred (see the browser console for more information). HOT 2
- Question: How can I allow users to change the node's surface colour HOT 1
- Model gets deformed when being converted HOT 1
- v6.2.12 - Cannot read properties of undefined (reading 'length') HOT 2
- stylelint fails with meow
- Typescript Errors in Web version and CLI using `--types` option HOT 3
- The instance all option generates code that doesn't work with animations. HOT 1
- new feature - skeleton programmatically HOT 1
- Uncaught TypeError: objectInfluences is undefined HOT 2
- Expose materials attributes/properties / Explode materials
- Using gltfjsx in Next.js - No "exports" main defined in /node_modules/@monogrid/gainmap-js/package.json
- Parsing input arbitrary three.js scene graph to component tree HOT 3
- How to rewrite gltfjsx generated jsx file to separate geometry and material HOT 1
- instruction for installation in documentation 😔❌ HOT 2
- Unit testing - gltfjsx created components
- TypeError while using gltfjsx to an animated model: Cannot read properties of null (reading 'array') HOT 2
- Could not load /animatedmodel.glb: Unexpected token '<', "<!DOCTYPE "... is not valid JSON
- --transform option on an animated model doesn't work anymore as it thinks the --instance option is on when it isn't. HOT 1
- default generated tsx code problems HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from gltfjsx.