Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
车家大少爷
three.js
提交
a861d97a
T
three.js
项目概览
车家大少爷
/
three.js
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
three.js
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
a861d97a
编写于
3月 14, 2011
作者:
M
Mikael Emtinger
浏览文件
操作
浏览文件
下载
差异文件
Merged with Alterq.
上级
24c75901
b6b0e210
变更
13
展开全部
隐藏空白更改
内联
并排
Showing
13 changed file
with
851 addition
and
412 deletion
+851
-412
build/Three.js
build/Three.js
+242
-230
build/custom/ThreeWebGL.js
build/custom/ThreeWebGL.js
+124
-106
examples/webgl_lines_splines.html
examples/webgl_lines_splines.html
+1
-1
src/animation/Animation.js
src/animation/Animation.js
+112
-64
src/animation/AnimationHandler.js
src/animation/AnimationHandler.js
+10
-4
src/cameras/PathCamera.js
src/cameras/PathCamera.js
+351
-0
src/cameras/QuakeCamera.js
src/cameras/QuakeCamera.js
+3
-3
src/core/Matrix4.js
src/core/Matrix4.js
+1
-0
src/core/Spline.js
src/core/Spline.js
+1
-1
utils/build.py
utils/build.py
+3
-0
utils/exporters/blender/2.49/convert_obj_threejs_slim.py
utils/exporters/blender/2.49/convert_obj_threejs_slim.py
+1
-1
utils/exporters/cinema4d/convert_obj_threejs_slim.py
utils/exporters/cinema4d/convert_obj_threejs_slim.py
+1
-1
utils/exporters/convert_obj_threejs_slim.py
utils/exporters/convert_obj_threejs_slim.py
+1
-1
未找到文件。
build/Three.js
浏览文件 @
a861d97a
因为 它太大了无法显示 source diff 。你可以改为
查看blob
。
build/custom/ThreeWebGL.js
浏览文件 @
a861d97a
此差异已折叠。
点击以展开。
examples/webgl_lines_splines.html
浏览文件 @
a861d97a
...
...
@@ -99,7 +99,7 @@
for
(
i
=
0
;
i
<
points
.
length
*
n_sub
;
i
++
)
{
index
=
i
/
(
points
.
length
*
n_sub
);
position
=
spline
.
get
2D
Point
(
points
,
index
);
position
=
spline
.
getPoint
(
points
,
index
);
geometry
.
vertices
[
i
]
=
new
THREE
.
Vertex
(
new
THREE
.
Vector3
(
position
.
x
,
position
.
y
,
position
.
z
)
);
...
...
src/animation/Animation.js
浏览文件 @
a861d97a
/**
* @author mikael emtinger / http://gomo.se/
* @author mrdoob / http://mrdoob.com/
* @author alteredq / http://alteredqualia.com/
*/
THREE
.
Animation
=
function
(
root
,
data
,
interpolationType
,
JITCompile
)
{
...
...
@@ -14,11 +16,13 @@ THREE.Animation = function( root, data, interpolationType, JITCompile ) {
this
.
loop
=
true
;
this
.
interpolationType
=
interpolationType
!==
undefined
?
interpolationType
:
THREE
.
AnimationHandler
.
LINEAR
;
this
.
JITCompile
=
JITCompile
!==
undefined
?
JITCompile
:
true
;
}
/*
* Play
*/
this
.
points
=
[];
this
.
target
=
new
THREE
.
Vector3
();
};
// Play
THREE
.
Animation
.
prototype
.
play
=
function
(
loop
,
startTimeMS
)
{
...
...
@@ -31,22 +35,32 @@ THREE.Animation.prototype.play = function( loop, startTimeMS ) {
// reset key cache
for
(
var
h
=
0
;
h
<
this
.
hierarchy
.
length
;
h
++
)
{
var
h
,
hl
=
this
.
hierarchy
.
length
,
object
;
for
(
h
=
0
;
h
<
hl
;
h
++
)
{
this
.
hierarchy
[
h
].
useQuaternion
=
true
;
this
.
hierarchy
[
h
].
matrixAutoUpdate
=
true
;
object
=
this
.
hierarchy
[
h
];
if
(
this
.
interpolationType
!==
THREE
.
AnimationHandler
.
CATMULLROM_FORWARD
)
{
if
(
this
.
hierarchy
[
h
].
animationCache
===
undefined
)
{
object
.
useQuaternion
=
true
;
this
.
hierarchy
[
h
].
animationCache
=
{};
this
.
hierarchy
[
h
].
animationCache
.
prevKey
=
{
pos
:
0
,
rot
:
0
,
scl
:
0
};
this
.
hierarchy
[
h
].
animationCache
.
nextKey
=
{
pos
:
0
,
rot
:
0
,
scl
:
0
};
this
.
hierarchy
[
h
].
animationCache
.
originalMatrix
=
this
.
hierarchy
[
h
]
instanceof
THREE
.
Bone
?
this
.
hierarchy
[
h
].
skinMatrix
:
this
.
hierarchy
[
h
].
matrix
;
}
object
.
matrixAutoUpdate
=
true
;
if
(
object
.
animationCache
===
undefined
)
{
var
prevKey
=
this
.
hierarchy
[
h
].
animationCache
.
prevKey
;
var
nextKey
=
this
.
hierarchy
[
h
].
animationCache
.
nextKey
;
object
.
animationCache
=
{};
object
.
animationCache
.
prevKey
=
{
pos
:
0
,
rot
:
0
,
scl
:
0
};
object
.
animationCache
.
nextKey
=
{
pos
:
0
,
rot
:
0
,
scl
:
0
};
object
.
animationCache
.
originalMatrix
=
object
instanceof
THREE
.
Bone
?
object
.
skinMatrix
:
object
.
matrix
;
}
var
prevKey
=
object
.
animationCache
.
prevKey
;
var
nextKey
=
object
.
animationCache
.
nextKey
;
prevKey
.
pos
=
this
.
data
.
hierarchy
[
h
].
keys
[
0
];
prevKey
.
rot
=
this
.
data
.
hierarchy
[
h
].
keys
[
0
];
...
...
@@ -55,20 +69,22 @@ THREE.Animation.prototype.play = function( loop, startTimeMS ) {
nextKey
.
pos
=
this
.
getNextKeyWith
(
"
pos
"
,
h
,
1
);
nextKey
.
rot
=
this
.
getNextKeyWith
(
"
rot
"
,
h
,
1
);
nextKey
.
scl
=
this
.
getNextKeyWith
(
"
scl
"
,
h
,
1
);
}
this
.
update
(
0
);
}
this
.
isPaused
=
false
;
THREE
.
AnimationHandler
.
addToUpdate
(
this
);
};
/*
* Pause
*/
// Pause
THREE
.
Animation
.
prototype
.
pause
=
function
()
{
...
...
@@ -83,12 +99,11 @@ THREE.Animation.prototype.pause = function() {
}
this
.
isPaused
=
!
this
.
isPaused
;
}
};
/*
* Stop
*/
// Stop
THREE
.
Animation
.
prototype
.
stop
=
function
()
{
...
...
@@ -110,19 +125,20 @@ THREE.Animation.prototype.stop = function() {
}
else
{
this
.
hierarchy
[
h
].
matrix
=
this
.
hierarchy
[
h
].
animationCache
.
originalMatrix
;
}
delete
this
.
hierarchy
[
h
].
animationCache
;
delete
this
.
hierarchy
[
h
].
animationCache
;
}
}
}
}
;
/*
* Update
*/
// Update
THREE
.
Animation
.
prototype
.
update
=
function
(
deltaTimeMS
)
{
...
...
@@ -144,6 +160,7 @@ THREE.Animation.prototype.update = function( deltaTimeMS ) {
var
frame
;
var
JIThierarchy
=
this
.
data
.
JIT
.
hierarchy
;
var
currentTime
,
unloopedCurrentTime
;
var
currentPoint
,
forwardPoint
,
angle
;
// update
...
...
@@ -172,13 +189,14 @@ THREE.Animation.prototype.update = function( deltaTimeMS ) {
object
.
matrixAutoUpdate
=
false
;
object
.
matrixWorldNeedsUpdate
=
false
;
}
else
{
}
else
{
object
.
matrix
=
JIThierarchy
[
h
][
frame
];
object
.
matrixAutoUpdate
=
false
;
object
.
matrixWorldNeedsUpdate
=
true
;
}
// use interpolation
...
...
@@ -277,39 +295,54 @@ THREE.Animation.prototype.update = function( deltaTimeMS ) {
if
(
type
===
"
pos
"
)
{
vector
=
object
.
position
;
if
(
this
.
interpolationType
===
THREE
.
AnimationHandler
.
LINEAR
)
{
vector
=
object
.
position
;
vector
.
x
=
prevXYZ
[
0
]
+
(
nextXYZ
[
0
]
-
prevXYZ
[
0
]
)
*
scale
;
vector
.
y
=
prevXYZ
[
1
]
+
(
nextXYZ
[
1
]
-
prevXYZ
[
1
]
)
*
scale
;
vector
.
z
=
prevXYZ
[
2
]
+
(
nextXYZ
[
2
]
-
prevXYZ
[
2
]
)
*
scale
;
}
else
{
var
points
=
[];
}
else
if
(
this
.
interpolationType
===
THREE
.
AnimationHandler
.
CATMULLROM
||
this
.
interpolationType
===
THREE
.
AnimationHandler
.
CATMULLROM_FORWARD
)
{
points
[
0
]
=
this
.
getPrevKeyWith
(
type
,
h
,
prevKey
.
index
-
1
)[
type
];
points
[
1
]
=
prevXYZ
;
points
[
2
]
=
nextXYZ
;
points
[
3
]
=
this
.
getNextKeyWith
(
type
,
h
,
nextKey
.
index
+
1
)[
type
];
this
.
points
[
0
]
=
this
.
getPrevKeyWith
(
"
pos
"
,
h
,
prevKey
.
index
-
1
)[
"
pos
"
];
this
.
points
[
1
]
=
prevXYZ
;
this
.
points
[
2
]
=
nextXYZ
;
this
.
points
[
3
]
=
this
.
getNextKeyWith
(
"
pos
"
,
h
,
nextKey
.
index
+
1
)[
"
pos
"
];
scale
=
scale
*
0.33
+
0.33
;
var
result
=
this
.
interpolateCatmullRom
(
points
,
scale
);
currentPoint
=
this
.
interpolateCatmullRom
(
this
.
points
,
scale
);
object
.
position
.
x
=
result
[
0
];
object
.
position
.
y
=
result
[
1
];
object
.
position
.
z
=
result
[
2
];
vector
.
x
=
currentPoint
[
0
];
vector
.
y
=
currentPoint
[
1
];
vector
.
z
=
currentPoint
[
2
];
if
(
this
.
interpolationType
===
THREE
.
AnimationHandler
.
CATMULLROM_FORWARD
)
{
forwardPoint
=
this
.
interpolateCatmullRom
(
this
.
points
,
scale
*
1.01
);
this
.
target
.
set
(
forwardPoint
[
0
],
forwardPoint
[
1
],
forwardPoint
[
2
]
);
this
.
target
.
subSelf
(
vector
);
this
.
target
.
y
=
0
;
this
.
target
.
normalize
();
angle
=
Math
.
atan2
(
this
.
target
.
x
,
this
.
target
.
z
);
object
.
rotation
.
set
(
0
,
angle
,
0
);
}
}
}
else
if
(
type
===
"
rot
"
)
{
}
else
if
(
type
===
"
rot
"
)
{
THREE
.
Quaternion
.
slerp
(
prevXYZ
,
nextXYZ
,
object
.
quaternion
,
scale
);
}
else
if
(
type
===
"
scl
"
)
{
}
else
if
(
type
===
"
scl
"
)
{
vector
=
object
.
scale
;
vector
=
object
.
scale
;
vector
.
x
=
prevXYZ
[
0
]
+
(
nextXYZ
[
0
]
-
prevXYZ
[
0
]
)
*
scale
;
vector
.
y
=
prevXYZ
[
1
]
+
(
nextXYZ
[
1
]
-
prevXYZ
[
1
]
)
*
scale
;
vector
.
z
=
prevXYZ
[
2
]
+
(
nextXYZ
[
2
]
-
prevXYZ
[
2
]
)
*
scale
;
...
...
@@ -350,16 +383,7 @@ THREE.Animation.prototype.update = function( deltaTimeMS ) {
};
/**
* Spline from Tween.js, slightly optimized
* Modified to fit to THREE.Animation.js
*
* http://sole.github.com/tween.js/examples/05_spline.html
*
* @author mrdoob / http://mrdoob.com/
*/
// Catmull-Rom spline
THREE
.
Animation
.
prototype
.
interpolateCatmullRom
=
function
(
points
,
scale
)
{
...
...
@@ -389,8 +413,8 @@ THREE.Animation.prototype.interpolateCatmullRom = function ( points, scale ) {
v3
[
2
]
=
this
.
interpolate
(
pa
[
2
],
pb
[
2
],
pc
[
2
],
pd
[
2
],
weight
,
w2
,
w3
);
return
v3
;
}
};
THREE
.
Animation
.
prototype
.
interpolate
=
function
(
p0
,
p1
,
p2
,
p3
,
t
,
t2
,
t3
)
{
...
...
@@ -398,17 +422,27 @@ THREE.Animation.prototype.interpolate = function( p0, p1, p2, p3, t, t2, t3 ) {
v1
=
(
p3
-
p1
)
*
0.5
;
return
(
2
*
(
p1
-
p2
)
+
v0
+
v1
)
*
t3
+
(
-
3
*
(
p1
-
p2
)
-
2
*
v0
-
v1
)
*
t2
+
v0
*
t
+
p1
;
}
};
/*
* Get next key with
*/
// Get next key with
THREE
.
Animation
.
prototype
.
getNextKeyWith
=
function
(
type
,
h
,
key
)
{
var
keys
=
this
.
data
.
hierarchy
[
h
].
keys
;
key
=
key
%
keys
.
length
;
if
(
this
.
interpolationType
===
THREE
.
AnimationHandler
.
CATMULLROM
||
this
.
interpolationType
===
THREE
.
AnimationHandler
.
CATMULLROM_FORWARD
)
{
key
=
key
<
keys
.
length
-
1
?
key
:
keys
.
length
-
1
;
}
else
{
key
=
key
%
keys
.
length
;
}
for
(
;
key
<
keys
.
length
;
key
++
)
{
...
...
@@ -422,12 +456,25 @@ THREE.Animation.prototype.getNextKeyWith = function( type, h, key ) {
return
this
.
data
.
hierarchy
[
h
].
keys
[
0
];
}
};
// Get previous key with
THREE
.
Animation
.
prototype
.
getPrevKeyWith
=
function
(
type
,
h
,
key
)
{
var
keys
=
this
.
data
.
hierarchy
[
h
].
keys
;
key
=
key
>=
0
?
key
:
key
+
keys
.
length
;
if
(
this
.
interpolationType
===
THREE
.
AnimationHandler
.
CATMULLROM
||
this
.
interpolationType
===
THREE
.
AnimationHandler
.
CATMULLROM_FORWARD
)
{
key
=
key
>
0
?
key
:
0
;
}
else
{
key
=
key
>=
0
?
key
:
key
+
keys
.
length
;
}
for
(
;
key
>=
0
;
key
--
)
{
...
...
@@ -440,4 +487,5 @@ THREE.Animation.prototype.getPrevKeyWith = function( type, h, key ) {
}
return
this
.
data
.
hierarchy
[
h
].
keys
[
keys
.
length
-
1
];
}
};
src/animation/AnimationHandler.js
浏览文件 @
a861d97a
...
...
@@ -50,6 +50,7 @@ THREE.AnimationHandler = (function() {
library
[
data
.
name
]
=
data
;
initData
(
data
);
};
...
...
@@ -66,12 +67,14 @@ THREE.AnimationHandler = (function() {
}
else
{
console
.
log
(
"
THREE.AnimationHandler.get: Couldn't find animation
"
+
name
);
return
null
;
return
null
;
}
}
else
{
}
else
{
// todo: add simple tween library
}
};
...
...
@@ -99,6 +102,7 @@ THREE.AnimationHandler = (function() {
}
return
hierarchy
;
};
var
parseRecurseHierarchy
=
function
(
root
,
hierarchy
)
{
...
...
@@ -107,6 +111,7 @@ THREE.AnimationHandler = (function() {
for
(
var
c
=
0
;
c
<
root
.
children
.
length
;
c
++
)
parseRecurseHierarchy
(
root
.
children
[
c
],
hierarchy
);
}
...
...
@@ -215,6 +220,7 @@ THREE.AnimationHandler = (function() {
data
.
hierarchy
[
h
].
keys
[
k
].
index
=
k
;
}
}
...
...
@@ -236,7 +242,7 @@ THREE.AnimationHandler = (function() {
};
// interpolation types
s
// interpolation types
that
.
LINEAR
=
0
;
that
.
CATMULLROM
=
1
;
...
...
src/cameras/PathCamera.js
0 → 100644
浏览文件 @
a861d97a
/**
* @author alteredq / http://alteredqualia.com/
*
* parameters = {
* fov: <float>,
* aspect: <float>,
* near: <float>,
* far: <float>,
* target: <THREE.Object3D>,
* waypoints: <Array>, // [ [x,y,z], [x,y,z] ... ]
* duration: <float>, // seconds
* createDebugPath: <bool>,
* createDebugDummy: <bool>,
* lookSpeed: <float>,
* lookVertical: <bool>,
* lookHorizontal: <bool>,
* verticalAngleMap: { srcRange: [ <float>, <float> ], dstRange: [ <float>, <float> ] }
* horizontalAngleMap: { srcRange: [ <float>, <float> ], dstRange: [ <float>, <float> ] }
* domElement: <HTMLElement>,
* }
*/
THREE
.
PathCamera
=
function
(
parameters
)
{
THREE
.
Camera
.
call
(
this
,
parameters
.
fov
,
parameters
.
aspect
,
parameters
.
near
,
parameters
.
far
,
parameters
.
target
);
this
.
duration
=
10
*
1000
;
// milliseconds
this
.
waypoints
=
[];
this
.
debugPath
=
new
THREE
.
Object3D
();
this
.
debugDummy
=
new
THREE
.
Object3D
();
this
.
animationParent
=
new
THREE
.
Object3D
();
this
.
lookSpeed
=
0.005
;
this
.
lookVertical
=
true
;
this
.
lookHorizontal
=
true
;
this
.
verticalAngleMap
=
{
srcRange
:
[
0
,
6.28
],
dstRange
:
[
0
,
6.28
]
};
this
.
horizontalAngleMap
=
{
srcRange
:
[
0
,
6.28
],
dstRange
:
[
0
,
6.28
]
};
this
.
domElement
=
document
;
if
(
parameters
)
{
if
(
parameters
.
duration
!==
undefined
)
this
.
duration
=
parameters
.
duration
*
1000
;
if
(
parameters
.
waypoints
!==
undefined
)
this
.
waypoints
=
parameters
.
waypoints
;
if
(
parameters
.
createDebugPath
!==
undefined
)
this
.
createDebugPath
=
parameters
.
createDebugPath
;
if
(
parameters
.
createDebugDummy
!==
undefined
)
this
.
createDebugDummy
=
parameters
.
createDebugDummy
;
if
(
parameters
.
lookSpeed
!==
undefined
)
this
.
lookSpeed
=
parameters
.
lookSpeed
;
if
(
parameters
.
lookVertical
!==
undefined
)
this
.
lookVertical
=
parameters
.
lookVertical
;
if
(
parameters
.
lookHorizontal
!==
undefined
)
this
.
lookHorizontal
=
parameters
.
lookHorizontal
;
if
(
parameters
.
verticalAngleMap
!==
undefined
)
this
.
verticalAngleMap
=
parameters
.
verticalAngleMap
;
if
(
parameters
.
horizontalAngleMap
!==
undefined
)
this
.
horizontalAngleMap
=
parameters
.
horizontalAngleMap
;
if
(
parameters
.
domElement
!==
undefined
)
this
.
domElement
=
parameters
.
domElement
;
}
this
.
mouseX
=
0
;
this
.
mouseY
=
0
;
this
.
lat
=
0
;
this
.
lon
=
0
;
this
.
phi
=
0
;
this
.
theta
=
0
;
this
.
windowHalfX
=
window
.
innerWidth
/
2
;
this
.
windowHalfY
=
window
.
innerHeight
/
2
;
var
PI2
=
Math
.
PI
*
2
,
PI180
=
Math
.
PI
/
180
;
// methods
this
.
updateManual
=
function
()
{
var
srcRange
,
dstRange
;
if
(
this
.
lookHorizontal
)
this
.
lon
+=
this
.
mouseX
*
this
.
lookSpeed
;
if
(
this
.
lookVertical
)
this
.
lat
-=
this
.
mouseY
*
this
.
lookSpeed
;
this
.
lon
=
Math
.
max
(
0
,
Math
.
min
(
360
,
this
.
lon
)
);
this
.
lat
=
Math
.
max
(
-
85
,
Math
.
min
(
85
,
this
.
lat
)
);
this
.
phi
=
(
90
-
this
.
lat
)
*
PI180
;
this
.
theta
=
this
.
lon
*
PI180
;
this
.
phi
=
normalize_angle_rad
(
this
.
phi
);
// constrain vertical look angle
srcRange
=
this
.
verticalAngleMap
.
srcRange
;
dstRange
=
this
.
verticalAngleMap
.
dstRange
;
this
.
phi
=
map_linear
(
this
.
phi
,
srcRange
[
0
],
srcRange
[
1
],
dstRange
[
0
],
dstRange
[
1
]
);
// constrain horizontal look angle
srcRange
=
this
.
horizontalAngleMap
.
srcRange
;
dstRange
=
this
.
horizontalAngleMap
.
dstRange
;
this
.
theta
=
map_linear
(
this
.
theta
,
srcRange
[
0
],
srcRange
[
1
],
dstRange
[
0
],
dstRange
[
1
]
);
var
targetPosition
=
this
.
target
.
position
,
position
=
this
.
position
;
targetPosition
.
x
=
position
.
x
+
100
*
Math
.
sin
(
this
.
phi
)
*
Math
.
cos
(
this
.
theta
);
targetPosition
.
y
=
position
.
y
+
100
*
Math
.
cos
(
this
.
phi
);
targetPosition
.
z
=
position
.
z
+
100
*
Math
.
sin
(
this
.
phi
)
*
Math
.
sin
(
this
.
theta
);
this
.
supr
.
update
.
call
(
this
);
};
this
.
onMouseMove
=
function
(
event
)
{
this
.
mouseX
=
event
.
clientX
-
this
.
windowHalfX
;
this
.
mouseY
=
event
.
clientY
-
this
.
windowHalfY
;
};
// utils
function
normalize_angle_rad
(
a
)
{
var
b
=
a
%
PI2
;
return
b
>=
0
?
b
:
b
+
PI2
;
};
function
cap
(
x
,
a
,
b
)
{
return
(
x
<
a
)
?
a
:
(
(
x
>
b
)
?
b
:
x
);
};
function
map_linear
(
x
,
sa
,
sb
,
ea
,
eb
)
{
return
(
x
-
sa
)
*
(
eb
-
ea
)
/
(
sb
-
sa
)
+
ea
;
};
function
distance
(
a
,
b
)
{
var
dx
=
a
[
0
]
-
b
[
0
],
dy
=
a
[
1
]
-
b
[
1
],
dz
=
a
[
2
]
-
b
[
2
];
return
Math
.
sqrt
(
dx
*
dx
+
dy
*
dy
+
dz
*
dz
);
};
function
bind
(
scope
,
fn
)
{
return
function
()
{
fn
.
apply
(
scope
,
arguments
);
};
};
function
initAnimationPath
(
parent
,
path
,
name
,
duration
)
{
var
animationData
=
{
name
:
name
,
fps
:
0.6
,
length
:
duration
,
hierarchy
:
[]
};
var
i
,
parentAnimation
,
childAnimation
,
pl
=
path
.
length
,
totalLength
=
splineLength
(
path
),
t
=
0
,
first
=
0
,
last
=
pl
-
1
;
parentAnimation
=
{
parent
:
-
1
,
keys
:
[]
};
parentAnimation
.
keys
[
first
]
=
{
time
:
0
,
pos
:
path
[
first
],
rot
:
[
0
,
0
,
0
,
1
],
scl
:
[
1
,
1
,
1
]
};
parentAnimation
.
keys
[
last
]
=
{
time
:
duration
,
pos
:
path
[
last
],
rot
:
[
0
,
0
,
0
,
1
],
scl
:
[
1
,
1
,
1
]
};
console
.
log
(
"
path totalLength:
"
,
totalLength
);
for
(
i
=
first
+
1
;
i
<
last
;
i
++
)
{
t
+=
duration
*
distance
(
path
[
i
],
path
[
i
-
1
]
)
/
totalLength
;
parentAnimation
.
keys
[
i
]
=
{
time
:
t
,
pos
:
path
[
i
]
};
}
animationData
.
hierarchy
[
0
]
=
parentAnimation
;
THREE
.
AnimationHandler
.
add
(
animationData
);
return
new
THREE
.
Animation
(
parent
,
name
,
THREE
.
AnimationHandler
.
CATMULLROM_FORWARD
,
false
);
};
function
createSplineGeometryFromPoints
(
points
,
n_sub
)
{
var
i
,
index
,
position
,
geometry
=
new
THREE
.
Geometry
(),
spline
=
new
THREE
.
Spline
(),
p
,
coords
=
[];
for
(
i
=
0
;
i
<
points
.
length
;
i
++
)
{
p
=
points
[
i
];
coords
[
i
]
=
{
x
:
p
[
0
],
y
:
p
[
1
],
z
:
p
[
2
]
};
}
for
(
i
=
0
;
i
<
coords
.
length
*
n_sub
;
i
++
)
{
index
=
i
/
(
coords
.
length
*
n_sub
);
position
=
spline
.
getPoint
(
coords
,
index
);
geometry
.
vertices
[
i
]
=
new
THREE
.
Vertex
(
new
THREE
.
Vector3
(
position
.
x
,
position
.
y
,
position
.
z
)
);
}
return
geometry
;
};
function
splineLength
(
points
)
{
var
i
,
index
,
p
,
coords
=
[],
spline
=
new
THREE
.
Spline
(),
n_sub
=
100
,
totalLength
=
0
;
for
(
i
=
0
;
i
<
points
.
length
;
i
++
)
{
p
=
points
[
i
];
coords
[
i
]
=
{
x
:
p
[
0
],
y
:
p
[
1
],
z
:
p
[
2
]
};
}
var
oldPosition
=
[
points
[
0
][
0
],
points
[
0
][
1
],
points
[
0
][
2
]
];
for
(
i
=
1
;
i
<
coords
.
length
*
n_sub
;
i
++
)
{
index
=
i
/
(
coords
.
length
*
n_sub
);
position
=
spline
.
getPoint
(
coords
,
index
);
totalLength
+=
distance
(
[
position
.
x
,
position
.
y
,
position
.
z
],
oldPosition
);
oldPosition
=
[
position
.
x
,
position
.
y
,
position
.
z
];
}
return
totalLength
;
};
function
createWaypointGeometryFromPoints
(
points
)
{
var
i
,
position
,
geometry
=
new
THREE
.
Geometry
();
for
(
i
=
0
;
i
<
points
.
length
;
i
++
)
{
position
=
points
[
i
];
geometry
.
vertices
[
i
]
=
new
THREE
.
Vertex
(
new
THREE
.
Vector3
(
position
.
x
,
position
.
y
,
position
.
z
)
);
}
return
geometry
;
};
function
createPath
(
parent
,
path
)
{
var
lineGeo
=
createSplineGeometryFromPoints
(
path
,
10
),
lineMat
=
new
THREE
.
LineBasicMaterial
(
{
color
:
0xff0000
,
linewidth
:
3
}
);
lineObj
=
new
THREE
.
Line
(
lineGeo
,
lineMat
);
lineObj
.
scale
.
set
(
1
,
1
,
1
);
parent
.
addChild
(
lineObj
);
var
waypoint
,
geo
=
new
Sphere
(
1
,
16
,
8
),
mat
=
new
THREE
.
MeshBasicMaterial
(
{
color
:
0x00ff00
}
);
for
(
i
=
0
;
i
<
path
.
length
;
i
++
)
{
waypoint
=
new
THREE
.
Mesh
(
geo
,
mat
);
waypoint
.
position
.
set
(
path
[
i
][
0
],
path
[
i
][
1
],
path
[
i
][
2
]
);
waypoint
.
updateMatrix
();
parent
.
addChild
(
waypoint
);
}
};
if
(
this
.
createDebugDummy
)
{
var
dummyParentMaterial
=
new
THREE
.
MeshLambertMaterial
(
{
color
:
0x0077ff
}
),
dummyChildMaterial
=
new
THREE
.
MeshLambertMaterial
(
{
color
:
0x00ff00
}
),
dummyParentGeo
=
new
Cube
(
10
,
10
,
20
),
dummyChildGeo
=
new
Cube
(
2
,
2
,
10
);
this
.
animationParent
=
new
THREE
.
Mesh
(
dummyParentGeo
,
dummyParentMaterial
);
var
dummyChild
=
new
THREE
.
Mesh
(
dummyChildGeo
,
dummyChildMaterial
);
dummyChild
.
position
.
set
(
0
,
10
,
0
);
this
.
animation
=
initAnimationPath
(
this
.
animationParent
,
this
.
waypoints
,
"
cameraPath01
"
,
this
.
duration
);
this
.
animationParent
.
addChild
(
this
);
this
.
animationParent
.
addChild
(
dummyChild
);
}
else
{
this
.
animation
=
initAnimationPath
(
this
.
animationParent
,
this
.
waypoints
,
"
cameraPath01
"
,
this
.
duration
);
this
.
animationParent
.
addChild
(
this
);
}
if
(
this
.
createDebugPath
)
{
createPath
(
this
.
debugPath
,
this
.
waypoints
);
}
this
.
domElement
.
addEventListener
(
'
mousemove
'
,
bind
(
this
,
this
.
onMouseMove
),
false
);
};
THREE
.
PathCamera
.
prototype
=
new
THREE
.
Camera
();
THREE
.
PathCamera
.
prototype
.
constructor
=
THREE
.
PathCamera
;
THREE
.
PathCamera
.
prototype
.
supr
=
THREE
.
Camera
.
prototype
;
src/cameras/QuakeCamera.js
浏览文件 @
a861d97a
...
...
@@ -72,7 +72,7 @@ THREE.QuakeCamera = function ( parameters ) {
this
.
lat
=
0
;
this
.
lon
=
0
;
this
.
ph
y
=
0
;
this
.
ph
i
=
0
;
this
.
theta
=
0
;
this
.
moveForward
=
false
;
...
...
@@ -125,7 +125,7 @@ THREE.QuakeCamera = function ( parameters ) {
};
this
.
onMouseMove
=
function
(
event
)
{
this
.
onMouseMove
=
function
(
event
)
{
this
.
mouseX
=
event
.
clientX
-
this
.
windowHalfX
;
this
.
mouseY
=
event
.
clientY
-
this
.
windowHalfY
;
...
...
@@ -235,7 +235,7 @@ THREE.QuakeCamera = function ( parameters ) {
};
}
}
;
function
clamp_bottom
(
x
,
a
)
{
...
...
src/core/Matrix4.js
浏览文件 @
a861d97a
...
...
@@ -76,6 +76,7 @@ THREE.Matrix4.prototype = {
if
(
z
.
length
()
===
0
)
{
z
.
z
=
1
;
}
x
.
cross
(
up
,
z
).
normalize
();
...
...
src/core/Spline.js
浏览文件 @
a861d97a
...
...
@@ -11,7 +11,7 @@ THREE.Spline = function () {
point
,
intPoint
,
weight
,
w2
,
w3
,
pa
,
pb
,
pc
,
pd
;
this
.
get
2D
Point
=
function
(
points
,
k
)
{
this
.
getPoint
=
function
(
points
,
k
)
{
point
=
(
points
.
length
-
1
)
*
k
;
intPoint
=
Math
.
floor
(
point
);
...
...
utils/build.py
浏览文件 @
a861d97a
...
...
@@ -33,6 +33,7 @@ COMMON_FILES = [
'animation/Animation.js'
,
'cameras/Camera.js'
,
'cameras/QuakeCamera.js'
,
'cameras/PathCamera.js'
,
'lights/Light.js'
,
'lights/AmbientLight.js'
,
'lights/DirectionalLight.js'
,
...
...
@@ -236,6 +237,8 @@ WEBGL_FILES = [
'core/UV.js'
,
'core/Geometry.js'
,
'cameras/Camera.js'
,
'cameras/QuakeCamera.js'
,
'cameras/PathCamera.js'
,
'lights/Light.js'
,
'lights/AmbientLight.js'
,
'lights/DirectionalLight.js'
,
...
...
utils/exporters/blender/2.49/convert_obj_threejs_slim.py
浏览文件 @
a861d97a
...
...
@@ -242,7 +242,7 @@ def get_name(fname):
"""Create model name based of filename ("path/fname.js" -> "fname").
"""
return
os
.
path
.
splitext
(
os
.
path
.
basename
(
fname
))
return
os
.
path
.
splitext
(
os
.
path
.
basename
(
fname
))
[
0
]
def
bbox
(
vertices
):
"""Compute bounding box of vertex array.
...
...
utils/exporters/cinema4d/convert_obj_threejs_slim.py
浏览文件 @
a861d97a
...
...
@@ -242,7 +242,7 @@ def get_name(fname):
"""Create model name based of filename ("path/fname.js" -> "fname").
"""
return
os
.
path
.
splitext
(
os
.
path
.
basename
(
fname
))
return
os
.
path
.
splitext
(
os
.
path
.
basename
(
fname
))
[
0
]
def
bbox
(
vertices
):
"""Compute bounding box of vertex array.
...
...
utils/exporters/convert_obj_threejs_slim.py
浏览文件 @
a861d97a
...
...
@@ -242,7 +242,7 @@ def get_name(fname):
"""Create model name based of filename ("path/fname.js" -> "fname").
"""
return
os
.
path
.
splitext
(
os
.
path
.
basename
(
fname
))
return
os
.
path
.
splitext
(
os
.
path
.
basename
(
fname
))
[
0
]
def
bbox
(
vertices
):
"""Compute bounding box of vertex array.
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录