Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Ablesons
three.js
提交
6660e155
T
three.js
项目概览
Ablesons
/
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,发现更多精彩内容 >>
提交
6660e155
编写于
10月 04, 2012
作者:
A
alteredq
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
More Closure compile warnings / errors fixing in examples/js.
上级
8109156a
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
196 addition
and
198 deletion
+196
-198
examples/js/CurveExtras.js
examples/js/CurveExtras.js
+18
-21
examples/js/MD2CharacterComplex.js
examples/js/MD2CharacterComplex.js
+8
-8
examples/js/ParametricGeometries.js
examples/js/ParametricGeometries.js
+38
-40
examples/js/Sparks.js
examples/js/Sparks.js
+122
-119
examples/js/loaders/ctm/CTMLoader.js
examples/js/loaders/ctm/CTMLoader.js
+10
-10
未找到文件。
examples/js/CurveExtras.js
浏览文件 @
6660e155
...
...
@@ -16,13 +16,13 @@ THREE.Curves = {};
THREE
.
Curves
.
GrannyKnot
=
THREE
.
Curve
.
create
(
function
(){},
function
(
t
)
{
t
=
2
*
Math
.
PI
*
t
;
var
x
=
-
0.22
*
cos
(
t
)
-
1.28
*
sin
(
t
)
-
0.44
*
cos
(
3
*
t
)
-
0.78
*
sin
(
3
*
t
);
var
y
=
-
0.1
*
cos
(
2
*
t
)
-
0.27
*
sin
(
2
*
t
)
+
0.38
*
cos
(
4
*
t
)
+
0.46
*
sin
(
4
*
t
);
var
z
=
0.7
*
cos
(
3
*
t
)
-
0.4
*
sin
(
3
*
t
);
var
x
=
-
0.22
*
Math
.
cos
(
t
)
-
1.28
*
Math
.
sin
(
t
)
-
0.44
*
Math
.
cos
(
3
*
t
)
-
0.78
*
Math
.
sin
(
3
*
t
);
var
y
=
-
0.1
*
Math
.
cos
(
2
*
t
)
-
0.27
*
Math
.
sin
(
2
*
t
)
+
0.38
*
Math
.
cos
(
4
*
t
)
+
0.46
*
Math
.
sin
(
4
*
t
);
var
z
=
0.7
*
Math
.
cos
(
3
*
t
)
-
0.4
*
Math
.
sin
(
3
*
t
);
return
new
THREE
.
Vector3
(
x
,
y
,
z
).
multiplyScalar
(
20
);
}
);
...
...
@@ -40,7 +40,7 @@ function(t) {
t
*=
2
*
Math
.
PI
;
var
tx
=
16
*
Math
.
pow
(
Math
.
sin
(
t
),
3
);
ty
=
13
*
Math
.
cos
(
t
)
-
5
*
Math
.
cos
(
2
*
t
)
-
2
*
Math
.
cos
(
3
*
t
)
-
Math
.
cos
(
4
*
t
),
tz
=
0
;
var
ty
=
13
*
Math
.
cos
(
t
)
-
5
*
Math
.
cos
(
2
*
t
)
-
2
*
Math
.
cos
(
3
*
t
)
-
Math
.
cos
(
4
*
t
),
tz
=
0
;
return
new
THREE
.
Vector3
(
tx
,
ty
,
tz
).
multiplyScalar
(
this
.
scale
);
...
...
@@ -206,9 +206,6 @@ THREE.Curves.TrefoilPolynomialKnot = THREE.Curve.create(
);
var
sin
=
Math
.
sin
,
pow
=
Math
.
pow
,
cos
=
Math
.
cos
;
// var scaleTo = function(x, y) {
// var r = y - x;
// return function(t) {
...
...
@@ -234,7 +231,7 @@ THREE.Curves.FigureEightPolynomialKnot = THREE.Curve.create(
t
=
scaleTo
(
-
4
,
4
,
t
);
var
tx
=
2
/
5
*
t
*
(
t
*
t
-
7
)
*
(
t
*
t
-
10
),
ty
=
pow
(
t
,
4
)
-
13
*
t
*
t
,
ty
=
Math
.
pow
(
t
,
4
)
-
13
*
t
*
t
,
tz
=
1
/
10
*
t
*
(
t
*
t
-
4
)
*
(
t
*
t
-
9
)
*
(
t
*
t
-
12
);
return
new
THREE
.
Vector3
(
tx
,
ty
,
tz
).
multiplyScalar
(
this
.
scale
);
...
...
@@ -255,9 +252,9 @@ THREE.Curves.DecoratedTorusKnot4a = THREE.Curve.create(
t
*=
Math
.
PI
*
2
;
var
x
=
cos
(
2
*
t
)
*
(
1
+
0.6
*
(
cos
(
5
*
t
)
+
0.75
*
cos
(
10
*
t
))),
y
=
sin
(
2
*
t
)
*
(
1
+
0.6
*
(
cos
(
5
*
t
)
+
0.75
*
cos
(
10
*
t
))),
z
=
0.35
*
sin
(
5
*
t
);
x
=
Math
.
cos
(
2
*
t
)
*
(
1
+
0.6
*
(
Math
.
cos
(
5
*
t
)
+
0.75
*
Math
.
cos
(
10
*
t
))),
y
=
Math
.
sin
(
2
*
t
)
*
(
1
+
0.6
*
(
Math
.
cos
(
5
*
t
)
+
0.75
*
Math
.
cos
(
10
*
t
))),
z
=
0.35
*
Math
.
sin
(
5
*
t
);
return
new
THREE
.
Vector3
(
x
,
y
,
z
).
multiplyScalar
(
this
.
scale
);
...
...
@@ -276,9 +273,9 @@ THREE.Curves.DecoratedTorusKnot4b = THREE.Curve.create(
function
(
t
)
{
var
fi
=
t
*
Math
.
PI
*
2
;
var
x
=
cos
(
2
*
fi
)
*
(
1
+
0.45
*
cos
(
3
*
fi
)
+
0.4
*
cos
(
9
*
fi
)),
y
=
sin
(
2
*
fi
)
*
(
1
+
0.45
*
cos
(
3
*
fi
)
+
0.4
*
cos
(
9
*
fi
)),
z
=
0.2
*
sin
(
9
*
fi
);
var
x
=
Math
.
cos
(
2
*
fi
)
*
(
1
+
0.45
*
Math
.
cos
(
3
*
fi
)
+
0.4
*
Math
.
cos
(
9
*
fi
)),
y
=
Math
.
sin
(
2
*
fi
)
*
(
1
+
0.45
*
Math
.
cos
(
3
*
fi
)
+
0.4
*
Math
.
cos
(
9
*
fi
)),
z
=
0.2
*
Math
.
sin
(
9
*
fi
);
return
new
THREE
.
Vector3
(
x
,
y
,
z
).
multiplyScalar
(
this
.
scale
);
...
...
@@ -298,9 +295,9 @@ THREE.Curves.DecoratedTorusKnot5a = THREE.Curve.create(
function
(
t
)
{
var
fi
=
t
*
Math
.
PI
*
2
;
var
x
=
cos
(
3
*
fi
)
*
(
1
+
0.3
*
cos
(
5
*
fi
)
+
0.5
*
cos
(
10
*
fi
)),
y
=
sin
(
3
*
fi
)
*
(
1
+
0.3
*
cos
(
5
*
fi
)
+
0.5
*
cos
(
10
*
fi
)),
z
=
0.2
*
sin
(
20
*
fi
);
var
x
=
Math
.
cos
(
3
*
fi
)
*
(
1
+
0.3
*
Math
.
cos
(
5
*
fi
)
+
0.5
*
Math
.
cos
(
10
*
fi
)),
y
=
Math
.
sin
(
3
*
fi
)
*
(
1
+
0.3
*
Math
.
cos
(
5
*
fi
)
+
0.5
*
Math
.
cos
(
10
*
fi
)),
z
=
0.2
*
Math
.
sin
(
20
*
fi
);
return
new
THREE
.
Vector3
(
x
,
y
,
z
).
multiplyScalar
(
this
.
scale
);
...
...
@@ -319,9 +316,9 @@ THREE.Curves.DecoratedTorusKnot5c = THREE.Curve.create(
function
(
t
)
{
var
fi
=
t
*
Math
.
PI
*
2
;
var
x
=
cos
(
4
*
fi
)
*
(
1
+
0.5
*
(
cos
(
5
*
fi
)
+
0.4
*
cos
(
20
*
fi
))),
y
=
sin
(
4
*
fi
)
*
(
1
+
0.5
*
(
cos
(
5
*
fi
)
+
0.4
*
cos
(
20
*
fi
))),
z
=
0.35
*
sin
(
15
*
fi
);
var
x
=
Math
.
cos
(
4
*
fi
)
*
(
1
+
0.5
*
(
Math
.
cos
(
5
*
fi
)
+
0.4
*
Math
.
cos
(
20
*
fi
))),
y
=
Math
.
sin
(
4
*
fi
)
*
(
1
+
0.5
*
(
Math
.
cos
(
5
*
fi
)
+
0.4
*
Math
.
cos
(
20
*
fi
))),
z
=
0.35
*
Math
.
sin
(
15
*
fi
);
return
new
THREE
.
Vector3
(
x
,
y
,
z
).
multiplyScalar
(
this
.
scale
);
...
...
examples/js/MD2CharacterComplex.js
浏览文件 @
6660e155
...
...
@@ -117,18 +117,18 @@ THREE.MD2CharacterComplex = function () {
for
(
var
i
=
0
;
i
<
original
.
weapons
.
length
;
i
++
)
{
var
mesh
=
createPart
(
original
.
weapons
[
i
].
geometry
,
this
.
skinsWeapon
[
i
]
);
mesh
.
scale
.
set
(
this
.
scale
,
this
.
scale
,
this
.
scale
);
mesh
.
visible
=
false
;
var
mesh
Weapon
=
createPart
(
original
.
weapons
[
i
].
geometry
,
this
.
skinsWeapon
[
i
]
);
mesh
Weapon
.
scale
.
set
(
this
.
scale
,
this
.
scale
,
this
.
scale
);
mesh
Weapon
.
visible
=
false
;
mesh
.
name
=
name
;
mesh
Weapon
.
name
=
original
.
weapons
[
i
].
name
;
this
.
root
.
add
(
mesh
);
this
.
root
.
add
(
mesh
Weapon
);
this
.
weapons
[
i
]
=
mesh
;
this
.
meshWeapon
=
mesh
;
this
.
weapons
[
i
]
=
mesh
Weapon
;
this
.
meshWeapon
=
mesh
Weapon
;
this
.
meshes
.
push
(
mesh
);
this
.
meshes
.
push
(
mesh
Weapon
);
}
...
...
examples/js/ParametricGeometries.js
浏览文件 @
6660e155
/*
* @author zz85
*
*
* Experimenting of primitive geometry creation using Surface Parametric equations
*
*/
var
sin
=
Math
.
sin
,
cos
=
Math
.
cos
,
pi
=
Math
.
PI
;
THREE
.
ParametricGeometries
=
{
klein
:
function
(
v
,
u
)
{
u
*=
pi
;
v
*=
2
*
pi
;
u
*=
Math
.
PI
;
v
*=
2
*
Math
.
PI
;
u
=
u
*
2
;
var
x
,
y
,
z
;
if
(
u
<
pi
)
{
x
=
3
*
cos
(
u
)
*
(
1
+
sin
(
u
))
+
(
2
*
(
1
-
cos
(
u
)
/
2
))
*
cos
(
u
)
*
cos
(
v
);
z
=
-
8
*
sin
(
u
)
-
2
*
(
1
-
cos
(
u
)
/
2
)
*
sin
(
u
)
*
cos
(
v
);
if
(
u
<
Math
.
PI
)
{
x
=
3
*
Math
.
cos
(
u
)
*
(
1
+
Math
.
sin
(
u
))
+
(
2
*
(
1
-
Math
.
cos
(
u
)
/
2
))
*
Math
.
cos
(
u
)
*
Math
.
cos
(
v
);
z
=
-
8
*
Math
.
sin
(
u
)
-
2
*
(
1
-
Math
.
cos
(
u
)
/
2
)
*
Math
.
sin
(
u
)
*
Math
.
cos
(
v
);
}
else
{
x
=
3
*
cos
(
u
)
*
(
1
+
sin
(
u
))
+
(
2
*
(
1
-
cos
(
u
)
/
2
))
*
cos
(
v
+
pi
);
z
=
-
8
*
sin
(
u
);
x
=
3
*
Math
.
cos
(
u
)
*
(
1
+
Math
.
sin
(
u
))
+
(
2
*
(
1
-
Math
.
cos
(
u
)
/
2
))
*
Math
.
cos
(
v
+
Math
.
PI
);
z
=
-
8
*
Math
.
sin
(
u
);
}
y
=
-
2
*
(
1
-
cos
(
u
)
/
2
)
*
sin
(
v
);
y
=
-
2
*
(
1
-
Math
.
cos
(
u
)
/
2
)
*
Math
.
sin
(
v
);
return
new
THREE
.
Vector3
(
x
,
y
,
z
);
},
plane
:
function
(
width
,
height
)
{
return
function
(
u
,
v
)
{
var
x
=
u
*
width
;
var
y
=
0
;
...
...
@@ -45,14 +43,14 @@ THREE.ParametricGeometries = {
// flat mobius strip
// http://www.wolframalpha.com/input/?i=M%C3%B6bius+strip+parametric+equations&lk=1&a=ClashPrefs_*Surface.MoebiusStrip.SurfaceProperty.ParametricEquations-
u
=
u
-
0.5
;
var
v
=
2
*
pi
*
t
;
var
v
=
2
*
Math
.
PI
*
t
;
var
x
,
y
,
z
;
var
a
=
2
;
x
=
cos
(
v
)
*
(
a
+
u
*
cos
(
v
/
2
));
y
=
sin
(
v
)
*
(
a
+
u
*
cos
(
v
/
2
));
z
=
u
*
sin
(
v
/
2
);
x
=
Math
.
cos
(
v
)
*
(
a
+
u
*
Math
.
cos
(
v
/
2
));
y
=
Math
.
sin
(
v
)
*
(
a
+
u
*
Math
.
cos
(
v
/
2
));
z
=
u
*
Math
.
sin
(
v
/
2
);
return
new
THREE
.
Vector3
(
x
,
y
,
z
);
},
...
...
@@ -60,17 +58,17 @@ THREE.ParametricGeometries = {
mobius3d
:
function
(
u
,
t
)
{
// volumetric mobius strip
u
*=
pi
;
t
*=
2
*
pi
;
u
*=
Math
.
PI
;
t
*=
2
*
Math
.
PI
;
u
=
u
*
2
;
var
phi
=
u
/
2
;
var
major
=
2.25
,
a
=
0.125
,
b
=
0.65
;
var
x
,
y
,
z
;
x
=
a
*
cos
(
t
)
*
cos
(
phi
)
-
b
*
sin
(
t
)
*
sin
(
phi
);
z
=
a
*
cos
(
t
)
*
sin
(
phi
)
+
b
*
sin
(
t
)
*
cos
(
phi
);
y
=
(
major
+
x
)
*
sin
(
u
);
x
=
(
major
+
x
)
*
cos
(
u
);
x
=
a
*
Math
.
cos
(
t
)
*
Math
.
cos
(
phi
)
-
b
*
Math
.
sin
(
t
)
*
Math
.
sin
(
phi
);
z
=
a
*
Math
.
cos
(
t
)
*
Math
.
sin
(
phi
)
+
b
*
Math
.
sin
(
t
)
*
Math
.
cos
(
phi
);
y
=
(
major
+
x
)
*
Math
.
sin
(
u
);
x
=
(
major
+
x
)
*
Math
.
cos
(
u
);
return
new
THREE
.
Vector3
(
x
,
y
,
z
);
}
...
...
@@ -114,11 +112,11 @@ THREE.ParametricGeometries.TubeGeometry = function(path, segments, radius, segme
this
.
normals
=
normals
;
this
.
binormals
=
binormals
;
var
ParametricTube
=
function
(
u
,
v
)
{
v
*=
2
*
pi
;
v
*=
2
*
Math
.
PI
;
i
=
u
*
(
numpoints
-
1
);
i
=
Math
.
floor
(
i
);
...
...
@@ -135,7 +133,7 @@ THREE.ParametricGeometries.TubeGeometry = function(path, segments, radius, segme
scope
.
debug
.
add
(
new
THREE
.
ArrowHelper
(
binormal
,
pos
,
radius
,
0x00ff00
));
}
cx
=
-
scope
.
radius
*
Math
.
cos
(
v
);
// TODO: Hack: Negating it so it faces outside.
cy
=
scope
.
radius
*
Math
.
sin
(
v
);
...
...
@@ -170,8 +168,8 @@ THREE.ParametricGeometries.TorusKnotGeometry = function ( radius, tube, segments
this
.
p
=
p
||
2
;
this
.
q
=
q
||
3
;
this
.
heightScale
=
heightScale
||
1
;
var
TorusKnotCurve
=
THREE
.
Curve
.
create
(
function
()
{
...
...
@@ -212,17 +210,17 @@ THREE.ParametricGeometries.TorusKnotGeometry.prototype = Object.create( THREE.Ge
THREE
.
ParametricGeometries
.
SphereGeometry
=
function
(
size
,
u
,
v
)
{
function
sphere
(
u
,
v
)
{
u
*=
pi
;
v
*=
2
*
pi
;
var
x
=
size
*
sin
(
u
)
*
cos
(
v
);
var
y
=
size
*
sin
(
u
)
*
sin
(
v
);
var
z
=
size
*
cos
(
u
);
u
*=
Math
.
PI
;
v
*=
2
*
Math
.
PI
;
var
x
=
size
*
Math
.
sin
(
u
)
*
Math
.
cos
(
v
);
var
y
=
size
*
Math
.
sin
(
u
)
*
Math
.
sin
(
v
);
var
z
=
size
*
Math
.
cos
(
u
);
return
new
THREE
.
Vector3
(
x
,
y
,
z
);
}
THREE
.
ParametricGeometry
.
call
(
this
,
sphere
,
u
,
v
,
!
true
);
};
...
...
@@ -239,14 +237,14 @@ THREE.ParametricGeometries.SphereGeometry.prototype = Object.create( THREE.Geome
THREE
.
ParametricGeometries
.
PlaneGeometry
=
function
(
width
,
depth
,
segmentsWidth
,
segmentsDepth
)
{
function
plane
(
u
,
v
)
{
var
x
=
u
*
width
;
var
y
=
0
;
var
z
=
v
*
depth
;
return
new
THREE
.
Vector3
(
x
,
y
,
z
);
}
THREE
.
ParametricGeometry
.
call
(
this
,
plane
,
segmentsWidth
,
segmentsDepth
);
};
...
...
examples/js/Sparks.js
浏览文件 @
6660e155
...
...
@@ -6,7 +6,7 @@
*
* for feature requests or bugs, please visit https://github.com/zz85/sparks.js
*
* licensed under the MIT license
* licensed under the MIT license
*/
var
SPARKS
=
{};
...
...
@@ -18,106 +18,109 @@ var SPARKS = {};
*********************************/
SPARKS
.
Emitter
=
function
(
counter
)
{
this
.
_counter
=
counter
?
counter
:
new
SPARKS
.
SteadyCounter
(
10
);
// provides number of particles to produce
this
.
_particles
=
[];
this
.
_initializers
=
[];
// use for creation of particles
this
.
_actions
=
[];
// uses action to update particles
this
.
_activities
=
[];
// not supported yet
this
.
_handlers
=
[];
this
.
callbacks
=
{};
};
SPARKS
.
Emitter
.
prototype
=
{
_TIMESTEP
:
15
,
_timer
:
null
,
_lastTime
:
null
,
_timerStep
:
10
,
_velocityVerlet
:
true
,
// run its built in timer / stepping
start
:
function
()
{
this
.
_lastTime
=
Date
.
now
();
this
.
_timer
=
setTimeout
(
this
.
step
,
this
.
_timerStep
,
this
);
this
.
_isRunning
=
true
;
},
stop
:
function
()
{
this
.
_isRunning
=
false
;
clearTimeout
(
this
.
_timer
);
},
isRunning
:
function
()
{
return
this
.
_isRunning
&
true
;
},
// Step gets called upon by the engine
// but attempts to call update() on a regular basics
// This method is also described in http://gameclosure.com/2011/04/11/deterministic-delta-tee-in-js-games/
step
:
function
(
emitter
)
{
var
time
=
Date
.
now
();
var
elapsed
=
time
-
emitter
.
_lastTime
;
if
(
!
this
.
_velocityVerlet
)
{
// if elapsed is way higher than time step, (usually after switching tabs, or excution cached in ff)
// we will drop cycles. perhaps set to a limit of 10 or something?
var
maxBlock
=
emitter
.
_TIMESTEP
*
20
;
if
(
elapsed
>=
maxBlock
)
{
//console.log('warning: sparks.js is fast fowarding engine, skipping steps', elapsed / emitter._TIMESTEP);
//emitter.update( (elapsed - maxBlock) / 1000);
elapsed
=
maxBlock
;
}
while
(
elapsed
>=
emitter
.
_TIMESTEP
)
{
emitter
.
update
(
emitter
.
_TIMESTEP
/
1000
);
elapsed
-=
emitter
.
_TIMESTEP
;
}
emitter
.
_lastTime
=
time
-
elapsed
;
}
else
{
emitter
.
update
(
elapsed
/
1000
);
emitter
.
_lastTime
=
time
;
}
if
(
emitter
.
_isRunning
)
setTimeout
(
emitter
.
step
,
emitter
.
_timerStep
,
emitter
);
},
// Update particle engine in seconds, not milliseconds
update
:
function
(
time
)
{
var
i
,
j
;
var
len
=
this
.
_counter
.
updateEmitter
(
this
,
time
);
// Create particles
for
(
i
=
0
;
i
<
len
;
i
++
)
{
this
.
createParticle
();
}
// Update activities
len
=
this
.
_activities
.
length
;
for
(
i
=
0
;
i
<
len
;
i
++
)
{
this
_
.
activities
[
i
].
update
(
this
,
time
);
this
.
_
activities
[
i
].
update
(
this
,
time
);
}
len
=
this
.
_actions
.
length
;
var
action
;
var
particle
;
var
action
;
var
len2
=
this
.
_particles
.
length
;
for
(
j
=
0
;
j
<
len
;
j
++
)
{
action
=
this
.
_actions
[
j
];
...
...
@@ -127,29 +130,29 @@ SPARKS.Emitter.prototype = {
action
.
update
(
this
,
particle
,
time
);
}
}
// remove dead particles
for
(
i
=
len2
;
i
--
;
)
{
particle
=
this
.
_particles
[
i
];
if
(
particle
.
isDead
)
{
//particle =
//particle =
this
.
_particles
.
splice
(
i
,
1
);
this
.
dispatchEvent
(
"
dead
"
,
particle
);
SPARKS
.
VectorPool
.
release
(
particle
.
position
);
//
SPARKS
.
VectorPool
.
release
(
particle
.
velocity
);
}
else
{
this
.
dispatchEvent
(
"
updated
"
,
particle
);
}
}
this
.
dispatchEvent
(
"
loopUpdated
"
);
},
createParticle
:
function
()
{
var
particle
=
new
SPARKS
.
Particle
();
// In future, use a Particle Factory
...
...
@@ -158,18 +161,18 @@ SPARKS.Emitter.prototype = {
for
(
i
=
0
;
i
<
len
;
i
++
)
{
this
.
_initializers
[
i
].
initialize
(
this
,
particle
);
}
this
.
_particles
.
push
(
particle
);
this
.
dispatchEvent
(
"
created
"
,
particle
);
// ParticleCreated
return
particle
;
},
addInitializer
:
function
(
initializer
)
{
this
.
_initializers
.
push
(
initializer
);
},
addAction
:
function
(
action
)
{
this
.
_actions
.
push
(
action
);
},
...
...
@@ -188,19 +191,19 @@ SPARKS.Emitter.prototype = {
}
//console.log('removeAction', index, this._actions);
},
addCallback
:
function
(
name
,
callback
)
{
this
.
callbacks
[
name
]
=
callback
;
},
dispatchEvent
:
function
(
name
,
args
)
{
var
callback
=
this
.
callbacks
[
name
];
if
(
callback
)
{
callback
(
args
);
}
}
};
...
...
@@ -208,7 +211,7 @@ SPARKS.Emitter.prototype = {
/*
* Constant Names for
* Events called by emitter.dispatchEvent()
*
*
*/
SPARKS
.
EVENT_PARTICLE_CREATED
=
"
created
"
SPARKS
.
EVENT_PARTICLE_UPDATED
=
"
updated
"
...
...
@@ -225,25 +228,25 @@ SPARKS.EVENT_LOOP_UPDATED = "loopUpdated";
// Number of particles per seconds
SPARKS
.
SteadyCounter
=
function
(
rate
)
{
this
.
rate
=
rate
;
// we use a shortfall counter to make up for slow emitters
// we use a shortfall counter to make up for slow emitters
this
.
leftover
=
0
;
};
SPARKS
.
SteadyCounter
.
prototype
.
updateEmitter
=
function
(
emitter
,
time
)
{
var
targetRelease
=
time
*
this
.
rate
+
this
.
leftover
;
var
actualRelease
=
Math
.
floor
(
targetRelease
);
this
.
leftover
=
targetRelease
-
actualRelease
;
return
actualRelease
;
};
/*
* Shot Counter produces specified particles
* Shot Counter produces specified particles
* on a single impluse or burst
*/
...
...
@@ -259,7 +262,7 @@ SPARKS.ShotCounter.prototype.updateEmitter = function(emitter, time) {
}
else
{
this
.
used
=
true
;
}
return
this
.
particles
;
};
...
...
@@ -275,35 +278,35 @@ SPARKS.Particle = function() {
* The lifetime of the particle, in seconds.
*/
this
.
lifetime
=
0
;
/**
* The age of the particle, in seconds.
*/
this
.
age
=
0
;
/**
* The energy of the particle.
*/
this
.
energy
=
1
;
/**
* Whether the particle is dead and should be removed from the stage.
*/
this
.
isDead
=
false
;
this
.
target
=
null
;
// tag
/**
* For 3D
*/
this
.
position
=
SPARKS
.
VectorPool
.
get
().
set
(
0
,
0
,
0
);
//new THREE.Vector3( 0, 0, 0 );
this
.
velocity
=
SPARKS
.
VectorPool
.
get
().
set
(
0
,
0
,
0
);
//new THREE.Vector3( 0, 0, 0 );
this
.
_oldvelocity
=
SPARKS
.
VectorPool
.
get
().
set
(
0
,
0
,
0
);
// rotation vec3
// angVelocity vec3
// faceAxis vec3
};
...
...
@@ -349,10 +352,10 @@ SPARKS.Death.prototype.update = function (emitter, particle, time) {
}
};
*/
SPARKS
.
Move
=
function
()
{
};
SPARKS
.
Move
.
prototype
.
update
=
function
(
emitter
,
particle
,
time
)
{
...
...
@@ -360,8 +363,8 @@ SPARKS.Move.prototype.update = function(emitter, particle, time) {
var
p
=
particle
.
position
;
var
v
=
particle
.
velocity
;
var
old
=
particle
.
_oldvelocity
;
if
(
this
.
_velocityVerlet
)
{
if
(
this
.
_velocityVerlet
)
{
p
.
x
+=
(
v
.
x
+
old
.
x
)
*
0.5
*
time
;
p
.
y
+=
(
v
.
y
+
old
.
y
)
*
0.5
*
time
;
p
.
z
+=
(
v
.
z
+
old
.
z
)
*
0.5
*
time
;
...
...
@@ -374,7 +377,7 @@ SPARKS.Move.prototype.update = function(emitter, particle, time) {
// OldVel = Vel;
// Vel = Vel + Accel * dt;
// Pos = Pos + (vel + Vel + Accel * dt) * 0.5 * dt;
};
...
...
@@ -385,7 +388,7 @@ SPARKS.DeathZone = function(zone) {
};
SPARKS
.
DeathZone
.
prototype
.
update
=
function
(
emitter
,
particle
,
time
)
{
if
(
this
.
zone
.
contains
(
particle
.
position
))
{
particle
.
isDead
=
true
;
}
...
...
@@ -409,29 +412,29 @@ SPARKS.ActionZone.prototype.update = function(emitter, particle, time) {
};
/*
* Accelerate action affects velocity in specified 3d direction
* Accelerate action affects velocity in specified 3d direction
*/
SPARKS
.
Accelerate
=
function
(
x
,
y
,
z
)
{
if
(
x
instanceof
THREE
.
Vector3
)
{
this
.
acceleration
=
x
;
return
;
}
this
.
acceleration
=
new
THREE
.
Vector3
(
x
,
y
,
z
);
};
SPARKS
.
Accelerate
.
prototype
.
update
=
function
(
emitter
,
particle
,
time
)
{
var
acc
=
this
.
acceleration
;
var
v
=
particle
.
velocity
;
particle
.
_oldvelocity
.
set
(
v
.
x
,
v
.
y
,
v
.
z
);
v
.
x
+=
acc
.
x
*
time
;
v
.
y
+=
acc
.
y
*
time
;
v
.
z
+=
acc
.
z
*
time
;
v
.
z
+=
acc
.
z
*
time
;
};
...
...
@@ -444,7 +447,7 @@ SPARKS.AccelerateFactor = function(factor) {
SPARKS
.
AccelerateFactor
.
prototype
.
update
=
function
(
emitter
,
particle
,
time
)
{
var
factor
=
this
.
factor
;
var
v
=
particle
.
velocity
;
var
len
=
v
.
length
();
var
adjFactor
;
...
...
@@ -452,11 +455,11 @@ SPARKS.AccelerateFactor.prototype.update = function(emitter, particle, time) {
adjFactor
=
factor
*
time
/
len
;
adjFactor
+=
1
;
v
.
multiplyScalar
(
adjFactor
);
// v.x *= adjFactor;
// v.y *= adjFactor;
// v.z *= adjFactor;
// v.z *= adjFactor;
}
};
...
...
@@ -497,9 +500,9 @@ SPARKS.RandomDrift = function(x,y,z) {
SPARKS
.
RandomDrift
.
prototype
.
update
=
function
(
emitter
,
particle
,
time
)
{
var
drift
=
this
.
drift
;
var
v
=
particle
.
velocity
;
v
.
x
+=
(
Math
.
random
()
-
0.5
)
*
drift
.
x
*
time
;
v
.
y
+=
(
Math
.
random
()
-
0.5
)
*
drift
.
y
*
time
;
v
.
z
+=
(
Math
.
random
()
-
0.5
)
*
drift
.
z
*
time
;
...
...
@@ -544,7 +547,7 @@ SPARKS.LineZone.prototype.getLocation = function() {
len
.
multiplyScalar
(
Math
.
random
()
);
return
len
.
addSelf
(
this
.
start
);
};
// Basically a RectangleZone
...
...
@@ -555,12 +558,12 @@ SPARKS.ParallelogramZone = function(corner, side1, side2) {
};
SPARKS
.
ParallelogramZone
.
prototype
.
getLocation
=
function
()
{
var
d1
=
this
.
side1
.
clone
().
multiplyScalar
(
Math
.
random
()
);
var
d2
=
this
.
side2
.
clone
().
multiplyScalar
(
Math
.
random
()
);
d1
.
addSelf
(
d2
);
return
d1
.
addSelf
(
this
.
corner
);
};
SPARKS
.
CubeZone
=
function
(
position
,
x
,
y
,
z
)
{
...
...
@@ -577,9 +580,9 @@ SPARKS.CubeZone.prototype.getLocation = function() {
location
.
x
+=
Math
.
random
()
*
this
.
x
;
location
.
y
+=
Math
.
random
()
*
this
.
y
;
location
.
z
+=
Math
.
random
()
*
this
.
z
;
return
location
;
};
...
...
@@ -591,46 +594,46 @@ SPARKS.CubeZone.prototype.contains = function(position) {
var
x
=
this
.
x
;
// width
var
y
=
this
.
y
;
// depth
var
z
=
this
.
z
;
// height
if
(
x
<
0
)
{
startX
+=
x
;
x
=
Math
.
abs
(
x
);
}
if
(
y
<
0
)
{
startY
+=
y
;
y
=
Math
.
abs
(
y
);
}
if
(
z
<
0
)
{
startZ
+=
z
;
z
=
Math
.
abs
(
z
);
}
var
diffX
=
position
.
x
-
startX
;
var
diffY
=
position
.
y
-
startY
;
var
diffZ
=
position
.
z
-
startZ
;
if
(
(
diffX
>
0
)
&&
(
diffX
<
x
)
&&
(
diffY
>
0
)
&&
(
diffY
<
y
)
&&
if
(
(
diffX
>
0
)
&&
(
diffX
<
x
)
&&
(
diffY
>
0
)
&&
(
diffY
<
y
)
&&
(
diffZ
>
0
)
&&
(
diffZ
<
z
)
)
{
return
true
;
}
return
false
;
};
/**
* The constructor creates a DiscZone 3D zone.
*
*
* @param centre The point at the center of the disc.
* @param normal A vector normal to the disc.
* @param outerRadius The outer radius of the disc.
* @param innerRadius The inner radius of the disc. This defines the hole
* in the center of the disc. If set to zero, there is no hole.
* @param innerRadius The inner radius of the disc. This defines the hole
* in the center of the disc. If set to zero, there is no hole.
*/
/*
...
...
@@ -640,7 +643,7 @@ SPARKS.DiscZone = function(center, radiusNormal, outerRadius, innerRadius) {
this.radiusNormal = radiusNormal;
this.outerRadius = (outerRadius==undefined) ? 0 : outerRadius;
this.innerRadius = (innerRadius==undefined) ? 0 : innerRadius;
};
SPARKS.DiscZone.prototype.getLocation = function() {
...
...
@@ -649,24 +652,24 @@ SPARKS.DiscZone.prototype.getLocation = function() {
var _outerRadius = this.outerRadius;
var center = this.center;
var _normal = this.radiusNormal;
_distToOrigin = _normal.dot( center );
var radius = _innerRadius + (1 - rand * rand ) * ( _outerRadius - _innerRadius );
var angle = Math.random() * SPARKS.Utils.TWOPI;
var _distToOrigin = _normal.dot( center );
var axes = SPARKS.Utils.getPerpendiculars( _normal.clone() );
var _planeAxis1 = axes[0];
var _planeAxis2 = axes[1];
var p = _planeAxis1.clone();
p.multiplyScalar( radius * Math.cos( angle ) );
var p2 = _planeAxis2.clone();
p2.multiplyScalar( radius * Math.sin( angle ) );
p.addSelf( p2 );
return _center.add( p );
};
*/
...
...
@@ -682,17 +685,17 @@ SPARKS.SphereCapZone = function(x, y, z, minr, maxr, angle) {
SPARKS
.
SphereCapZone
.
prototype
.
getLocation
=
function
()
{
var
theta
=
Math
.
PI
*
2
*
SPARKS
.
Utils
.
random
();
var
r
=
SPARKS
.
Utils
.
random
();
//new THREE.Vector3
var
v
=
SPARKS
.
VectorPool
.
get
().
set
(
r
*
Math
.
cos
(
theta
),
-
1
/
Math
.
tan
(
this
.
angle
*
SPARKS
.
Utils
.
DEGREE_TO_RADIAN
),
r
*
Math
.
sin
(
theta
));
//v.length = StardustMath.interpolate(0, _minRadius, 1, _maxRadius, Math.random());
var
i
=
this
.
minr
-
((
this
.
minr
-
this
.
maxr
)
*
Math
.
random
()
);
v
.
multiplyScalar
(
i
);
v
.
__markedForReleased
=
true
;
return
v
;
};
...
...
@@ -707,9 +710,9 @@ SPARKS.SphereCapZone.prototype.getLocation = function() {
// Specifies random life between max and min
SPARKS
.
Lifetime
=
function
(
min
,
max
)
{
this
.
_min
=
min
;
this
.
_max
=
max
?
max
:
min
;
};
SPARKS
.
Lifetime
.
prototype
.
initialize
=
function
(
emitter
/*Emitter*/
,
particle
/*Particle*/
)
{
...
...
@@ -756,7 +759,7 @@ SPARKS.Target.prototype.initialize = function( emitter, particle ) {
};
/********************************
* VectorPool
* VectorPool
*
* Reuse much of Vectors if possible
*********************************/
...
...
@@ -769,30 +772,30 @@ SPARKS.VectorPool = {
if
(
this
.
__pools
.
length
>
0
)
{
return
this
.
__pools
.
pop
();
}
return
this
.
_addToPool
();
},
// Release a vector back into the pool
release
:
function
(
v
)
{
this
.
__pools
.
push
(
v
);
},
// Create a bunch of vectors and add to the pool
_addToPool
:
function
()
{
//console.log("creating some pools");
for
(
var
i
=
0
,
size
=
100
;
i
<
size
;
i
++
)
{
this
.
__pools
.
push
(
new
THREE
.
Vector3
());
}
return
new
THREE
.
Vector3
();
}
};
...
...
@@ -815,7 +818,7 @@ SPARKS.Utils = {
p2
.
normalize
();
return
[
p1
,
p2
];
},
getPerpendicular
:
function
(
v
)
{
if
(
v
.
x
==
0
)
...
...
examples/js/loaders/ctm/CTMLoader.js
浏览文件 @
6660e155
...
...
@@ -592,19 +592,19 @@ THREE.CTMLoader.prototype.createModelClassic = function ( file, callback ) {
};
function
f3n
(
scope
,
normals
,
a
,
b
,
c
,
mi
,
na
,
nb
,
nc
)
{
function
f3n
(
scope
,
normals
,
a
,
b
,
c
,
mi
,
na
i
,
nbi
,
nci
)
{
var
nax
=
normals
[
na
*
3
],
nay
=
normals
[
na
*
3
+
1
],
naz
=
normals
[
na
*
3
+
2
],
var
nax
=
normals
[
na
i
*
3
],
nay
=
normals
[
na
i
*
3
+
1
],
naz
=
normals
[
na
i
*
3
+
2
],
nbx
=
normals
[
nb
*
3
],
nby
=
normals
[
nb
*
3
+
1
],
nbz
=
normals
[
nb
*
3
+
2
],
nbx
=
normals
[
nb
i
*
3
],
nby
=
normals
[
nb
i
*
3
+
1
],
nbz
=
normals
[
nb
i
*
3
+
2
],
ncx
=
normals
[
nc
*
3
],
ncy
=
normals
[
nc
*
3
+
1
],
ncz
=
normals
[
nc
*
3
+
2
];
ncx
=
normals
[
nc
i
*
3
],
ncy
=
normals
[
nc
i
*
3
+
1
],
ncz
=
normals
[
nc
i
*
3
+
2
];
var
na
=
new
THREE
.
Vector3
(
nax
,
nay
,
naz
),
nb
=
new
THREE
.
Vector3
(
nbx
,
nby
,
nbz
),
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录