Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
N
next.js
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Alex
next.js
Commits
6c1cfc10
Unverified
Commit
6c1cfc10
authored
Apr 11, 2022
by
Henrik Wenz
Committed by
GitHub
Apr 11, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[example] Fix bird animations in with-three-js example (#36053)
* Fix bird animations * Use memo for birds generation
parent
16f7084e
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
46 additions
and
42 deletions
+46
-42
package.json
examples/with-three-js/package.json
+5
-5
birds.js
examples/with-three-js/pages/birds.js
+41
-37
No files found.
examples/with-three-js/package.json
View file @
6c1cfc10
...
@@ -6,11 +6,11 @@
...
@@ -6,11 +6,11 @@
"start"
:
"next start"
"start"
:
"next start"
},
},
"dependencies"
:
{
"dependencies"
:
{
"@react-three/drei"
:
"
7.6.1
"
,
"@react-three/drei"
:
"
9.3.4
"
,
"@react-three/fiber"
:
"
7.0.6
"
,
"@react-three/fiber"
:
"
8.0.10
"
,
"next"
:
"latest"
,
"next"
:
"latest"
,
"react"
:
"^1
7.0.2
"
,
"react"
:
"^1
8.0.0
"
,
"react-dom"
:
"^1
7.0.2
"
,
"react-dom"
:
"^1
8.0.0
"
,
"three"
:
"0.1
28.0
"
"three"
:
"0.1
39.2
"
}
}
}
}
examples/with-three-js/pages/birds.js
View file @
6c1cfc10
import
{
Suspense
}
from
'react'
import
{
Suspense
,
useMemo
}
from
'react'
import
{
Canvas
}
from
'@react-three/fiber'
import
{
Canvas
}
from
'@react-three/fiber'
import
{
OrbitControls
}
from
'@react-three/drei'
import
{
OrbitControls
}
from
'@react-three/drei'
import
Bird
from
'../components/Bird'
import
Bird
from
'../components/Bird'
export
default
function
BirdsPage
()
{
export
default
function
BirdsPage
()
{
return
(
const
birds
=
useMemo
(
<>
()
=>
<
Canvas
camera
=
{{
position
:
[
0
,
0
,
35
]
}}
>
new
Array
(
10
).
fill
().
map
((
_
,
index
)
=>
{
<
ambientLight
intensity
=
{
2
}
/
>
<
pointLight
position
=
{[
40
,
40
,
40
]}
/
>
<
OrbitControls
/>
<
Suspense
fallback
=
{
null
}
>
{
new
Array
(
6
).
fill
().
map
((
_
,
i
)
=>
{
const
x
=
const
x
=
(
15
+
Math
.
random
()
*
30
)
*
(
Math
.
round
(
Math
.
random
())
?
-
1
:
1
)
(
15
+
Math
.
random
()
*
30
)
*
(
Math
.
round
(
Math
.
random
())
?
-
1
:
1
)
const
y
=
-
10
+
Math
.
random
()
*
20
const
y
=
-
10
+
Math
.
random
()
*
20
...
@@ -19,27 +14,36 @@ export default function BirdsPage() {
...
@@ -19,27 +14,36 @@ export default function BirdsPage() {
const
bird
=
[
'stork'
,
'parrot'
,
'flamingo'
][
const
bird
=
[
'stork'
,
'parrot'
,
'flamingo'
][
Math
.
round
(
Math
.
random
()
*
2
)
Math
.
round
(
Math
.
random
()
*
2
)
]
]
le
t
speed
=
bird
===
'stork'
?
0.5
:
bird
===
'flamingo'
?
2
:
5
cons
t
speed
=
bird
===
'stork'
?
0.5
:
bird
===
'flamingo'
?
2
:
5
le
t
factor
=
cons
t
factor
=
bird
===
'stork'
bird
===
'stork'
?
0.5
+
Math
.
random
()
?
0.5
+
Math
.
random
()
:
bird
===
'flamingo'
:
bird
===
'flamingo'
?
0.25
+
Math
.
random
()
?
0.25
+
Math
.
random
()
:
1
+
Math
.
random
()
-
0.5
:
1
+
Math
.
random
()
-
0.5
return
(
return
{
<
Bird
key
:
index
,
key
=
{
i
}
position
:
[
x
,
y
,
z
],
position
=
{[
x
,
y
,
z
]}
rotation
:
[
0
,
x
>
0
?
Math
.
PI
:
0
,
0
],
rotation
=
{[
0
,
x
>
0
?
Math
.
PI
:
0
,
0
]}
speed
,
speed
=
{
speed
}
factor
,
factor
=
{
factor
}
url
:
`/glb/
${
bird
}
.glb`
,
url
=
{
`/glb/
${
bird
}
.glb`
}
}
/
>
}),
[]
)
)
})}
return
(
<
Canvas
camera
=
{{
position
:
[
0
,
0
,
35
]
}}
>
<
ambientLight
intensity
=
{
2
}
/
>
<
pointLight
position
=
{[
40
,
40
,
40
]}
/
>
<
OrbitControls
/>
<
Suspense
fallback
=
{
null
}
>
{
birds
.
map
((
props
)
=>
(
<
Bird
{...
props
}
key
=
{
props
.
key
}
/
>
))}
<
/Suspense
>
<
/Suspense
>
<
/Canvas
>
<
/Canvas
>
<
/
>
)
)
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment