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
0fa88afc
Commit
0fa88afc
authored
Mar 13, 2024
by
吕祺
⛹🏽
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
3d one cylinder one time
parent
787ddeb5
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
107 additions
and
72 deletions
+107
-72
addThreeD2.js
static/addThreeD2.js
+107
-72
timeline-cn.png
static/img/timeline-cn.png
+0
-0
No files found.
static/addThreeD2.js
View file @
0fa88afc
var
camera
,
scene
,
renderer
,
controls
,
mat
,
geo
,
tex
var
slice
=
128
var
pcPicWidth
=
17943
var
mobilePicWidth
=
8980
var
slice
=
Math
.
round
(
pcPicWidth
/
256
)
var
isMobile
=
checkMobile
()
var
cylinderGroup
,
cylinderMobileGroup
var
materialArray
,
materialMobileArray
...
...
@@ -8,6 +10,10 @@ var target
var
lan
var
resizeTimer
var
radius
=
pcPicWidth
/
Math
.
PI
/
12
var
planeHeight
=
1024
/
6
window
.
addThreeD
=
function
(
en
)
{
target
=
document
.
querySelector
(
'#threeD'
)
lan
=
en
...
...
@@ -47,8 +53,8 @@ function genMaterialArray(isMobile,en, callback) {
timeline
.
onload
=
function
()
{
const
canvas
=
document
.
createElement
(
'canvas'
)
const
sprite
=
isMobile
?
{
w
:
8980
/
slice
,
h
:
1024
}
:
{
w
:
17943
/
slice
,
h
:
1024
}
?
{
w
:
mobilePicWidth
/
slice
,
h
:
1024
}
:
{
w
:
pcPicWidth
/
slice
,
h
:
1024
}
const
context
=
canvas
.
getContext
(
'2d'
)
canvas
.
height
=
sprite
.
h
canvas
.
width
=
sprite
.
w
...
...
@@ -73,16 +79,16 @@ function genMaterialArray(isMobile,en, callback) {
}
}
function
getWindowWidth
()
{
isMobile
=
checkMobile
()
const
w
=
isMobile
?
window
.
innerWidth
*
2
:
window
.
innerWidth
//
isMobile = checkMobile()
const
w
=
checkMobile
()
?
window
.
innerWidth
*
2
:
window
.
innerWidth
return
w
// > 1440 ? 1440 : w
}
function
getWindowHeight
()
{
if
(
isMobile
)
{
return
window
.
innerHeight
*
0.
9
return
window
.
innerHeight
*
0.
8
}
else
{
return
window
.
innerHeight
*
0.6
6
return
window
.
innerHeight
*
0.6
8
}
}
...
...
@@ -93,73 +99,27 @@ function checkMobile() {
return
mobile
}
function
init
(
en
)
{
if
(
!
target
)
return
if
(
typeof
THREE
===
'undefined'
)
{
console
.
log
(
'three undefined'
)
return
setTimeout
(
function
()
{
init
(
en
)
},
500
)
}
renderer
=
new
THREE
.
WebGLRenderer
({
antialias
:
true
})
renderer
.
setSize
(
getWindowWidth
(),
getWindowHeight
())
renderer
.
setPixelRatio
(
window
.
devicePixelRatio
)
target
.
appendChild
(
renderer
.
domElement
)
// set the camera with the frustum parameters
camera
=
new
THREE
.
PerspectiveCamera
(
30
,
getWindowWidth
()
/
getWindowHeight
(),
1
,
1500
)
controls
=
new
THREE
.
OrbitControls
(
camera
,
renderer
.
domElement
)
controls
.
dampingFactor
=
0.6
controls
.
minPolarAngle
=
Math
.
PI
/
2
-
0.03
controls
.
maxPolarAngle
=
controls
.
minPolarAngle
controls
.
enableZoom
=
false
controls
.
mouseButtons
=
{
ORBIT
:
THREE
.
MOUSE
.
LEFT
}
controls
.
enableKeys
=
false
controls
.
rotateSpeed
=
0.5
// scene is like a graph of everything that will be rendered
scene
=
new
THREE
.
Scene
()
scene
.
background
=
new
THREE
.
Color
(
0xffffff
)
renderer
.
render
(
scene
,
camera
)
scene
.
fog
=
new
THREE
.
Fog
(
0xe3e3e3
,
200
,
isMobile
?
640
:
1024
)
cylinderGroup
=
new
THREE
.
Group
()
cylinderGroup
.
position
.
y
-=
30
function
initMobileGeo
(
en
)
{
cylinderMobileGroup
=
new
THREE
.
Group
()
cylinderMobileGroup
.
position
.
y
+=
30
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
w
=
radius
*
Math
.
sin
(
Math
.
PI
/
slice
)
*
2
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
))
const
geo2
=
new
THREE
.
PlaneGeometry
(
w
/
2
,
planeHeight
)
geo2
.
translate
(
0
,
-
56
,
0.5
*
radius
*
Math
.
cos
(
Math
.
PI
/
slice
))
geo2
.
rotateY
(
rotation
)
const
mesh2
=
new
THREE
.
Mesh
(
geo2
,
_debugMaterial
)
cylinderMobileGroup
.
add
(
mesh2
)
}
scene
.
add
(
cylinderGroup
)
scene
.
add
(
cylinderMobileGroup
)
genMaterialArray
(
false
,
en
,
function
(
canvasArray
)
{
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
()
...
...
@@ -169,11 +129,33 @@ function init(en) {
transparent
:
true
,
side
:
THREE
.
DoubleSide
,
})
cylinderGroup
.
children
[
i
].
material
.
needsUpdate
=
true
cylinderGroup
.
children
[
i
].
material
=
mat
cylinder
Mobile
Group
.
children
[
i
].
material
.
needsUpdate
=
true
cylinder
Mobile
Group
.
children
[
i
].
material
=
mat
}
})
genMaterialArray
(
true
,
en
,
function
(
canvasArray
)
{
}
function
initPcGeo
(
en
)
{
cylinderGroup
=
new
THREE
.
Group
()
cylinderGroup
.
position
.
y
-=
30
for
(
let
sliceIndex
=
0
;
sliceIndex
<
slice
;
sliceIndex
++
)
{
const
w
=
radius
*
Math
.
sin
(
Math
.
PI
/
slice
)
*
2
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
,
planeHeight
)
geo
.
translate
(
0
,
0
,
radius
*
Math
.
cos
(
Math
.
PI
/
slice
))
geo
.
rotateY
(
rotation
)
const
mesh
=
new
THREE
.
Mesh
(
geo
,
_debugMaterial
)
cylinderGroup
.
add
(
mesh
)
}
scene
.
add
(
cylinderGroup
)
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
()
...
...
@@ -183,13 +165,52 @@ function init(en) {
transparent
:
true
,
side
:
THREE
.
DoubleSide
,
})
cylinder
Mobile
Group
.
children
[
i
].
material
.
needsUpdate
=
true
cylinder
Mobile
Group
.
children
[
i
].
material
=
mat
cylinderGroup
.
children
[
i
].
material
.
needsUpdate
=
true
cylinderGroup
.
children
[
i
].
material
=
mat
}
})
}
function
init
(
en
)
{
if
(
!
target
)
return
if
(
typeof
THREE
===
'undefined'
)
{
console
.
log
(
'three undefined'
)
return
setTimeout
(
function
()
{
init
(
en
)
},
500
)
}
renderer
=
new
THREE
.
WebGLRenderer
({
antialias
:
true
})
renderer
.
setSize
(
getWindowWidth
(),
getWindowHeight
())
renderer
.
setPixelRatio
(
window
.
devicePixelRatio
)
target
.
appendChild
(
renderer
.
domElement
)
// set the camera with the frustum parameters
camera
=
new
THREE
.
PerspectiveCamera
(
30
,
getWindowWidth
()
/
getWindowHeight
(),
1
,
1500
)
controls
=
new
THREE
.
OrbitControls
(
camera
,
renderer
.
domElement
)
controls
.
dampingFactor
=
0.6
controls
.
minPolarAngle
=
Math
.
PI
/
2
-
0.03
controls
.
maxPolarAngle
=
controls
.
minPolarAngle
controls
.
enableZoom
=
false
controls
.
mouseButtons
=
{
ORBIT
:
THREE
.
MOUSE
.
LEFT
}
controls
.
enableKeys
=
false
controls
.
rotateSpeed
=
0.5
// scene is like a graph of everything that will be rendered
scene
=
new
THREE
.
Scene
()
scene
.
background
=
new
THREE
.
Color
(
0xffffff
)
renderer
.
render
(
scene
,
camera
)
scene
.
fog
=
new
THREE
.
Fog
(
0xe3e3e3
,
200
,
isMobile
?
640
:
1024
)
if
(
isMobile
)
{
initMobileGeo
(
en
)
}
else
{
initPcGeo
(
en
)
}
controls
.
update
()
onWindowResize
()
changeMobile
()
changeMobile
(
true
)
animate
()
window
.
addEventListener
(
'resize'
,
onWindowResize
,
false
)
}
...
...
@@ -201,14 +222,28 @@ function handleWindowResize() {
window
.
addThreeD
(
lan
)
}
function
changeMobile
()
{
isMobile
=
checkMobile
()
cylinderGroup
.
visible
=
!
isMobile
cylinderMobileGroup
.
visible
=
isMobile
camera
.
position
.
set
(
0
,
0
,
isMobile
?
700
:
1000
)
scene
.
fog
.
near
=
isMobile
?
500
:
500
scene
.
fog
.
far
=
isMobile
?
550
:
1500
controls
.
update
()
function
changeMobile
(
forceUpdate
=
false
)
{
var
tmpIsMobile
=
checkMobile
()
if
(
forceUpdate
||
isMobile
!=
tmpIsMobile
)
{
isMobile
=
tmpIsMobile
if
(
isMobile
)
{
scene
.
remove
(
cylinderGroup
)
if
(
!
cylinderMobileGroup
)
{
initMobileGeo
(
lan
)
}
scene
.
add
(
cylinderMobileGroup
)
}
else
{
scene
.
remove
(
cylinderMobileGroup
)
if
(
!
cylinderGroup
)
{
initPcGeo
(
lan
)
}
scene
.
add
(
cylinderGroup
)
}
camera
.
position
.
set
(
0
,
0
,
isMobile
?
700
:
1000
)
scene
.
fog
.
near
=
isMobile
?
500
:
500
scene
.
fog
.
far
=
isMobile
?
550
:
1500
controls
.
update
()
}
}
function
onWindowResize
()
{
...
...
static/img/timeline-cn.png
View replaced file @
787ddeb5
View file @
0fa88afc
This diff is collapsed.
Click to expand it.
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