Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Ablesons
three.js
提交
45c71d31
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,发现更多精彩内容 >>
提交
45c71d31
编写于
12月 04, 2019
作者:
D
Don McCurdy
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
MeshSurfaceSampler: Delete js/ version, keep jsm/.
上级
a5a4d7f5
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
0 addition
and
182 deletion
+0
-182
examples/js/math/MeshSurfaceSampler.js
examples/js/math/MeshSurfaceSampler.js
+0
-181
utils/modularize.js
utils/modularize.js
+0
-1
未找到文件。
examples/js/math/MeshSurfaceSampler.js
已删除
100644 → 0
浏览文件 @
a5a4d7f5
/**
* @author donmccurdy / https://www.donmccurdy.com/
*/
/**
* Utility class for sampling weighted random points on the surface of a mesh.
*
* Building the sampler is a one-time O(n) operation. Once built, any number of
* random samples may be selected in O(logn) time. Memory usage is O(n).
*
* References:
* - http://www.joesfer.com/?p=84
* - https://stackoverflow.com/a/4322940/1314762
*/
THREE
.
MeshSurfaceSampler
=
(
function
()
{
var
_face
=
new
THREE
.
Triangle
();
function
MeshSurfaceSampler
(
geometry
)
{
if
(
!
geometry
.
isBufferGeometry
||
geometry
.
attributes
.
position
.
itemSize
!==
3
)
{
throw
new
Error
(
'
THREE.MeshSurfaceSampler: Requires BufferGeometry triangle mesh.
'
);
}
if
(
geometry
.
index
)
{
console
.
warn
(
'
THREE.MeshSurfaceSampler: Converting geometry to non-indexed BufferGeometry.
'
);
geometry
=
geometry
.
toNonIndexed
();
}
this
.
geometry
=
geometry
;
this
.
positionAttribute
=
this
.
geometry
.
getAttribute
(
'
position
'
);
this
.
weightAttribute
=
null
;
this
.
distribution
=
null
;
};
MeshSurfaceSampler
.
prototype
=
{
constructor
:
MeshSurfaceSampler
,
setWeightAttribute
:
function
(
name
)
{
this
.
weightAttribute
=
name
?
this
.
geometry
.
getAttribute
(
name
)
:
null
;
return
this
;
},
build
:
function
()
{
var
positionAttribute
=
this
.
positionAttribute
;
var
weightAttribute
=
this
.
weightAttribute
;
var
faceWeights
=
new
Float32Array
(
positionAttribute
.
count
/
3
);
// Accumulate weights for each mesh face.
for
(
var
i
=
0
;
i
<
positionAttribute
.
count
;
i
+=
3
)
{
var
faceWeight
=
1
;
if
(
weightAttribute
)
{
faceWeight
=
weightAttribute
.
getX
(
i
)
+
weightAttribute
.
getX
(
i
+
1
)
+
weightAttribute
.
getX
(
i
+
2
);
}
_face
.
a
.
fromBufferAttribute
(
positionAttribute
,
i
);
_face
.
b
.
fromBufferAttribute
(
positionAttribute
,
i
+
1
);
_face
.
c
.
fromBufferAttribute
(
positionAttribute
,
i
+
2
);
faceWeight
*=
_face
.
getArea
();
faceWeights
[
i
/
3
]
=
faceWeight
;
}
// Store cumulative total face weights in an array, where weight index
// corresponds to face index.
this
.
distribution
=
new
Float32Array
(
positionAttribute
.
count
/
3
);
var
cumulativeTotal
=
0
;
for
(
var
i
=
0
;
i
<
faceWeights
.
length
;
i
++
)
{
cumulativeTotal
+=
faceWeights
[
i
];
this
.
distribution
[
i
]
=
cumulativeTotal
;
}
return
this
;
},
sample
:
function
(
targetPosition
,
targetNormal
)
{
var
cumulativeTotal
=
this
.
distribution
[
this
.
distribution
.
length
-
1
];
var
faceIndex
=
this
.
binarySearch
(
Math
.
random
()
*
cumulativeTotal
);
return
this
.
sampleFace
(
faceIndex
,
targetPosition
,
targetNormal
);
},
binarySearch
:
function
(
x
)
{
var
dist
=
this
.
distribution
;
var
start
=
0
;
var
end
=
dist
.
length
-
1
;
var
index
=
-
1
;
while
(
start
<=
end
)
{
var
mid
=
Math
.
floor
(
(
start
+
end
)
/
2
);
if
(
dist
[
mid
-
1
]
<=
x
&&
dist
[
mid
]
>
x
)
{
index
=
mid
;
break
;
}
else
if
(
x
<
dist
[
mid
]
)
{
end
=
mid
-
1
;
}
else
{
start
=
mid
+
1
;
}
}
return
index
;
},
sampleFace
:
function
(
faceIndex
,
targetPosition
,
targetNormal
)
{
var
u
=
Math
.
random
();
var
v
=
Math
.
random
();
if
(
u
+
v
>
1
)
{
u
=
1
-
u
;
v
=
1
-
v
;
}
_face
.
a
.
fromBufferAttribute
(
this
.
positionAttribute
,
faceIndex
*
3
);
_face
.
b
.
fromBufferAttribute
(
this
.
positionAttribute
,
faceIndex
*
3
+
1
);
_face
.
c
.
fromBufferAttribute
(
this
.
positionAttribute
,
faceIndex
*
3
+
2
);
targetPosition
.
set
(
0
,
0
,
0
)
.
addScaledVector
(
_face
.
a
,
u
)
.
addScaledVector
(
_face
.
b
,
v
)
.
addScaledVector
(
_face
.
c
,
1
-
(
u
+
v
)
);
_face
.
getNormal
(
targetNormal
);
return
this
;
}
};
return
MeshSurfaceSampler
;
}
)();
utils/modularize.js
浏览文件 @
45c71d31
...
...
@@ -111,7 +111,6 @@ var files = [
{
path
:
'
math/ConvexHull.js
'
,
dependencies
:
[],
ignoreList
:
[]
},
{
path
:
'
math/ImprovedNoise.js
'
,
dependencies
:
[],
ignoreList
:
[]
},
{
path
:
'
math/Lut.js
'
,
dependencies
:
[],
ignoreList
:
[]
},
{
path
:
'
math/MeshSurfaceSampler.js
'
,
dependencies
:
[],
ignoreList
:
[]
},
{
path
:
'
math/SimplexNoise.js
'
,
dependencies
:
[],
ignoreList
:
[]
},
{
path
:
'
misc/CarControls.js
'
,
dependencies
:
[],
ignoreList
:
[]
},
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录