Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
O
official
Project
Project
Details
Activity
Releases
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
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
吕祺
official
Commits
01b25aa9
Unverified
Commit
01b25aa9
authored
Mar 13, 2024
by
limichange
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: update threejs & addThreeD2
parent
96175ead
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
986 additions
and
1984 deletions
+986
-1984
.eslintignore
.eslintignore
+2
-1
addThreeD2.js
static/addThreeD2.js
+87
-31
three.min.js
static/three.min.js
+897
-1952
No files found.
.eslintignore
View file @
01b25aa9
node_modules/
node_modules/
.next/
.next/
out/
out/
*.min.js
\ No newline at end of file
static/addThreeD2.js
View file @
01b25aa9
...
@@ -10,7 +10,6 @@ var target
...
@@ -10,7 +10,6 @@ var target
var
lan
var
lan
var
resizeTimer
var
resizeTimer
var
radius
=
pcPicWidth
/
Math
.
PI
/
12
var
radius
=
pcPicWidth
/
Math
.
PI
/
12
var
planeHeight
=
1024
/
6
var
planeHeight
=
1024
/
6
...
@@ -48,7 +47,7 @@ function imageMobile(en) {
...
@@ -48,7 +47,7 @@ function imageMobile(en) {
:
'/static/img/timeline-mobile-cn.png'
:
'/static/img/timeline-mobile-cn.png'
return
img
return
img
}
}
function
genMaterialArray
(
isMobile
,
en
,
callback
)
{
function
genMaterialArray
(
isMobile
,
en
,
callback
)
{
const
timeline
=
isMobile
?
imageMobile
(
en
)
:
image
(
en
)
const
timeline
=
isMobile
?
imageMobile
(
en
)
:
image
(
en
)
timeline
.
onload
=
function
()
{
timeline
.
onload
=
function
()
{
const
canvas
=
document
.
createElement
(
'canvas'
)
const
canvas
=
document
.
createElement
(
'canvas'
)
...
@@ -85,15 +84,11 @@ function getWindowWidth() {
...
@@ -85,15 +84,11 @@ function getWindowWidth() {
}
}
function
getWindowHeight
()
{
function
getWindowHeight
()
{
if
(
isMobile
)
{
isMobile
=
checkMobile
()
return
window
.
innerHeight
*
0.9
const
h
=
isMobile
?
window
.
innerHeight
*
0.6
:
window
.
innerWidth
/
2.5
}
else
{
return
h
return
window
.
innerHeight
*
0.8
}
}
}
function
checkMobile
()
{
function
checkMobile
()
{
let
mobile
=
window
.
innerWidth
<
780
let
mobile
=
window
.
innerWidth
<
780
return
mobile
return
mobile
...
@@ -109,7 +104,7 @@ function initMobileGeo(en) {
...
@@ -109,7 +104,7 @@ function initMobileGeo(en) {
const
_debugMaterial
=
new
THREE
.
MeshBasicMaterial
({
const
_debugMaterial
=
new
THREE
.
MeshBasicMaterial
({
color
:
16777215
/
(
sliceIndex
*
10
+
1
),
color
:
16777215
/
(
sliceIndex
*
10
+
1
),
transparent
:
true
,
transparent
:
true
,
opacity
:
0.0002
,
opacity
:
0.0002
})
})
const
geo2
=
new
THREE
.
PlaneGeometry
(
w
/
2
,
planeHeight
)
const
geo2
=
new
THREE
.
PlaneGeometry
(
w
/
2
,
planeHeight
)
geo2
.
translate
(
0
,
-
56
,
0.5
*
radius
*
Math
.
cos
(
Math
.
PI
/
slice
))
geo2
.
translate
(
0
,
-
56
,
0.5
*
radius
*
Math
.
cos
(
Math
.
PI
/
slice
))
...
@@ -119,7 +114,7 @@ function initMobileGeo(en) {
...
@@ -119,7 +114,7 @@ function initMobileGeo(en) {
}
}
scene
.
add
(
cylinderMobileGroup
)
scene
.
add
(
cylinderMobileGroup
)
genMaterialArray
(
true
,
en
,
function
(
canvasArray
)
{
genMaterialArray
(
true
,
en
,
function
(
canvasArray
)
{
for
(
let
i
=
0
;
i
<
slice
;
i
++
)
{
for
(
let
i
=
0
;
i
<
slice
;
i
++
)
{
let
tex
=
new
THREE
.
TextureLoader
().
load
(
canvasArray
[
i
])
let
tex
=
new
THREE
.
TextureLoader
().
load
(
canvasArray
[
i
])
tex
.
anisotropy
=
renderer
.
capabilities
.
getMaxAnisotropy
()
tex
.
anisotropy
=
renderer
.
capabilities
.
getMaxAnisotropy
()
...
@@ -127,7 +122,7 @@ function initMobileGeo(en) {
...
@@ -127,7 +122,7 @@ function initMobileGeo(en) {
map
:
tex
,
map
:
tex
,
alphaTest
:
0.01
,
alphaTest
:
0.01
,
transparent
:
true
,
transparent
:
true
,
side
:
THREE
.
DoubleSide
,
side
:
THREE
.
DoubleSide
})
})
cylinderMobileGroup
.
children
[
i
].
material
.
needsUpdate
=
true
cylinderMobileGroup
.
children
[
i
].
material
.
needsUpdate
=
true
cylinderMobileGroup
.
children
[
i
].
material
=
mat
cylinderMobileGroup
.
children
[
i
].
material
=
mat
...
@@ -144,7 +139,7 @@ function initPcGeo(en) {
...
@@ -144,7 +139,7 @@ function initPcGeo(en) {
const
_debugMaterial
=
new
THREE
.
MeshBasicMaterial
({
const
_debugMaterial
=
new
THREE
.
MeshBasicMaterial
({
color
:
16777215
/
(
sliceIndex
*
10
+
1
),
color
:
16777215
/
(
sliceIndex
*
10
+
1
),
transparent
:
true
,
transparent
:
true
,
opacity
:
0.0002
,
opacity
:
0.0002
})
})
const
geo
=
new
THREE
.
PlaneGeometry
(
w
,
planeHeight
)
const
geo
=
new
THREE
.
PlaneGeometry
(
w
,
planeHeight
)
...
@@ -163,7 +158,7 @@ function initPcGeo(en) {
...
@@ -163,7 +158,7 @@ function initPcGeo(en) {
map
:
tex
,
map
:
tex
,
alphaTest
:
0.01
,
alphaTest
:
0.01
,
transparent
:
true
,
transparent
:
true
,
side
:
THREE
.
DoubleSide
,
side
:
THREE
.
DoubleSide
})
})
cylinderGroup
.
children
[
i
].
material
.
needsUpdate
=
true
cylinderGroup
.
children
[
i
].
material
.
needsUpdate
=
true
cylinderGroup
.
children
[
i
].
material
=
mat
cylinderGroup
.
children
[
i
].
material
=
mat
...
@@ -186,14 +181,16 @@ function init(en) {
...
@@ -186,14 +181,16 @@ function init(en) {
target
.
appendChild
(
renderer
.
domElement
)
target
.
appendChild
(
renderer
.
domElement
)
// set the camera with the frustum parameters
// set the camera with the frustum parameters
camera
=
new
THREE
.
PerspectiveCamera
(
30
,
getWindowWidth
()
/
getWindowHeight
(),
1
,
1500
)
camera
=
new
THREE
.
PerspectiveCamera
(
30
,
getWindowWidth
()
/
getWindowHeight
(),
1
,
1500
)
controls
=
new
THREE
.
OrbitControls
(
camera
,
renderer
.
domElement
)
controls
=
new
THREE
.
OrbitControls
(
camera
,
renderer
.
domElement
)
controls
.
dampingFactor
=
0.6
controls
.
minPolarAngle
=
Math
.
PI
/
2
-
0.05
controls
.
minPolarAngle
=
Math
.
PI
/
2
-
0.03
controls
.
maxPolarAngle
=
controls
.
minPolarAngle
controls
.
maxPolarAngle
=
controls
.
minPolarAngle
controls
.
enableZoom
=
false
controls
.
enableZoom
=
false
controls
.
mouseButtons
=
{
ORBIT
:
THREE
.
MOUSE
.
LEFT
}
controls
.
enableKeys
=
false
controls
.
enableKeys
=
false
controls
.
rotateSpeed
=
0.5
controls
.
rotateSpeed
=
0.5
...
@@ -203,11 +200,70 @@ function init(en) {
...
@@ -203,11 +200,70 @@ function init(en) {
renderer
.
render
(
scene
,
camera
)
renderer
.
render
(
scene
,
camera
)
scene
.
fog
=
new
THREE
.
Fog
(
0xe3e3e3
,
200
,
isMobile
?
640
:
1024
)
scene
.
fog
=
new
THREE
.
Fog
(
0xe3e3e3
,
200
,
isMobile
?
640
:
1024
)
if
(
isMobile
)
{
cylinderGroup
=
new
THREE
.
Group
()
initMobileGeo
(
en
)
cylinderMobileGroup
=
new
THREE
.
Group
()
cylinderMobileGroup
.
position
.
y
+=
60
for
(
let
sliceIndex
=
0
;
sliceIndex
<
slice
;
sliceIndex
++
)
{
const
r
=
16384
/
Math
.
PI
/
12
const
w
=
r
*
Math
.
sin
(
Math
.
PI
/
slice
)
*
2
const
h
=
1024
/
6
const
rotation
=
((
2
*
Math
.
PI
)
/
slice
)
*
sliceIndex
const
_debugMaterial
=
new
THREE
.
MeshBasicMaterial
({
color
:
16777215
/
(
sliceIndex
*
10
+
1
),
transparent
:
true
,
opacity
:
0.0002
})
const
geo
=
new
THREE
.
PlaneGeometry
(
w
,
h
)
geo
.
translate
(
0
,
0
,
r
*
Math
.
cos
(
Math
.
PI
/
slice
))
geo
.
rotateY
(
rotation
)
const
mesh
=
new
THREE
.
Mesh
(
geo
,
_debugMaterial
)
cylinderGroup
.
add
(
mesh
)
const
geo2
=
new
THREE
.
PlaneGeometry
(
w
/
2
,
h
)
geo2
.
translate
(
0
,
-
56
,
0.5
*
r
*
Math
.
cos
(
Math
.
PI
/
slice
))
geo2
.
rotateY
(
rotation
)
const
mesh2
=
new
THREE
.
Mesh
(
geo2
,
_debugMaterial
)
cylinderMobileGroup
.
add
(
mesh2
)
}
if
(
isMobile
)
{
scene
.
add
(
cylinderMobileGroup
)
}
else
{
}
else
{
initPcGeo
(
en
)
initPcGeo
(
en
)
}
}
genMaterialArray
(
false
,
en
,
function
(
canvasArray
)
{
for
(
let
i
=
0
;
i
<
slice
;
i
++
)
{
let
tex
=
new
THREE
.
TextureLoader
().
load
(
canvasArray
[
i
])
tex
.
anisotropy
=
renderer
.
capabilities
.
getMaxAnisotropy
()
let
mat
=
new
THREE
.
MeshBasicMaterial
({
map
:
tex
,
alphaTest
:
0.01
,
transparent
:
true
,
side
:
THREE
.
DoubleSide
})
cylinderGroup
.
children
[
i
].
material
.
needsUpdate
=
true
cylinderGroup
.
children
[
i
].
material
=
mat
}
})
genMaterialArray
(
true
,
en
,
function
(
canvasArray
)
{
for
(
let
i
=
0
;
i
<
slice
;
i
++
)
{
let
tex
=
new
THREE
.
TextureLoader
().
load
(
canvasArray
[
i
])
tex
.
anisotropy
=
renderer
.
capabilities
.
getMaxAnisotropy
()
let
mat
=
new
THREE
.
MeshBasicMaterial
({
map
:
tex
,
alphaTest
:
0.01
,
transparent
:
true
,
side
:
THREE
.
DoubleSide
})
cylinderMobileGroup
.
children
[
i
].
material
.
needsUpdate
=
true
cylinderMobileGroup
.
children
[
i
].
material
=
mat
}
})
controls
.
update
()
controls
.
update
()
onWindowResize
()
onWindowResize
()
changeMobile
(
true
)
changeMobile
(
true
)
...
@@ -224,22 +280,22 @@ function handleWindowResize() {
...
@@ -224,22 +280,22 @@ function handleWindowResize() {
function
changeMobile
(
forceUpdate
=
false
)
{
function
changeMobile
(
forceUpdate
=
false
)
{
var
tmpIsMobile
=
checkMobile
()
var
tmpIsMobile
=
checkMobile
()
if
(
forceUpdate
||
isMobile
!=
tmpIsMobile
)
{
if
(
forceUpdate
||
isMobile
!=
tmpIsMobile
)
{
isMobile
=
tmpIsMobile
isMobile
=
tmpIsMobile
if
(
isMobile
)
{
if
(
isMobile
)
{
scene
.
remove
(
cylinderGroup
)
scene
.
remove
(
cylinderGroup
)
if
(
!
cylinderMobileGroup
)
{
if
(
!
cylinderMobileGroup
)
{
initMobileGeo
(
lan
)
initMobileGeo
(
lan
)
}
}
scene
.
add
(
cylinderMobileGroup
)
scene
.
add
(
cylinderMobileGroup
)
}
else
{
}
else
{
scene
.
remove
(
cylinderMobileGroup
)
scene
.
remove
(
cylinderMobileGroup
)
if
(
!
cylinderGroup
)
{
if
(
!
cylinderGroup
)
{
initPcGeo
(
lan
)
initPcGeo
(
lan
)
}
}
scene
.
add
(
cylinderGroup
)
scene
.
add
(
cylinderGroup
)
}
}
camera
.
position
.
set
(
0
,
0
,
isMobile
?
700
:
100
0
)
camera
.
position
.
set
(
0
,
0
,
isMobile
?
650
:
85
0
)
scene
.
fog
.
near
=
isMobile
?
500
:
500
scene
.
fog
.
near
=
isMobile
?
500
:
500
scene
.
fog
.
far
=
isMobile
?
550
:
1500
scene
.
fog
.
far
=
isMobile
?
550
:
1500
controls
.
update
()
controls
.
update
()
...
@@ -260,10 +316,10 @@ function onWindowResize() {
...
@@ -260,10 +316,10 @@ function onWindowResize() {
}
}
function
animate
(
time
)
{
function
animate
(
time
)
{
animId
=
requestAnimationFrame
(
animate
)
animId
=
requestAnimationFrame
(
animate
)
if
(
isMobile
)
{
if
(
isMobile
)
{
cylinderMobileGroup
.
rotation
.
y
=
-
time
*
0.00005
;
cylinderMobileGroup
.
rotation
.
y
=
-
time
*
0.00005
}
else
{
}
else
{
cylinderGroup
.
rotation
.
y
=
-
time
*
0.00005
;
cylinderGroup
.
rotation
.
y
=
-
time
*
0.00005
}
}
render
()
render
()
...
...
static/three.min.js
View file @
01b25aa9
This source diff could not be displayed because it is too large. You can
view the blob
instead.
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