3D 元素表示您项目中的三维对象,包括导入的 3D 模型、基本几何原始体、从 2D 形状挤出的形状、3D 文本和布尔运算结果。
3D 元素共享 基本元素 和 视图元素 的公共字段,同时还引入了额外的 3D 特定属性。
| 属性 | 类型 | 必需 | 示例 | 值范围 | 描述 |
|---|---|---|---|---|---|
| type | string | true | - | 3D | 元素的类型。对于 3D 元素,这始终是 "3D"。 |
| sourceId | string | false | - | - | 3D 模型或几何资源的内部标识符。 |
| ext | string | false | - | glb | gltf | fbx | obj | geometry | primitive | text3d | parametric | curve | 3D 元素的文件扩展名或节点类型。 |
| externalUrl | string | false | - | - | 加载外部 glTF/glb 模型的可选 URL。引擎将获取并缓存模型。 |
| nodeType | string | false | - | primitive | geometry | text3d | import | model | parametric | curve | 3D 节点的类型。决定附加属性的结构。 |
| category | string | false | - | For primitive/geometry: basic | polyhedron. For parametric: extrusion | lathe | sweep. For curve: helix | torusKnot | custom | 3D 节点的子类别。可用值取决于 nodeType。 |
| geometryType | string | false | - | - | 基本几何的类型。请参见下面的 "几何类型" 部分。 |
| originalWidth | number | false | - | - | 3D 模型在世界单位中的原始宽度。 |
| originalHeight | number | false | - | - | 3D 模型在世界单位中的原始高度。 |
| originalDepth | number | false | - | - | 3D 模型在世界单位中的原始深度。 |
| animation | object | false | - | - | 带动画的 glTF 模型的动画设置。包含 currentIndex、speed 和 loop 属性。 |
除了标准的 2D 变换属性(x、y、旋转、scaleX、scaleY)外,3D 元素还支持用于三维定位和旋转的额外变换属性:
| 属性 | 类型 | 必需 | 示例 | 值范围 | 描述 |
|---|---|---|---|---|---|
| z | number | false | - | - | 元素在 3D 空间中的深度位置。单位与像素对齐,其中 z=0 对应于画布平面。 |
| rotationX | number | false | - | - | 围绕 X 轴的旋转,单位为度。 |
| rotationY | number | false | - | - | 围绕 Y 轴的旋转,单位为度。 |
| scaleZ | number | false | - | > 0 | 沿 Z 轴的缩放因子。值大于 1 放大,值在 0 和 1 之间缩小。 |
geometryType 字段指定基本 3D 几何的类型。可用类型按类别组织(在 nodeType 为 "geometry" 或 "primitive" 时通过 category 字段指定):
注意:
nodeType: "primitive"是"geometry"的别名。两者都被支持并表现相同。
基本形状 (category: "basic"):
cube - 六面体sphere - 球形几何cylinder - 圆柱形几何cone - 圆锥形几何torus - 圆环形几何capsule - 胶囊形几何disc - 平面圆盘多面体 (category: "polyhedron"):
pyramid - 四面体octahedron - 八面体icosahedron - 二十面体dodecahedron - 十二面体hexPrism - 六面棱柱triangle - 三角棱柱参数化节点 (nodeType: "parametric") 以过程方式生成几何:
挤出 (category: "extrusion"):
车床 (category: "lathe"):
扫掠 (category: "sweep"):
曲线节点 (nodeType: "curve") 创建 3D 曲线和路径:
螺旋 (category: "helix"):
圆环结 (category: "torusKnot"):
自定义 (category: "custom"):
拓扑操作(布尔、数组、镜像、复合)在编辑器内执行,并生成标准几何输出。这些操作在编辑时应用,无需在渲染 API 中进行特殊处理。
可以通过挤出 2D 形状来创建 3D 元素。当您在编辑器中将 2D 形状元素转换为 3D 时,它会生成一个新的 type: "3D" 元素,并具有以下附加字段:
| 属性 | 类型 | 必需 | 示例 | 值范围 | 描述 |
|---|---|---|---|---|---|
| extrusionSource | object | false | - | - | 用于创建 3D 挤出的原始 2D 形状数据。包含完整的 ShapeNodeData。 |
| shapeSizeX | number | false | - | - | 挤出形状的宽度,单位为像素。 |
| shapeSizeY | number | false | - | - | 挤出形状的高度,单位为像素。 |
| shapeExtrusion | number | false | - | - | 沿 Z 轴的挤出深度,单位为像素。 |
| shapeCorner | string | false | - | round | chamfer | straight | 挤出形状的角落类型。 |
| shapeRoundnessSmooth | number | false | - | 0 - 1 | 圆角的平滑度(0-1)。 |
| shapeRoundnessArc | number | false | - | - | 圆角的弧半径。 |
| shapeBevel | number | false | - | - | 边缘的倒角深度。 |
| shapeBevelSides | number | false | - | - | 倒角边缘的段数。 |
3D 元素还可以表示具有深度和倒角的三维文本:
| 属性 | 类型 | 必需 | 示例 | 值范围 | 描述 |
|---|---|---|---|---|---|
| textContent | string | false | - | - | 要在 3D 中渲染的文本内容。 |
| textStyle3D | object | false | - | - | 文本样式属性(字体、大小、粗细等)。重用一些 2D 文本样式字段。 |
| textDepth | number | false | - | - | 3D 文本的挤出深度。 |
| textBevelSize | number | false | - | - | 文本边缘的倒角大小。 |
| textBevelSegments | number | false | - | - | 文本倒角的段数。 |
| textCurveSegments | number | false | - | - | 文本曲线的段数。 |
3D 元素使用 PBR(物理基础渲染)材料系统,具有全面的纹理支持:
| 属性 | 类型 | 必需 | 示例 | 值范围 | 描述 |
|---|---|---|---|---|---|
| material | object | false | - | - | 完整的材料配置,包括 PBR 属性和纹理贴图。 |
material 对象包含:
physicalMaterialData - PBR 材料属性:
color (string) - 以十六进制格式表示的基础颜色,默认值:'#818cf8'roughness (number) - 表面粗糙度,0-1,默认值:0.4metalness (number) - 金属属性,0-1,默认值:0.0opacity (number) - 材料不透明度,0-1,默认值:1.0transmission (number) - 玻璃状材料的光传输,0-1,默认值:0.0ior (number) - 折射率,通常为 1.0-2.5,默认值:1.5clearcoat (number) - 清漆涂层强度,0-1,默认值:0.0clearcoatRoughness (number) - 清漆粗糙度,0-1,默认值:0.0sheen (number) - 类似织物的光泽效果,0-1,默认值:0.0sheenRoughness (number) - 光泽粗糙度,0-1,默认值:0.0sheenColor (string) - 光泽色调颜色thickness (number) - 材料的传输厚度materialXPath (string) - 可选的 MaterialX 预设路径:
纹理贴图 - 材料对象可以包含纹理贴图 URL:
colorMap - 基础颜色/漫反射纹理normalMap - 表面细节的法线贴图roughnessMap - 粗糙度纹理metalnessMap - 金属度纹理aoMap - 环境遮蔽贴图emissiveMap - 发光/辉光纹理纹理贴图使用 TSL(Three.js 着色语言)函数应用,以获得最佳性能。
具有 nodeType: "model" 或 nodeType: "import" 的 3D 元素表示导入的 3D 模型:
注意:
nodeType: "import"是"model"的别名。两者都被支持并表现相同。
source.url 指定远程 glTF/glb/FBX 文件的 URLsourceId 获取并缓存模型animation.currentIndex 选择要播放的动画currentIndex (number)、speed (number,默认 1.0)、loop (boolean,默认 true)sizeParams 包含模型尺寸的 width、height、depth
{
"id": "3d-cube-001",
"type": "3D",
"start": 0,
"duration": 5,
"trackIndex": 0,
"x": 540,
"y": 540,
"z": 0,
"width": 200,
"height": 200,
"anchorX": 100,
"anchorY": 100,
"rotation": 0,
"rotationX": 30,
"rotationY": 45,
"scaleX": 1,
"scaleY": 1,
"scaleZ": 1,
"alpha": 1,
"ext": "geometry",
"nodeType": "geometry",
"category": "basic",
"geometryType": "cube",
"material": {
"physicalMaterialData": {
"color": "#4A90E2",
"roughness": 0.4,
"metalness": 0.0
}
}
}
{
"id": "3d-extrusion-001",
"type": "3D",
"start": 0,
"duration": 5,
"trackIndex": 0,
"x": 540,
"y": 540,
"z": 0,
"width": 300,
"height": 300,
"anchorX": 150,
"anchorY": 150,
"rotation": 0,
"rotationX": 0,
"rotationY": 0,
"scaleX": 1,
"scaleY": 1,
"scaleZ": 1,
"alpha": 1,
"ext": "parametric",
"nodeType": "parametric",
"category": "extrusion",
"shapeSizeX": 300,
"shapeSizeY": 300,
"shapeExtrusion": 100,
"material": {
"physicalMaterialData": {
"color": "#FF6B6B",
"roughness": 0.3,
"metalness": 0.1
}
},
"extrusionSource": {
"shapeType": "SHAPE_STAR",
"starPoints": 5,
"starInnerRadius": 0.4
}
}
{
"id": "3d-model-001",
"type": "3D",
"start": 0,
"duration": 10,
"trackIndex": 0,
"x": 540,
"y": 540,
"z": -200,
"width": 400,
"height": 400,
"anchorX": 200,
"anchorY": 200,
"rotation": 0,
"rotationX": 0,
"rotationY": 0,
"scaleX": 1,
"scaleY": 1,
"scaleZ": 1,
"alpha": 1,
"ext": "glb",
"nodeType": "model",
"sourceId": "cached-model-123",
"source": {
"url": "https://example.com/models/animated_character.glb"
},
"animation": {
"currentIndex": 0,
"speed": 1.0,
"loop": true
},
"sizeParams": {
"width": 2,
"height": 2,
"depth": 2
},
"originalWidth": 2,
"originalHeight": 2,
"originalDepth": 2
}