Skip to content
Open
Show file tree
Hide file tree
Changes from 5 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
4 changes: 2 additions & 2 deletions .husky/commit-msg
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"
# . "$(dirname "$0")/_/husky.sh"

npx --no-install commitlint --edit $1
# npx --no-install commitlint --edit $1
35 changes: 20 additions & 15 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@react-three/drei",
"version": "0.0.0-semantic-release",
"private": true,
"name": "@nicetouch/drei",
"version": "10.0.0-alpha.1",
"private": false,
"description": "useful add-ons for react-three-fiber",
"keywords": [
"react",
Expand All @@ -24,10 +24,10 @@
"Marco Perego (https://github.com/emmelleppi)",
"Josh Ellis (https://github.com/joshuaellis)"
],
"main": "index.cjs.js",
"module": "index.js",
"types": "index.d.ts",
"react-native": "native/index.cjs.js",
"main": "dist/index.cjs.js",
"module": "dist/index.js",
"types": "dist/index.d.ts",
"react-native": "dist/native/index.cjs.js",
"sideEffects": false,
"commitlint": {
"extends": [
Expand Down Expand Up @@ -65,6 +65,7 @@
"cross-env": "^7.0.3",
"detect-gpu": "^5.0.28",
"glsl-noise": "^0.0.0",
"hls.js": "1.3.5",
"maath": "^0.10.7",
"meshline": "^3.1.6",
"react-composer": "^5.0.3",
Expand All @@ -77,20 +78,20 @@
"tunnel-rat": "^0.1.2",
"utility-types": "^3.10.0",
"uuid": "^9.0.1",
"zustand": "^3.7.1",
"hls.js": "1.3.5"
"zustand": "^3.7.1"
},
"devDependencies": {
"@babel/core": "^7.14.3",
"@babel/plugin-proposal-class-properties": "^7.18.6",
"@babel/plugin-proposal-nullish-coalescing-operator": "^7.18.6",
"@babel/plugin-transform-modules-commonjs": "^7.14.0",
"@babel/plugin-transform-runtime": "^7.14.3",
"@babel/preset-env": "^7.21.5",
"@babel/preset-react": "^7.18.6",
"@babel/preset-typescript": "^7.21.5",
"@commitlint/cli": "^12.0.1",
"@commitlint/config-conventional": "^12.0.1",
"@react-three/fiber": "^8.0.8",
"@react-three/fiber": "^9.0.0-alpha.5",
"@rollup/plugin-babel": "^5.3.0",
"@rollup/plugin-commonjs": "^19.0.0",
"@rollup/plugin-json": "^4.1.0",
Expand Down Expand Up @@ -127,8 +128,8 @@
"prettier": "^2.4.1",
"pretty-quick": "^3.1.0",
"puppeteer": "^20.7.4",
"react": "^18.0.0",
"react-dom": "^18.0.0",
"react": "19.0.0-beta-94eed63c49-20240425",
"react-dom": "19.0.0-beta-94eed63c49-20240425",
"rimraf": "^3.0.2",
"rollup": "^2.78.1",
"rollup-plugin-glslify": "^1.3.0",
Expand All @@ -145,14 +146,18 @@
"yarn": "^1.22.17"
},
"peerDependencies": {
"@react-three/fiber": ">=8.0",
"react": ">=18.0",
"react-dom": ">=18.0",
"@react-three/fiber": ">=9.0.0-alpha.5",
"react": ">=19.0",
"react-dom": ">=19.0",
"three": ">=0.137"
},
"peerDependenciesMeta": {
"react-dom": {
"optional": true
}
},
"overrides": {
"@types/react": "npm:types-react@beta",
"@types/react-dom": "npm:types-react-dom@beta"
}
}
23 changes: 10 additions & 13 deletions src/core/AccumulativeShadows.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as THREE from 'three'
import * as React from 'react'
import { extend, ReactThreeFiber, useFrame, useThree } from '@react-three/fiber'
import { extend, ReactThreeFiber, ThreeElements, useFrame, useThree } from '@react-three/fiber'
import { shaderMaterial } from './shaderMaterial'
import { DiscardMaterial } from '../materials/DiscardMaterial'
import { ForwardRefComponent } from '../helpers/ts-utils'
Expand Down Expand Up @@ -65,11 +65,9 @@ type SoftShadowMaterialProps = {
blend?: number
}

