Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lint README.md & Organizing Imports #189

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions readme.md → README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
https://user-images.githubusercontent.com/2223602/126318148-99da7ed6-a578-48dd-bdd2-21056dbad003.mp4

<br />
<br/>
<br />

[![Version](https://img.shields.io/npm/v/gltfjsx?style=flat&colorA=000000&colorB=000000)](https://www.npmjs.com/package/gltfjsx) [![Discord Shield](https://img.shields.io/discord/740090768164651008?style=flat&colorA=000000&colorB=000000&label=discord&logo=discord&logoColor=ffffff)](https://discord.gg/ZZjjNvJ)

Expand All @@ -18,7 +18,7 @@ A small command-line tool that turns GLTF assets into declarative and re-usable

### GLTFJSX fixes that

- 🧑‍💻 It creates a virtual graph of all objects and materials. Now you can easily alter contents and re-use.
- 🧑‍💻 It creates a virtual graph of all objects and materials. Now you can easily alter contents and re-use.
- 🏎️ The graph gets pruned (empty groups, unnecessary transforms, ...) and will perform better.
- ⚡️ It will optionally compress your model with up to 70%-90% size reduction.

Expand Down Expand Up @@ -75,7 +75,7 @@ export function Model(props) {
const { nodes, materials } = useGLTF('/model-transformed.glb')
return (
<group {...props} dispose={null}>
<PerspectiveCamera name="camera" fov={40} near={10} far={1000} position={[10, 0, 50]} />
<PerspectiveCamera name="camera" fov={40} near={10} far={1000} position={[10, 0, 50]} />
<pointLight intensity={10} position={[100, 50, 100]} rotation={[-Math.PI / 2, 0, 0]} />
<group position={[10, -5, 0]}>
<mesh geometry={nodes.robot.geometry} material={materials.metal} />
Expand Down Expand Up @@ -104,7 +104,7 @@ import { Model } from './Model'
function App() {
return (
<Canvas>
<Model />
<Model />
```

You can re-use it, it will re-use geometries and materials out of the box:
Expand Down Expand Up @@ -202,7 +202,7 @@ useEffect(() => {

#### ⚡️ Auto-instancing

Use the `--instance` flag and it will look for similar geometry and create instances of them. Look into [drei/Merged](https://github.com/pmndrs/drei#instances) to understand how it works. It does not matter if you instanced the model previously in Blender, it creates instances for each mesh that has a specific geometry and/or material.
Use the `--instance` flag and it will look for similar geometry and create instances of them. Look into [drei/Merged](https://github.com/pmndrs/drei#instances) to understand how it works. It does not matter if you instanced the model previously in Blender, it creates instances for each mesh that has a specific geometry and/or material.

`--instanceall` will create instances of all the geometry. This allows you to re-use the model with the smallest amount of drawcalls.

Expand Down Expand Up @@ -275,7 +275,7 @@ it('should have a scene with a blue mesh', async () => {
const { scene } = await new Promise((res) => loader.parse(data, '', res))
expect(() => scene.children.length).toEqual(1)
expect(() => scene.children[0].type).toEqual('mesh')
expect(() => scene.children[0].material.color).toEqual('blue')
expect(() => scene.children[0].material.color).toEqual('blue')
})
```

Expand Down
5 changes: 2 additions & 3 deletions cli.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
#!/usr/bin/env node
'use strict'
import meow from 'meow'
import path from 'path'
import { fileURLToPath } from 'url'
import { dirname } from 'path'
import gltfjsx from './src/gltfjsx.js'
import { readPackageUpSync } from 'read-pkg-up'
import { fileURLToPath } from 'url'
import gltfjsx from './src/gltfjsx.js'

const __filename = fileURLToPath(import.meta.url)
const __dirname = dirname(__filename)
Expand Down
2 changes: 1 addition & 1 deletion src/bin/DRACOLoader.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict'
import THREE from 'three'
import draco from 'draco3dgltf'
import THREE from 'three'
const decoder = draco.createDecoderModule()
const DRACOLoader = (THREE.DRACOLoader = function (t) {
;(this.timeLoaded = 0),
Expand Down
6 changes: 3 additions & 3 deletions src/gltfjsx.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import 'jsdom-global'
import fs from 'fs'
import 'jsdom-global'
import path from 'path'
import transform from './utils/transform.js'

import prettier from 'prettier'
import THREE from 'three'
global.THREE = THREE

import './bin/GLTFLoader.js'
import DracoLoader from './bin/DRACOLoader.js'
THREE.DRACOLoader.getDecoderModule = () => {}
import './bin/GLTFLoader.js'
import parse from './utils/parser.js'
THREE.DRACOLoader.getDecoderModule = () => {}

const gltfLoader = new THREE.GLTFLoader()
gltfLoader.setDRACOLoader(new DracoLoader())
Expand Down
2 changes: 1 addition & 1 deletion src/utils/exports.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import GLTFStructureLoader from './glftLoader'
import parse from './parser'
import transform from './transform'
import GLTFStructureLoader from './glftLoader'

export { transform, parse, GLTFStructureLoader }
4 changes: 2 additions & 2 deletions src/utils/transform.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { NodeIO } from '@gltf-transform/core'
import { simplify, weld, dedup, resample, prune, textureCompress, draco } from '@gltf-transform/functions'
import { ALL_EXTENSIONS } from '@gltf-transform/extensions'
import { MeshoptDecoder, MeshoptEncoder, MeshoptSimplifier } from 'meshoptimizer'
import { dedup, draco, prune, resample, simplify, textureCompress, weld } from '@gltf-transform/functions'
import draco3d from 'draco3dgltf'
import { MeshoptDecoder, MeshoptEncoder, MeshoptSimplifier } from 'meshoptimizer'
import sharp from 'sharp'

async function transform(file, output, config = {}) {
Expand Down