Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
T
ThreeJsLesson
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
钱根
ThreeJsLesson
Commits
0a527e6e
Commit
0a527e6e
authored
Sep 23, 2022
by
Master Q
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
1
parent
c2e93616
Changes
6
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
48 additions
and
69164 deletions
+48
-69164
output.js
output.js
+2
-69149
output.js.map
output.js.map
+1
-1
index.ts
src/CarScene/index.ts
+33
-7
ResJson.ts
src/ResJson.ts
+2
-1
index.ts
src/index.ts
+9
-5
webpack.prod.js
webpack.prod.js
+1
-1
No files found.
output.js
View file @
0a527e6e
This diff is collapsed.
Click to expand it.
output.js.map
View file @
0a527e6e
This diff is collapsed.
Click to expand it.
src/CarScene/index.ts
View file @
0a527e6e
...
@@ -821,6 +821,9 @@ export class CarScene extends PerspectiveScene {
...
@@ -821,6 +821,9 @@ export class CarScene extends PerspectiveScene {
preSpeedNum
:
number
=
0
// 前一帧速度
preSpeedNum
:
number
=
0
// 前一帧速度
preVehiclePositionY
:
number
=
0
// 前一帧高度
preVehiclePositionY
:
number
=
0
// 前一帧高度
_currDistance
:
number
=
0
_currDistance
:
number
=
0
_preVehiclePos
:
THREE
.
Vector3
=
new
THREE
.
Vector3
()
_rotateNum
:
number
=
0
_prerotateflag
:
number
=
0
get
currDistance
()
{
get
currDistance
()
{
return
this
.
_currDistance
return
this
.
_currDistance
...
@@ -833,6 +836,14 @@ export class CarScene extends PerspectiveScene {
...
@@ -833,6 +836,14 @@ export class CarScene extends PerspectiveScene {
})
})
}
}
get
rotateNum
()
{
return
this
.
_rotateNum
}
set
rotateNum
(
v
)
{
this
.
_rotateNum
=
v
}
onEnterFrame
(
e
:
any
)
{
onEnterFrame
(
e
:
any
)
{
const
delta
=
e
.
data
.
delta
const
delta
=
e
.
data
.
delta
if
(
this
.
physicWorld
)
{
if
(
this
.
physicWorld
)
{
...
@@ -846,7 +857,8 @@ export class CarScene extends PerspectiveScene {
...
@@ -846,7 +857,8 @@ export class CarScene extends PerspectiveScene {
this
.
updateCamera
(
this
.
camera
)
this
.
updateCamera
(
this
.
camera
)
if
(
this
.
vehicleIns
&&
this
.
UICtn
)
{
if
(
this
.
vehicleIns
&&
this
.
UICtn
)
{
const
h
=
this
.
vehicleIns
.
chassisMesh
.
position
.
y
const
vehiclePos
=
this
.
vehicleIns
.
chassisMesh
.
position
const
h
=
vehiclePos
.
y
const
currSpeedNum
=
this
.
vehicleIns
.
speedNum
const
currSpeedNum
=
this
.
vehicleIns
.
speedNum
const
minH
=
GameConfig
.
h
const
minH
=
GameConfig
.
h
...
@@ -854,24 +866,38 @@ export class CarScene extends PerspectiveScene {
...
@@ -854,24 +866,38 @@ export class CarScene extends PerspectiveScene {
// 高于 一定高度
// 高于 一定高度
if
(
h
>
minH
)
{
if
(
h
>
minH
)
{
// this.currDistance += currSpeedNum * delta
const
_t
=
new
THREE
.
Vector3
(
vehiclePos
.
x
,
0
,
vehiclePos
.
z
)
const
currflag
=
_defaultVector3
.
crossVectors
(
this
.
_preVehiclePos
,
_t
).
y
let
rn
=
0
if
(
this
.
preVehiclePositionY
<
minH
)
{
if
(
this
.
preVehiclePositionY
<
minH
)
{
console
.
log
(
'开始积分'
)
// 刚开始进入
// 刚开始进入
this
.
currDistance
=
0
this
.
currDistance
=
0
this
.
currDistance
+=
currSpeedNum
*
delta
this
.
rotateNum
=
0
}
else
{
}
else
{
const
isReversal
=
currSpeedNum
*
this
.
preSpeedNum
<
0
const
isReversalSpeed
=
currSpeedNum
*
this
.
preSpeedNum
<
0
if
(
isReversal
)
{
// 跑的方向 相反
const
isReversal
=
this
.
_prerotateflag
*
currflag
<
0
rn
=
this
.
_preVehiclePos
.
angleTo
(
_t
)
if
(
isReversalSpeed
||
isReversal
)
{
this
.
onGameSubmit
(
this
.
currDistance
)
this
.
onGameSubmit
(
this
.
currDistance
)
console
.
log
(
'开始积分'
)
this
.
currDistance
=
0
this
.
currDistance
=
0
this
.
rotateNum
=
0
}
}
this
.
currDistance
+=
currSpeedNum
*
delta
}
}
this
.
currDistance
+=
currSpeedNum
*
delta
this
.
rotateNum
+=
rn
this
.
_preVehiclePos
.
copy
(
_t
)
this
.
_prerotateflag
=
currflag
}
else
{
}
else
{
if
(
this
.
currDistance
!=
0
)
{
if
(
this
.
currDistance
!=
0
)
{
// 提交
// 提交
this
.
onGameSubmit
(
this
.
currDistance
)
this
.
onGameSubmit
(
this
.
currDistance
)
this
.
currDistance
=
0
this
.
currDistance
=
0
this
.
rotateNum
=
0
}
}
}
}
...
@@ -882,7 +908,7 @@ export class CarScene extends PerspectiveScene {
...
@@ -882,7 +908,7 @@ export class CarScene extends PerspectiveScene {
}
}
onGameSubmit
(
n
:
number
)
{
onGameSubmit
(
n
:
number
)
{
console
.
log
(
'当前分数:'
,
Math
.
abs
(
n
))
console
.
log
(
'当前分数:'
,
Math
.
abs
(
n
)
,
'圈数:'
,
(
this
.
rotateNum
/
Math
.
PI
/
2
).
toFixed
(
2
)
)
GDispather
.
dispatchEvent
(
'distanceUpdate'
,
{
GDispather
.
dispatchEvent
(
'distanceUpdate'
,
{
distance
:
Math
.
abs
(
n
)
distance
:
Math
.
abs
(
n
)
})
})
...
...
src/ResJson.ts
View file @
0a527e6e
...
@@ -13,5 +13,6 @@ export const ResJson = {
...
@@ -13,5 +13,6 @@ export const ResJson = {
"name"
:
"skybox"
"name"
:
"skybox"
}
}
],
],
"path"
:
"./resource/"
// eslint-disable-next-line
"path"
:
"https://yun.duiba.com.cn/db_games/activity/template/1663753225/resource/"
}
}
\ No newline at end of file
src/index.ts
View file @
0a527e6e
...
@@ -27,15 +27,19 @@ export class StageScene {
...
@@ -27,15 +27,19 @@ export class StageScene {
async
initStage
()
{
async
initStage
()
{
RES
.
loadConfig
(
ResJson
)
RES
.
loadConfig
(
ResJson
)
if
(
typeof
Ammo
===
'function'
)
{
// @ts-ignore
// @ts-ignore
Ammo
().
then
(()
=>
{
Ammo
().
then
(()
=>
{
this
.
stage
=
new
CarScene
(
this
.
renderDom
,
this
.
UIParentNode
)
})
}
else
{
this
.
stage
=
new
CarScene
(
this
.
renderDom
,
this
.
UIParentNode
)
this
.
stage
=
new
CarScene
(
this
.
renderDom
,
this
.
UIParentNode
)
})
}
}
}
destroy
()
{
destroy
()
{
this
.
stage
.
destroy
()
this
.
stage
&&
this
.
stage
.
destroy
()
}
}
}
}
\ No newline at end of file
webpack.prod.js
View file @
0a527e6e
...
@@ -4,7 +4,7 @@ const webpack = require('webpack');
...
@@ -4,7 +4,7 @@ const webpack = require('webpack');
const
path
=
require
(
'path'
)
const
path
=
require
(
'path'
)
module
.
exports
=
merge
(
common
,
{
module
.
exports
=
merge
(
common
,
{
mode
:
"
development
"
,
//production development
mode
:
"
production
"
,
//production development
devtool
:
'source-map'
,
devtool
:
'source-map'
,
plugins
:
[
plugins
:
[
]
]
...
...
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