Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Ablesons
three.js
提交
88b44758
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,体验更适合开发者的 AI 搜索 >>
提交
88b44758
编写于
1月 08, 2021
作者:
M
Mr.doob
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Moved THREE.Geometry out of core.
上级
6a43de47
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
408 addition
and
553 deletion
+408
-553
examples/jsm/deprecated/Geometry.d.ts
examples/jsm/deprecated/Geometry.d.ts
+0
-0
examples/jsm/deprecated/Geometry.js
examples/jsm/deprecated/Geometry.js
+408
-15
src/Three.Legacy.js
src/Three.Legacy.js
+0
-39
src/Three.js
src/Three.js
+0
-1
src/core/BufferGeometry.js
src/core/BufferGeometry.js
+0
-102
src/core/DirectGeometry.d.ts
src/core/DirectGeometry.d.ts
+0
-113
src/core/DirectGeometry.js
src/core/DirectGeometry.js
+0
-283
未找到文件。
src/core
/Geometry.d.ts
→
examples/jsm/deprecated
/Geometry.d.ts
浏览文件 @
88b44758
文件已移动
src/core
/Geometry.js
→
examples/jsm/deprecated
/Geometry.js
浏览文件 @
88b44758
import
{
EventDispatcher
}
from
'
./EventDispatcher.js
'
;
import
{
Face3
}
from
'
./Face3.js
'
;
import
{
Matrix3
}
from
'
../math/Matrix3.js
'
;
import
{
Sphere
}
from
'
../math/Sphere.js
'
;
import
{
Box3
}
from
'
../math/Box3.js
'
;
import
{
Vector3
}
from
'
../math/Vector3.js
'
;
import
{
Matrix4
}
from
'
../math/Matrix4.js
'
;
import
{
Vector2
}
from
'
../math/Vector2.js
'
;
import
{
Color
}
from
'
../math/Color.js
'
;
import
{
Object3D
}
from
'
./Object3D.js
'
;
import
{
MathUtils
}
from
'
../math/MathUtils.js
'
;
let
_geometryId
=
0
;
// Geometry uses even numbers as Id
import
{
Box3
,
BufferAttribute
,
Color
,
EventDispatcher
,
Face3
,
Float32BufferAttribute
,
Matrix3
,
Matrix4
,
MathUtils
,
Object3D
,
Sphere
,
Vector2
,
Vector3
}
from
'
../../../build/three.module.js
'
;
const
_m1
=
new
Matrix4
();
const
_obj
=
new
Object3D
();
const
_offset
=
new
Vector3
();
function
Geometry
()
{
Object
.
defineProperty
(
this
,
'
id
'
,
{
value
:
_geometryId
+=
2
}
);
this
.
uuid
=
MathUtils
.
generateUUID
();
this
.
name
=
''
;
...
...
@@ -1365,6 +1366,120 @@ Geometry.prototype = Object.assign( Object.create( EventDispatcher.prototype ),
},
toBufferGeometry
:
function
()
{
const
geometry
=
new
DirectGeometry
().
fromGeometry
(
this
);
const
positions
=
new
Float32Array
(
geometry
.
vertices
.
length
*
3
);
this
.
setAttribute
(
'
position
'
,
new
BufferAttribute
(
positions
,
3
).
copyVector3sArray
(
geometry
.
vertices
)
);
if
(
geometry
.
normals
.
length
>
0
)
{
const
normals
=
new
Float32Array
(
geometry
.
normals
.
length
*
3
);
this
.
setAttribute
(
'
normal
'
,
new
BufferAttribute
(
normals
,
3
).
copyVector3sArray
(
geometry
.
normals
)
);
}
if
(
geometry
.
colors
.
length
>
0
)
{
const
colors
=
new
Float32Array
(
geometry
.
colors
.
length
*
3
);
this
.
setAttribute
(
'
color
'
,
new
BufferAttribute
(
colors
,
3
).
copyColorsArray
(
geometry
.
colors
)
);
}
if
(
geometry
.
uvs
.
length
>
0
)
{
const
uvs
=
new
Float32Array
(
geometry
.
uvs
.
length
*
2
);
this
.
setAttribute
(
'
uv
'
,
new
BufferAttribute
(
uvs
,
2
).
copyVector2sArray
(
geometry
.
uvs
)
);
}
if
(
geometry
.
uvs2
.
length
>
0
)
{
const
uvs2
=
new
Float32Array
(
geometry
.
uvs2
.
length
*
2
);
this
.
setAttribute
(
'
uv2
'
,
new
BufferAttribute
(
uvs2
,
2
).
copyVector2sArray
(
geometry
.
uvs2
)
);
}
// groups
this
.
groups
=
geometry
.
groups
;
// morphs
for
(
const
name
in
geometry
.
morphTargets
)
{
const
array
=
[];
const
morphTargets
=
geometry
.
morphTargets
[
name
];
for
(
let
i
=
0
,
l
=
morphTargets
.
length
;
i
<
l
;
i
++
)
{
const
morphTarget
=
morphTargets
[
i
];
const
attribute
=
new
Float32BufferAttribute
(
morphTarget
.
data
.
length
*
3
,
3
);
attribute
.
name
=
morphTarget
.
name
;
array
.
push
(
attribute
.
copyVector3sArray
(
morphTarget
.
data
)
);
}
this
.
morphAttributes
[
name
]
=
array
;
}
// skinning
if
(
geometry
.
skinIndices
.
length
>
0
)
{
const
skinIndices
=
new
Float32BufferAttribute
(
geometry
.
skinIndices
.
length
*
4
,
4
);
this
.
setAttribute
(
'
skinIndex
'
,
skinIndices
.
copyVector4sArray
(
geometry
.
skinIndices
)
);
}
if
(
geometry
.
skinWeights
.
length
>
0
)
{
const
skinWeights
=
new
Float32BufferAttribute
(
geometry
.
skinWeights
.
length
*
4
,
4
);
this
.
setAttribute
(
'
skinWeight
'
,
skinWeights
.
copyVector4sArray
(
geometry
.
skinWeights
)
);
}
//
if
(
geometry
.
boundingSphere
!==
null
)
{
this
.
boundingSphere
=
geometry
.
boundingSphere
.
clone
();
}
if
(
geometry
.
boundingBox
!==
null
)
{
this
.
boundingBox
=
geometry
.
boundingBox
.
clone
();
}
return
this
;
},
computeTangents
:
function
()
{
console
.
error
(
'
THREE.Geometry: .computeTangents() has been removed.
'
);
},
computeLineDistances
:
function
()
{
console
.
error
(
'
THREE.Geometry: .computeLineDistances() has been removed. Use THREE.Line.computeLineDistances() instead.
'
);
},
applyMatrix
:
function
(
matrix
)
{
console
.
warn
(
'
THREE.Geometry: .applyMatrix() has been renamed to .applyMatrix4().
'
);
return
this
.
applyMatrix4
(
matrix
);
},
dispose
:
function
()
{
this
.
dispatchEvent
(
{
type
:
'
dispose
'
}
);
...
...
@@ -1373,5 +1488,283 @@ Geometry.prototype = Object.assign( Object.create( EventDispatcher.prototype ),
}
);
class
DirectGeometry
{
constructor
()
{
this
.
vertices
=
[];
this
.
normals
=
[];
this
.
colors
=
[];
this
.
uvs
=
[];
this
.
uvs2
=
[];
this
.
groups
=
[];
this
.
morphTargets
=
{};
this
.
skinWeights
=
[];
this
.
skinIndices
=
[];
// this.lineDistances = [];
this
.
boundingBox
=
null
;
this
.
boundingSphere
=
null
;
// update flags
this
.
verticesNeedUpdate
=
false
;
this
.
normalsNeedUpdate
=
false
;
this
.
colorsNeedUpdate
=
false
;
this
.
uvsNeedUpdate
=
false
;
this
.
groupsNeedUpdate
=
false
;
}
computeGroups
(
geometry
)
{
const
groups
=
[];
let
group
,
i
;
let
materialIndex
=
undefined
;
const
faces
=
geometry
.
faces
;
for
(
i
=
0
;
i
<
faces
.
length
;
i
++
)
{
const
face
=
faces
[
i
];
// materials
if
(
face
.
materialIndex
!==
materialIndex
)
{
materialIndex
=
face
.
materialIndex
;
if
(
group
!==
undefined
)
{
group
.
count
=
(
i
*
3
)
-
group
.
start
;
groups
.
push
(
group
);
}
group
=
{
start
:
i
*
3
,
materialIndex
:
materialIndex
};
}
}
if
(
group
!==
undefined
)
{
group
.
count
=
(
i
*
3
)
-
group
.
start
;
groups
.
push
(
group
);
}
this
.
groups
=
groups
;
}
fromGeometry
(
geometry
)
{
const
faces
=
geometry
.
faces
;
const
vertices
=
geometry
.
vertices
;
const
faceVertexUvs
=
geometry
.
faceVertexUvs
;
const
hasFaceVertexUv
=
faceVertexUvs
[
0
]
&&
faceVertexUvs
[
0
].
length
>
0
;
const
hasFaceVertexUv2
=
faceVertexUvs
[
1
]
&&
faceVertexUvs
[
1
].
length
>
0
;
// morphs
const
morphTargets
=
geometry
.
morphTargets
;
const
morphTargetsLength
=
morphTargets
.
length
;
let
morphTargetsPosition
;
if
(
morphTargetsLength
>
0
)
{
morphTargetsPosition
=
[];
for
(
let
i
=
0
;
i
<
morphTargetsLength
;
i
++
)
{
morphTargetsPosition
[
i
]
=
{
name
:
morphTargets
[
i
].
name
,
data
:
[]
};
}
this
.
morphTargets
.
position
=
morphTargetsPosition
;
}
const
morphNormals
=
geometry
.
morphNormals
;
const
morphNormalsLength
=
morphNormals
.
length
;
let
morphTargetsNormal
;
if
(
morphNormalsLength
>
0
)
{
morphTargetsNormal
=
[];
for
(
let
i
=
0
;
i
<
morphNormalsLength
;
i
++
)
{
morphTargetsNormal
[
i
]
=
{
name
:
morphNormals
[
i
].
name
,
data
:
[]
};
}
this
.
morphTargets
.
normal
=
morphTargetsNormal
;
}
// skins
const
skinIndices
=
geometry
.
skinIndices
;
const
skinWeights
=
geometry
.
skinWeights
;
const
hasSkinIndices
=
skinIndices
.
length
===
vertices
.
length
;
const
hasSkinWeights
=
skinWeights
.
length
===
vertices
.
length
;
//
if
(
vertices
.
length
>
0
&&
faces
.
length
===
0
)
{
console
.
error
(
'
THREE.DirectGeometry: Faceless geometries are not supported.
'
);
}
for
(
let
i
=
0
;
i
<
faces
.
length
;
i
++
)
{
const
face
=
faces
[
i
];
this
.
vertices
.
push
(
vertices
[
face
.
a
],
vertices
[
face
.
b
],
vertices
[
face
.
c
]
);
const
vertexNormals
=
face
.
vertexNormals
;
if
(
vertexNormals
.
length
===
3
)
{
this
.
normals
.
push
(
vertexNormals
[
0
],
vertexNormals
[
1
],
vertexNormals
[
2
]
);
}
else
{
const
normal
=
face
.
normal
;
this
.
normals
.
push
(
normal
,
normal
,
normal
);
}
const
vertexColors
=
face
.
vertexColors
;
if
(
vertexColors
.
length
===
3
)
{
this
.
colors
.
push
(
vertexColors
[
0
],
vertexColors
[
1
],
vertexColors
[
2
]
);
}
else
{
const
color
=
face
.
color
;
this
.
colors
.
push
(
color
,
color
,
color
);
}
if
(
hasFaceVertexUv
===
true
)
{
const
vertexUvs
=
faceVertexUvs
[
0
][
i
];
if
(
vertexUvs
!==
undefined
)
{
this
.
uvs
.
push
(
vertexUvs
[
0
],
vertexUvs
[
1
],
vertexUvs
[
2
]
);
}
else
{
console
.
warn
(
'
THREE.DirectGeometry.fromGeometry(): Undefined vertexUv
'
,
i
);
this
.
uvs
.
push
(
new
Vector2
(),
new
Vector2
(),
new
Vector2
()
);
}
}
if
(
hasFaceVertexUv2
===
true
)
{
const
vertexUvs
=
faceVertexUvs
[
1
][
i
];
if
(
vertexUvs
!==
undefined
)
{
this
.
uvs2
.
push
(
vertexUvs
[
0
],
vertexUvs
[
1
],
vertexUvs
[
2
]
);
}
else
{
console
.
warn
(
'
THREE.DirectGeometry.fromGeometry(): Undefined vertexUv2
'
,
i
);
this
.
uvs2
.
push
(
new
Vector2
(),
new
Vector2
(),
new
Vector2
()
);
}
}
// morphs
for
(
let
j
=
0
;
j
<
morphTargetsLength
;
j
++
)
{
const
morphTarget
=
morphTargets
[
j
].
vertices
;
morphTargetsPosition
[
j
].
data
.
push
(
morphTarget
[
face
.
a
],
morphTarget
[
face
.
b
],
morphTarget
[
face
.
c
]
);
}
for
(
let
j
=
0
;
j
<
morphNormalsLength
;
j
++
)
{
const
morphNormal
=
morphNormals
[
j
].
vertexNormals
[
i
];
morphTargetsNormal
[
j
].
data
.
push
(
morphNormal
.
a
,
morphNormal
.
b
,
morphNormal
.
c
);
}
// skins
if
(
hasSkinIndices
)
{
this
.
skinIndices
.
push
(
skinIndices
[
face
.
a
],
skinIndices
[
face
.
b
],
skinIndices
[
face
.
c
]
);
}
if
(
hasSkinWeights
)
{
this
.
skinWeights
.
push
(
skinWeights
[
face
.
a
],
skinWeights
[
face
.
b
],
skinWeights
[
face
.
c
]
);
}
}
this
.
computeGroups
(
geometry
);
this
.
verticesNeedUpdate
=
geometry
.
verticesNeedUpdate
;
this
.
normalsNeedUpdate
=
geometry
.
normalsNeedUpdate
;
this
.
colorsNeedUpdate
=
geometry
.
colorsNeedUpdate
;
this
.
uvsNeedUpdate
=
geometry
.
uvsNeedUpdate
;
this
.
groupsNeedUpdate
=
geometry
.
groupsNeedUpdate
;
if
(
geometry
.
boundingSphere
!==
null
)
{
this
.
boundingSphere
=
geometry
.
boundingSphere
.
clone
();
}
if
(
geometry
.
boundingBox
!==
null
)
{
this
.
boundingBox
=
geometry
.
boundingBox
.
clone
();
}
return
this
;
}
}
export
{
Geometry
};
src/Three.Legacy.js
浏览文件 @
88b44758
...
...
@@ -25,7 +25,6 @@ import { BufferGeometry } from './core/BufferGeometry.js';
import
{
InstancedBufferGeometry
}
from
'
./core/InstancedBufferGeometry.js
'
;
import
{
InterleavedBuffer
}
from
'
./core/InterleavedBuffer.js
'
;
import
{
Face3
}
from
'
./core/Face3.js
'
;
import
{
Geometry
}
from
'
./core/Geometry.js
'
;
import
{
Object3D
}
from
'
./core/Object3D.js
'
;
import
{
Uniform
}
from
'
./core/Uniform.js
'
;
import
{
Raycaster
}
from
'
./core/Raycaster.js
'
;
...
...
@@ -301,23 +300,6 @@ Object.assign( CurvePath.prototype, {
const
pts
=
this
.
getSpacedPoints
(
divisions
);
return
this
.
createGeometry
(
pts
);
},
createGeometry
:
function
(
points
)
{
console
.
warn
(
'
THREE.CurvePath: .createGeometry() has been removed. Use new THREE.Geometry().setFromPoints( points ) instead.
'
);
const
geometry
=
new
Geometry
();
for
(
let
i
=
0
,
l
=
points
.
length
;
i
<
l
;
i
++
)
{
const
point
=
points
[
i
];
geometry
.
vertices
.
push
(
new
Vector3
(
point
.
x
,
point
.
y
,
point
.
z
||
0
)
);
}
return
geometry
;
}
}
);
...
...
@@ -965,27 +947,6 @@ Object.assign( Vector4.prototype, {
//
Object
.
assign
(
Geometry
.
prototype
,
{
computeTangents
:
function
()
{
console
.
error
(
'
THREE.Geometry: .computeTangents() has been removed.
'
);
},
computeLineDistances
:
function
()
{
console
.
error
(
'
THREE.Geometry: .computeLineDistances() has been removed. Use THREE.Line.computeLineDistances() instead.
'
);
},
applyMatrix
:
function
(
matrix
)
{
console
.
warn
(
'
THREE.Geometry: .applyMatrix() has been renamed to .applyMatrix4().
'
);
return
this
.
applyMatrix4
(
matrix
);
}
}
);
export
function
BoxGeometry
(
width
,
height
,
depth
,
widthSegments
,
heightSegments
,
depthSegments
)
{
console
.
warn
(
'
THREE.BoxGeometry has been removed. Use THREE.BoxBufferGeometry instead.
'
);
...
...
src/Three.js
浏览文件 @
88b44758
...
...
@@ -89,7 +89,6 @@ export { AnimationClip } from './animation/AnimationClip.js';
export
{
Uniform
}
from
'
./core/Uniform.js
'
;
export
{
InstancedBufferGeometry
}
from
'
./core/InstancedBufferGeometry.js
'
;
export
{
BufferGeometry
}
from
'
./core/BufferGeometry.js
'
;
export
{
Geometry
}
from
'
./core/Geometry.js
'
;
export
{
InterleavedBufferAttribute
}
from
'
./core/InterleavedBufferAttribute.js
'
;
export
{
InstancedInterleavedBuffer
}
from
'
./core/InstancedInterleavedBuffer.js
'
;
export
{
InterleavedBuffer
}
from
'
./core/InterleavedBuffer.js
'
;
...
...
src/core/BufferGeometry.js
浏览文件 @
88b44758
...
...
@@ -3,7 +3,6 @@ import { Box3 } from '../math/Box3.js';
import
{
EventDispatcher
}
from
'
./EventDispatcher.js
'
;
import
{
BufferAttribute
,
Float32BufferAttribute
,
Uint16BufferAttribute
,
Uint32BufferAttribute
}
from
'
./BufferAttribute.js
'
;
import
{
Sphere
}
from
'
../math/Sphere.js
'
;
import
{
DirectGeometry
}
from
'
./DirectGeometry.js
'
;
import
{
Object3D
}
from
'
./Object3D.js
'
;
import
{
Matrix4
}
from
'
../math/Matrix4.js
'
;
import
{
Matrix3
}
from
'
../math/Matrix3.js
'
;
...
...
@@ -450,107 +449,6 @@ BufferGeometry.prototype = Object.assign( Object.create( EventDispatcher.prototy
},
fromGeometry
:
function
(
geometry
)
{
geometry
.
__directGeometry
=
new
DirectGeometry
().
fromGeometry
(
geometry
);
return
this
.
fromDirectGeometry
(
geometry
.
__directGeometry
);
},
fromDirectGeometry
:
function
(
geometry
)
{
const
positions
=
new
Float32Array
(
geometry
.
vertices
.
length
*
3
);
this
.
setAttribute
(
'
position
'
,
new
BufferAttribute
(
positions
,
3
).
copyVector3sArray
(
geometry
.
vertices
)
);
if
(
geometry
.
normals
.
length
>
0
)
{
const
normals
=
new
Float32Array
(
geometry
.
normals
.
length
*
3
);
this
.
setAttribute
(
'
normal
'
,
new
BufferAttribute
(
normals
,
3
).
copyVector3sArray
(
geometry
.
normals
)
);
}
if
(
geometry
.
colors
.
length
>
0
)
{
const
colors
=
new
Float32Array
(
geometry
.
colors
.
length
*
3
);
this
.
setAttribute
(
'
color
'
,
new
BufferAttribute
(
colors
,
3
).
copyColorsArray
(
geometry
.
colors
)
);
}
if
(
geometry
.
uvs
.
length
>
0
)
{
const
uvs
=
new
Float32Array
(
geometry
.
uvs
.
length
*
2
);
this
.
setAttribute
(
'
uv
'
,
new
BufferAttribute
(
uvs
,
2
).
copyVector2sArray
(
geometry
.
uvs
)
);
}
if
(
geometry
.
uvs2
.
length
>
0
)
{
const
uvs2
=
new
Float32Array
(
geometry
.
uvs2
.
length
*
2
);
this
.
setAttribute
(
'
uv2
'
,
new
BufferAttribute
(
uvs2
,
2
).
copyVector2sArray
(
geometry
.
uvs2
)
);
}
// groups
this
.
groups
=
geometry
.
groups
;
// morphs
for
(
const
name
in
geometry
.
morphTargets
)
{
const
array
=
[];
const
morphTargets
=
geometry
.
morphTargets
[
name
];
for
(
let
i
=
0
,
l
=
morphTargets
.
length
;
i
<
l
;
i
++
)
{
const
morphTarget
=
morphTargets
[
i
];
const
attribute
=
new
Float32BufferAttribute
(
morphTarget
.
data
.
length
*
3
,
3
);
attribute
.
name
=
morphTarget
.
name
;
array
.
push
(
attribute
.
copyVector3sArray
(
morphTarget
.
data
)
);
}
this
.
morphAttributes
[
name
]
=
array
;
}
// skinning
if
(
geometry
.
skinIndices
.
length
>
0
)
{
const
skinIndices
=
new
Float32BufferAttribute
(
geometry
.
skinIndices
.
length
*
4
,
4
);
this
.
setAttribute
(
'
skinIndex
'
,
skinIndices
.
copyVector4sArray
(
geometry
.
skinIndices
)
);
}
if
(
geometry
.
skinWeights
.
length
>
0
)
{
const
skinWeights
=
new
Float32BufferAttribute
(
geometry
.
skinWeights
.
length
*
4
,
4
);
this
.
setAttribute
(
'
skinWeight
'
,
skinWeights
.
copyVector4sArray
(
geometry
.
skinWeights
)
);
}
//
if
(
geometry
.
boundingSphere
!==
null
)
{
this
.
boundingSphere
=
geometry
.
boundingSphere
.
clone
();
}
if
(
geometry
.
boundingBox
!==
null
)
{
this
.
boundingBox
=
geometry
.
boundingBox
.
clone
();
}
return
this
;
},
computeBoundingBox
:
function
()
{
if
(
this
.
boundingBox
===
null
)
{
...
...
src/core/DirectGeometry.d.ts
已删除
100644 → 0
浏览文件 @
6a43de47
import
{
Vector3
}
from
'
./../math/Vector3
'
;
import
{
Color
}
from
'
./../math/Color
'
;
import
{
Vector2
}
from
'
./../math/Vector2
'
;
import
{
Vector4
}
from
'
./../math/Vector4
'
;
import
{
Box3
}
from
'
./../math/Box3
'
;
import
{
Sphere
}
from
'
./../math/Sphere
'
;
import
{
Geometry
}
from
'
./Geometry
'
;
import
{
MorphTarget
}
from
'
./Geometry
'
;
/**
* @see {@link https://github.com/mrdoob/three.js/blob/master/src/core/DirectGeometry.js|src/core/DirectGeometry.js}
*/
export
class
DirectGeometry
{
constructor
();
id
:
number
;
uuid
:
string
;
name
:
string
;
type
:
string
;
/**
* @default []
*/
indices
:
number
[];
/**
* @default []
*/
vertices
:
Vector3
[];
/**
* @default []
*/
normals
:
Vector3
[];
/**
* @default []
*/
colors
:
Color
[];
/**
* @default []
*/
uvs
:
Vector2
[];
/**
* @default []
*/
uvs2
:
Vector2
[];
/**
* @default []
*/
groups
:
{
start
:
number
;
materialIndex
:
number
}[];
/**
* @default {}
*/
morphTargets
:
MorphTarget
[];
/**
* @default []
*/
skinWeights
:
Vector4
[];
/**
* @default []
*/
skinIndices
:
Vector4
[];
/**
* @default null
*/
boundingBox
:
Box3
|
null
;
/**
* @default null
*/
boundingSphere
:
Sphere
|
null
;
/**
* @default false
*/
verticesNeedUpdate
:
boolean
;
/**
* @default false
*/
normalsNeedUpdate
:
boolean
;
/**
* @default false
*/
colorsNeedUpdate
:
boolean
;
/**
* @default false
*/
uvsNeedUpdate
:
boolean
;
/**
* @default false
*/
groupsNeedUpdate
:
boolean
;
computeBoundingBox
():
void
;
computeBoundingSphere
():
void
;
computeGroups
(
geometry
:
Geometry
):
void
;
fromGeometry
(
geometry
:
Geometry
):
DirectGeometry
;
dispose
():
void
;
}
src/core/DirectGeometry.js
已删除
100644 → 0
浏览文件 @
6a43de47
import
{
Vector2
}
from
'
../math/Vector2.js
'
;
class
DirectGeometry
{
constructor
()
{
this
.
vertices
=
[];
this
.
normals
=
[];
this
.
colors
=
[];
this
.
uvs
=
[];
this
.
uvs2
=
[];
this
.
groups
=
[];
this
.
morphTargets
=
{};
this
.
skinWeights
=
[];
this
.
skinIndices
=
[];
// this.lineDistances = [];
this
.
boundingBox
=
null
;
this
.
boundingSphere
=
null
;
// update flags
this
.
verticesNeedUpdate
=
false
;
this
.
normalsNeedUpdate
=
false
;
this
.
colorsNeedUpdate
=
false
;
this
.
uvsNeedUpdate
=
false
;
this
.
groupsNeedUpdate
=
false
;
}
computeGroups
(
geometry
)
{
const
groups
=
[];
let
group
,
i
;
let
materialIndex
=
undefined
;
const
faces
=
geometry
.
faces
;
for
(
i
=
0
;
i
<
faces
.
length
;
i
++
)
{
const
face
=
faces
[
i
];
// materials
if
(
face
.
materialIndex
!==
materialIndex
)
{
materialIndex
=
face
.
materialIndex
;
if
(
group
!==
undefined
)
{
group
.
count
=
(
i
*
3
)
-
group
.
start
;
groups
.
push
(
group
);
}
group
=
{
start
:
i
*
3
,
materialIndex
:
materialIndex
};
}
}
if
(
group
!==
undefined
)
{
group
.
count
=
(
i
*
3
)
-
group
.
start
;
groups
.
push
(
group
);
}
this
.
groups
=
groups
;
}
fromGeometry
(
geometry
)
{
const
faces
=
geometry
.
faces
;
const
vertices
=
geometry
.
vertices
;
const
faceVertexUvs
=
geometry
.
faceVertexUvs
;
const
hasFaceVertexUv
=
faceVertexUvs
[
0
]
&&
faceVertexUvs
[
0
].
length
>
0
;
const
hasFaceVertexUv2
=
faceVertexUvs
[
1
]
&&
faceVertexUvs
[
1
].
length
>
0
;
// morphs
const
morphTargets
=
geometry
.
morphTargets
;
const
morphTargetsLength
=
morphTargets
.
length
;
let
morphTargetsPosition
;
if
(
morphTargetsLength
>
0
)
{
morphTargetsPosition
=
[];
for
(
let
i
=
0
;
i
<
morphTargetsLength
;
i
++
)
{
morphTargetsPosition
[
i
]
=
{
name
:
morphTargets
[
i
].
name
,
data
:
[]
};
}
this
.
morphTargets
.
position
=
morphTargetsPosition
;
}
const
morphNormals
=
geometry
.
morphNormals
;
const
morphNormalsLength
=
morphNormals
.
length
;
let
morphTargetsNormal
;
if
(
morphNormalsLength
>
0
)
{
morphTargetsNormal
=
[];
for
(
let
i
=
0
;
i
<
morphNormalsLength
;
i
++
)
{
morphTargetsNormal
[
i
]
=
{
name
:
morphNormals
[
i
].
name
,
data
:
[]
};
}
this
.
morphTargets
.
normal
=
morphTargetsNormal
;
}
// skins
const
skinIndices
=
geometry
.
skinIndices
;
const
skinWeights
=
geometry
.
skinWeights
;
const
hasSkinIndices
=
skinIndices
.
length
===
vertices
.
length
;
const
hasSkinWeights
=
skinWeights
.
length
===
vertices
.
length
;
//
if
(
vertices
.
length
>
0
&&
faces
.
length
===
0
)
{
console
.
error
(
'
THREE.DirectGeometry: Faceless geometries are not supported.
'
);
}
for
(
let
i
=
0
;
i
<
faces
.
length
;
i
++
)
{
const
face
=
faces
[
i
];
this
.
vertices
.
push
(
vertices
[
face
.
a
],
vertices
[
face
.
b
],
vertices
[
face
.
c
]
);
const
vertexNormals
=
face
.
vertexNormals
;
if
(
vertexNormals
.
length
===
3
)
{
this
.
normals
.
push
(
vertexNormals
[
0
],
vertexNormals
[
1
],
vertexNormals
[
2
]
);
}
else
{
const
normal
=
face
.
normal
;
this
.
normals
.
push
(
normal
,
normal
,
normal
);
}
const
vertexColors
=
face
.
vertexColors
;
if
(
vertexColors
.
length
===
3
)
{
this
.
colors
.
push
(
vertexColors
[
0
],
vertexColors
[
1
],
vertexColors
[
2
]
);
}
else
{
const
color
=
face
.
color
;
this
.
colors
.
push
(
color
,
color
,
color
);
}
if
(
hasFaceVertexUv
===
true
)
{
const
vertexUvs
=
faceVertexUvs
[
0
][
i
];
if
(
vertexUvs
!==
undefined
)
{
this
.
uvs
.
push
(
vertexUvs
[
0
],
vertexUvs
[
1
],
vertexUvs
[
2
]
);
}
else
{
console
.
warn
(
'
THREE.DirectGeometry.fromGeometry(): Undefined vertexUv
'
,
i
);
this
.
uvs
.
push
(
new
Vector2
(),
new
Vector2
(),
new
Vector2
()
);
}
}
if
(
hasFaceVertexUv2
===
true
)
{
const
vertexUvs
=
faceVertexUvs
[
1
][
i
];
if
(
vertexUvs
!==
undefined
)
{
this
.
uvs2
.
push
(
vertexUvs
[
0
],
vertexUvs
[
1
],
vertexUvs
[
2
]
);
}
else
{
console
.
warn
(
'
THREE.DirectGeometry.fromGeometry(): Undefined vertexUv2
'
,
i
);
this
.
uvs2
.
push
(
new
Vector2
(),
new
Vector2
(),
new
Vector2
()
);
}
}
// morphs
for
(
let
j
=
0
;
j
<
morphTargetsLength
;
j
++
)
{
const
morphTarget
=
morphTargets
[
j
].
vertices
;
morphTargetsPosition
[
j
].
data
.
push
(
morphTarget
[
face
.
a
],
morphTarget
[
face
.
b
],
morphTarget
[
face
.
c
]
);
}
for
(
let
j
=
0
;
j
<
morphNormalsLength
;
j
++
)
{
const
morphNormal
=
morphNormals
[
j
].
vertexNormals
[
i
];
morphTargetsNormal
[
j
].
data
.
push
(
morphNormal
.
a
,
morphNormal
.
b
,
morphNormal
.
c
);
}
// skins
if
(
hasSkinIndices
)
{
this
.
skinIndices
.
push
(
skinIndices
[
face
.
a
],
skinIndices
[
face
.
b
],
skinIndices
[
face
.
c
]
);
}
if
(
hasSkinWeights
)
{
this
.
skinWeights
.
push
(
skinWeights
[
face
.
a
],
skinWeights
[
face
.
b
],
skinWeights
[
face
.
c
]
);
}
}
this
.
computeGroups
(
geometry
);
this
.
verticesNeedUpdate
=
geometry
.
verticesNeedUpdate
;
this
.
normalsNeedUpdate
=
geometry
.
normalsNeedUpdate
;
this
.
colorsNeedUpdate
=
geometry
.
colorsNeedUpdate
;
this
.
uvsNeedUpdate
=
geometry
.
uvsNeedUpdate
;
this
.
groupsNeedUpdate
=
geometry
.
groupsNeedUpdate
;
if
(
geometry
.
boundingSphere
!==
null
)
{
this
.
boundingSphere
=
geometry
.
boundingSphere
.
clone
();
}
if
(
geometry
.
boundingBox
!==
null
)
{
this
.
boundingBox
=
geometry
.
boundingBox
.
clone
();
}
return
this
;
}
}
export
{
DirectGeometry
};
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录