declare global {
namespace JSX {
interface IntrinsicElements {
softShadowMaterial: JSX.IntrinsicElements['shaderMaterial'] & SoftShadowMaterialProps
}
declare module '@react-three/fiber' {
interface ThreeElements {
softShadowMaterial: ThreeElements['shaderMaterial'] & SoftShadowMaterialProps
}
}

Expand Down Expand Up @@ -105,7 +103,7 @@ const SoftShadowMaterial = /* @__PURE__ */ shaderMaterial(
)

export const AccumulativeShadows: ForwardRefComponent<
JSX.IntrinsicElements['group'] & AccumulativeShadowsProps,
ThreeElements['group'] & AccumulativeShadowsProps,
AccumulativeContext
> = /* @__PURE__ */ React.forwardRef(
(
Expand All @@ -123,7 +121,7 @@ export const AccumulativeShadows: ForwardRefComponent<
resolution = 1024,
toneMapped = true,
...props
}: JSX.IntrinsicElements['group'] & AccumulativeShadowsProps,
}: ThreeElements['group'] & AccumulativeShadowsProps,
forwardRef: React.ForwardedRef<AccumulativeContext>
) => {
extend({ SoftShadowMaterial })
Expand Down Expand Up @@ -254,7 +252,7 @@ export type RandomizedLightProps = {
}

export const RandomizedLight: ForwardRefComponent<
JSX.IntrinsicElements['group'] & RandomizedLightProps,
ThreeElements['group'] & RandomizedLightProps,
AccumulativeLightContext
> = /* @__PURE__ */ React.forwardRef(
(
Expand All @@ -265,14 +263,13 @@ export const RandomizedLight: ForwardRefComponent<
size = 5,
near = 0.5,
far = 500,
frames = 1,
position = [0, 0, 0],
radius = 1,
amount = 8,
intensity = version >= 155 ? Math.PI : 1,
ambient = 0.5,
...props
}: JSX.IntrinsicElements['group'] & RandomizedLightProps,
}: ThreeElements['group'] & RandomizedLightProps,
forwardRef: React.ForwardedRef<AccumulativeLightContext>
) => {
const gLights = React.useRef<THREE.Group>(null!)
Expand All @@ -291,8 +288,8 @@ export const RandomizedLight: ForwardRefComponent<
position[2] + THREE.MathUtils.randFloatSpread(radius)
)
} else {
let lambda = Math.acos(2 * Math.random() - 1) - Math.PI / 2.0
let phi = 2 * Math.PI * Math.random()
const lambda = Math.acos(2 * Math.random() - 1) - Math.PI / 2.0
const phi = 2 * Math.PI * Math.random()
light.position.set(
Math.cos(lambda) * Math.cos(phi) * length,
Math.abs(Math.cos(lambda) * Math.sin(phi) * length),
Expand Down
2 changes: 2 additions & 0 deletions src/core/AdaptiveDpr.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export function AdaptiveDpr({ pixelated }: { pixelated?: boolean }) {
const current = useThree((state) => state.performance.current)
const initialDpr = useThree((state) => state.viewport.initialDpr)
const setDpr = useThree((state) => state.setDpr)

// Restore initial pixelratio on unmount
React.useEffect(() => {
const domElement = gl.domElement
Expand All @@ -15,6 +16,7 @@ export function AdaptiveDpr({ pixelated }: { pixelated?: boolean }) {
if (pixelated && domElement) domElement.style.imageRendering = 'auto'
}
}, [])

// Set adaptive pixelratio
React.useEffect(() => {
setDpr(current * initialDpr)
Expand Down
4 changes: 2 additions & 2 deletions src/core/ArcballControls.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { EventManager, ReactThreeFiber, useFrame, useThree } from '@react-three/fiber'
import { EventManager, ReactThreeFiber, ThreeElement, useFrame, useThree } from '@react-three/fiber'
import * as React from 'react'
import { forwardRef, useEffect, useMemo } from 'react'
import { ArcballControls as ArcballControlsImpl } from 'three-stdlib'
Expand All @@ -8,7 +8,7 @@ import { ForwardRefComponent } from '../helpers/ts-utils'

export type ArcballControlsProps = Omit<
ReactThreeFiber.Overwrite<
ReactThreeFiber.Object3DNode<ArcballControlsImpl, typeof ArcballControlsImpl>,
ThreeElement<typeof ArcballControlsImpl>,
{
target?: ReactThreeFiber.Vector3
camera?: OrthographicCamera | PerspectiveCamera
Expand Down
6 changes: 3 additions & 3 deletions src/core/BBAnchor.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import * as React from 'react'
import * as THREE from 'three'
import { useFrame, GroupProps } from '@react-three/fiber'
import { type ThreeElements, useFrame } from '@react-three/fiber'

const boundingBox = /* @__PURE__ */ new THREE.Box3()
const boundingBoxSize = /* @__PURE__ */ new THREE.Vector3()

export interface BBAnchorProps extends GroupProps {
export type BBAnchorProps = {
anchor: THREE.Vector3 | [number, number, number]
}
} & ThreeElements['group']

export const BBAnchor = ({ anchor, ...props }: BBAnchorProps) => {
const ref = React.useRef<THREE.Group>(null!)
Expand Down
3 changes: 2 additions & 1 deletion src/core/Backdrop.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { ThreeElements } from '@react-three/fiber'
import * as React from 'react'
import { PlaneGeometry, BufferAttribute } from 'three'

const easeInExpo = (x: number) => (x === 0 ? 0 : Math.pow(2, 10 * x - 10))

export type BackdropProps = JSX.IntrinsicElements['group'] & {
export type BackdropProps = ThreeElements['group'] & {
floor?: number
segments?: number
receiveShadow?: boolean
Expand Down
4 changes: 2 additions & 2 deletions src/core/Billboard.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import * as React from 'react'
import { Group, Quaternion } from 'three'
import { useFrame } from '@react-three/fiber'
import { ThreeElements, useFrame } from '@react-three/fiber'
import { ForwardRefComponent } from '../helpers/ts-utils'

export type BillboardProps = {
follow?: boolean
lockX?: boolean
lockY?: boolean
lockZ?: boolean
} & JSX.IntrinsicElements['group']
} & ThreeElements['group']

/**
* Wraps children in a billboarded group. Sample usage:
Expand Down
9 changes: 5 additions & 4 deletions src/core/Bounds.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as React from 'react'
import * as THREE from 'three'

import { useFrame, useThree } from '@react-three/fiber'
import { ThreeElements, useFrame, useThree } from '@react-three/fiber'

export type SizeProps = {
box: THREE.Box3
Expand All @@ -27,7 +27,7 @@ export type BoundsApi = {
clip(): BoundsApi
}

export type BoundsProps = JSX.IntrinsicElements['group'] & {
export type BoundsProps = ThreeElements['group'] & {
maxDuration?: number
margin?: number
observe?: boolean
Expand Down Expand Up @@ -127,8 +127,9 @@ export function Bounds({
return {
getSize,
refresh(object?: THREE.Object3D | THREE.Box3) {
if (isBox3(object)) box.copy(object)
else {
if (isBox3(object)) {
box.copy(object)
} else {
const target = object || ref.current
if (!target) return this
target.updateWorldMatrix(true, true)
Expand Down
4 changes: 2 additions & 2 deletions src/core/CameraControls.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ import {

import * as React from 'react'
import { forwardRef, useMemo, useEffect } from 'react'
import { extend, useFrame, useThree, ReactThreeFiber, EventManager } from '@react-three/fiber'
import { extend, useFrame, useThree, ReactThreeFiber, EventManager, ThreeElement } from '@react-three/fiber'

import CameraControlsImpl from 'camera-controls'
import { ForwardRefComponent } from '../helpers/ts-utils'

export type CameraControlsProps = Omit<
ReactThreeFiber.Overwrite<
ReactThreeFiber.Node<CameraControlsImpl, typeof CameraControlsImpl>,
ThreeElement<typeof CameraControlsImpl>,
{
camera?: PerspectiveCamera | OrthographicCamera
domElement?: HTMLElement
Expand Down
8 changes: 3 additions & 5 deletions src/core/Caustics.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import * as THREE from 'three'
import * as React from 'react'
import { extend, ReactThreeFiber, useFrame, useThree } from '@react-three/fiber'
import { extend, ReactThreeFiber, ThreeElements, useFrame, useThree } from '@react-three/fiber'
import { useFBO } from './useFBO'
import { useHelper } from './useHelper'
import { shaderMaterial } from './shaderMaterial'
Expand Down Expand Up @@ -41,7 +41,7 @@ type CausticsProjectionMaterialType = THREE.MeshNormalMaterial & {
lightViewMatrix?: THREE.Matrix4
}

type CausticsProps = JSX.IntrinsicElements['group'] & {
type CausticsProps = ThreeElements['group'] & {
/** How many frames it will render, set it to Infinity for runtime, default: 1 */
frames?: number
/** Enables visual cues to help you stage your scene, default: false */
Expand Down Expand Up @@ -69,7 +69,7 @@ type CausticsProps = JSX.IntrinsicElements['group'] & {
declare global {
namespace JSX {
interface IntrinsicElements {
causticsProjectionMaterial: ReactThreeFiber.MeshNormalMaterialProps & {
causticsProjectionMaterial: ThreeElements['meshNormalMaterial'] & {
viewMatrix?: { value: THREE.Matrix4 }
color?: ReactThreeFiber.Color
causticsTexture?: THREE.Texture
Expand Down Expand Up @@ -277,8 +277,6 @@ const CAUSTICPROPS = {
generateMipmaps: true,
}

const causticsContext = /* @__PURE__ */ React.createContext(null)

export const Caustics: ForwardRefComponent<CausticsProps, THREE.Group> = /* @__PURE__ */ React.forwardRef(
(
{
Expand Down
6 changes: 3 additions & 3 deletions src/core/Center.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Box3, Vector3, Sphere, Group, Object3D } from 'three'
import * as React from 'react'
import { useThree } from '@react-three/fiber'
import { ThreeElements } from '@react-three/fiber'
import { ForwardRefComponent } from '../helpers/ts-utils'

export type OnCenterCallbackProps = {
Expand Down Expand Up @@ -42,8 +42,8 @@ export type CenterProps = {
cacheKey?: any
}

export const Center: ForwardRefComponent<JSX.IntrinsicElements['group'] & CenterProps, Group> =
/* @__PURE__ */ React.forwardRef<Group, JSX.IntrinsicElements['group'] & CenterProps>(function Center(
export const Center: ForwardRefComponent<ThreeElements['group'] & CenterProps, Group> =
/* @__PURE__ */ React.forwardRef<Group, ThreeElements['group'] & CenterProps>(function Center(
{
children,
disable,
Expand Down
10 changes: 5 additions & 5 deletions src/core/Clone.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import * as THREE from 'three'
import * as React from 'react'
import { MeshProps } from '@react-three/fiber'
import { SkeletonUtils } from 'three-stdlib'
import { ForwardRefComponent } from '../helpers/ts-utils'
import { ThreeElements } from '@react-three/fiber'

export type CloneProps = {
/** Any pre-existing THREE.Object3D (groups, meshes, ...), or an array of objects */
Expand All @@ -14,7 +14,7 @@ export type CloneProps = {
/** The property keys it will shallow-clone (material, geometry, visible, ...) */
keys?: string[]
/** Can either spread over props or fill in JSX children, applies to every mesh within */
inject?: MeshProps | React.ReactNode | ((object: THREE.Object3D) => React.ReactNode)
inject?: ThreeElements['mesh'] | React.ReactNode | ((object: THREE.Object3D) => React.ReactNode)
/** Short access castShadow, applied to every mesh within */
castShadow?: boolean
/** Short access receiveShadow, applied to every mesh within */
Expand Down Expand Up @@ -57,7 +57,7 @@ function createSpread(
inject,
castShadow,
receiveShadow,
}: Omit<JSX.IntrinsicElements['group'], 'children'> & Partial<CloneProps>
}: Omit<ThreeElements['group'], 'children'> & Partial<CloneProps>
) {
let spread: Record<(typeof keys)[number], any> = {}
for (const key of keys) {
Expand All @@ -81,7 +81,7 @@ function createSpread(
return spread
}

export const Clone: ForwardRefComponent<Omit<JSX.IntrinsicElements['group'], 'children'> & CloneProps, THREE.Group> =
export const Clone: ForwardRefComponent<Omit<ThreeElements['group'], 'children'> & CloneProps, THREE.Group> =
/* @__PURE__ */ React.forwardRef(
(
{
Expand All @@ -94,7 +94,7 @@ export const Clone: ForwardRefComponent<Omit<JSX.IntrinsicElements['group'], 'ch
inject,
keys,
...props
}: Omit<JSX.IntrinsicElements['group'], 'children'> & CloneProps,
}: Omit<ThreeElements['group'], 'children'> & CloneProps,
forwardRef: React.Ref<THREE.Group>
) => {
const config = { keys, deep, inject, castShadow, receiveShadow }
Expand Down
Loading