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 中進行特殊處理。
3D 元素可以通過擠出 2D 形狀來創建。當您在編輯器中將 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 Shading Language)函數進行應用,以獲得最佳性能。
具有 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
}