react-two.js 0.2.3 → 0.2.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +15 -13
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -10,16 +10,16 @@ npm install react-two.js react react-dom two.js
|
|
|
10
10
|
```
|
|
11
11
|
|
|
12
12
|
```jsx
|
|
13
|
-
import { Canvas,
|
|
13
|
+
import { Canvas, Rectangle, useFrame } from 'react-two.js'
|
|
14
14
|
|
|
15
|
-
function
|
|
15
|
+
function RotatingRectangle() {
|
|
16
16
|
const ref = useRef()
|
|
17
17
|
useFrame((t) => ref.current.rotation = t * 0.5)
|
|
18
|
-
return <
|
|
18
|
+
return <Rectangle ref={ref} radius={50} fill="#00AEFF" />
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
-
<Canvas width={800} height={600}>
|
|
22
|
-
<
|
|
21
|
+
<Canvas width={800} height={600} autostart={true}>
|
|
22
|
+
<RotatingRectangle />
|
|
23
23
|
</Canvas>
|
|
24
24
|
```
|
|
25
25
|
|
|
@@ -71,7 +71,7 @@ npm install react-two.js react react-dom two.js
|
|
|
71
71
|
- Two.js v0.8.21+
|
|
72
72
|
|
|
73
73
|
> [!IMPORTANT]
|
|
74
|
-
> react-two.js is a React renderer, it must pair with a major version of React,
|
|
74
|
+
> react-two.js is a React renderer, it must pair with a major version of React, like react-dom.
|
|
75
75
|
|
|
76
76
|
## First Steps
|
|
77
77
|
|
|
@@ -87,7 +87,7 @@ function App() {
|
|
|
87
87
|
<Canvas
|
|
88
88
|
width={800}
|
|
89
89
|
height={600}
|
|
90
|
-
type="
|
|
90
|
+
type="SVGRenderer"
|
|
91
91
|
autostart={true}
|
|
92
92
|
>
|
|
93
93
|
{/* Your scene goes here */}
|
|
@@ -101,7 +101,7 @@ function App() {
|
|
|
101
101
|
All Two.js primitives are available as React components:
|
|
102
102
|
|
|
103
103
|
```jsx
|
|
104
|
-
<Canvas width={800} height={600}>
|
|
104
|
+
<Canvas width={800} height={600} autostart={true}>
|
|
105
105
|
<Circle radius={50} fill="#00AEFF" x={400} y={300} />
|
|
106
106
|
<Rectangle width={100} height={60} stroke="#FF0000" linewidth={3} />
|
|
107
107
|
<Polygon sides={6} radius={40} fill="#00FF00" />
|
|
@@ -114,9 +114,9 @@ The `useFrame` hook runs on every frame, perfect for animations:
|
|
|
114
114
|
|
|
115
115
|
```jsx
|
|
116
116
|
import { useRef } from 'react'
|
|
117
|
-
import {
|
|
117
|
+
import { Rectangle, useFrame } from 'react-two.js'
|
|
118
118
|
|
|
119
|
-
function
|
|
119
|
+
function AnimatedRectangle() {
|
|
120
120
|
const ref = useRef()
|
|
121
121
|
|
|
122
122
|
useFrame((elapsed) => {
|
|
@@ -124,7 +124,7 @@ function AnimatedCircle() {
|
|
|
124
124
|
ref.current.scale = 1 + Math.sin(elapsed) * 0.2
|
|
125
125
|
})
|
|
126
126
|
|
|
127
|
-
return <
|
|
127
|
+
return <Rectangle ref={ref} width={50} height={50} fill="#00AEFF" />
|
|
128
128
|
}
|
|
129
129
|
```
|
|
130
130
|
|
|
@@ -136,9 +136,10 @@ Use `useTwo` to access the underlying Two.js instance:
|
|
|
136
136
|
import { useTwo } from 'react-two.js'
|
|
137
137
|
|
|
138
138
|
function Component() {
|
|
139
|
-
const {
|
|
139
|
+
const { two, width, height } = useTwo()
|
|
140
140
|
|
|
141
141
|
useEffect(() => {
|
|
142
|
+
two.play();
|
|
142
143
|
console.log('Canvas size:', width, height)
|
|
143
144
|
console.log('Two.js instance:', instance)
|
|
144
145
|
}, [])
|
|
@@ -228,7 +229,7 @@ import { useRef } from 'react'
|
|
|
228
229
|
import { Circle, RefCircle } from 'react-two.js'
|
|
229
230
|
|
|
230
231
|
function Component() {
|
|
231
|
-
const circleRef = useRef<RefCircle>(null)
|
|
232
|
+
const circleRef = useRef<RefCircle | null>(null)
|
|
232
233
|
|
|
233
234
|
useEffect(() => {
|
|
234
235
|
if (circleRef.current) {
|
|
@@ -292,6 +293,7 @@ function () {
|
|
|
292
293
|
- **[Two.js Documentation](https://two.js.org/docs/)** — Complete Two.js API reference
|
|
293
294
|
- **[Two.js Examples](https://two.js.org/examples/)** — Interactive examples and demos
|
|
294
295
|
- **[Two.js Repository](https://github.com/jonobr1/two.js)** — Source code and issues
|
|
296
|
+
- **[Two.js Tutor on ChatGPT](https://chatgpt.com/g/g-hkcTX8uPm-two-js-tutor)** - Talk to a custom ChatGPT trained on Two.js and react-two.js
|
|
295
297
|
|
|
296
298
|
## Development
|
|
297
299
|
|
package/package.json
CHANGED