const addTextF = (srcText, sizef, heightn, num,objMain) => { const loader = new FontLoader(manager); loader.load('./mapData/FZXiYuan-M01S_Regular.json', (font) => { let geometryText = [] let mesh = { obj: [], gropzhou:[] } const color = 0xffffff; const matLite = new THREE.MeshStandardMaterial({ color: color, emissive: color, emissiveIntensity: 15, transparent: true, opacity: 1, side: THREE.DoubleSide }); geometryText[num] = new TextGeometry(srcText, { font: font, size: sizef, height: heightn, curveSegments: 12, bevelEnabled: false, bevelThickness: 10, bevelSize: 16, bevelOffset: 0, bevelSegments: 5 }); mesh.obj[num] = new THREE.Mesh(geometryText[num], matLite) mesh.obj[num].name = '分支文字' mesh.obj[num].material.name = '分支文字材质' const box = new THREE.BoxHelper(mesh.obj[num], 0xffff00); let TextLength = (box.geometry.attributes.position.array[9] - box.geometry.attributes.position.array[6]) / 2//通过边界框计算出了生成数据长度 mesh.obj[num].position.x -= TextLength mesh.obj[num].position.z=0.4 mesh.obj[num].rotation.x=-90/180 *Math.PI mesh.gropzhou[num]=new THREE.Group() const formatter = new Intl.NumberFormat('en-US'); mesh.gropzhou[num].name='文字轴心'+formatter.format(num); mesh.gropzhou[num].add( mesh.obj[num]) objMain.add( mesh.gropzhou[num] ) } ) }如何把mesh.obj[num]导出
时间: 2023-06-18 12:05:48 浏览: 45
你可以使用 `THREE.OBJExporter` 将 `mesh.obj[num]` 导出为 OBJ 格式的文件。以下是一个示例代码:
```javascript
const exporter = new THREE.OBJExporter();
const result = exporter.parse(mesh.obj[num]);
console.log(result); // 输出导出的 OBJ 文件内容
```
你也可以将导出的内容保存为文件,可以使用 `FileSaver.js` 库实现。示例代码如下:
```javascript
const exporter = new THREE.OBJExporter();
const result = exporter.parse(mesh.obj[num]);
const blob = new Blob([result], { type: 'text/plain;charset=utf-8' });
saveAs(blob, 'mesh.obj'); // 保存为文件
```
相关问题
const addTextF = (srcText, sizef, heightn, num,objMain) => { const loader = new FontLoader(manager); loader.load('./mapData/FZXiYuan-M01S_Regular.json', (font) => { let geometryText = [] let mesh = { obj: [], gropzhou:[] } const color = 0xffffff; const matLite = new THREE.MeshStandardMaterial({ color: color, emissive: color, emissiveIntensity: 15, transparent: true, opacity: 1, side: THREE.DoubleSide }); geometryText[num] = new TextGeometry(srcText, { font: font, size: sizef, height: heightn, curveSegments: 12, bevelEnabled: false, bevelThickness: 10, bevelSize: 16, bevelOffset: 0, bevelSegments: 5 }); mesh.obj[num] = new THREE.Mesh(geometryText[num], matLite) mesh.obj[num].name = '分支文字' mesh.obj[num].material.name = '分支文字材质' const box = new THREE.BoxHelper(mesh.obj[num], 0xffff00); let TextLength = (box.geometry.attributes.position.array[9] - box.geometry.attributes.position.array[6]) / 2//通过边界框计算出了生成数据长度 mesh.obj[num].position.x -= TextLength mesh.obj[num].position.z=0.4 mesh.obj[num].rotation.x=-90/180 *Math.PI mesh.gropzhou[num]=new THREE.Group() const formatter = new Intl.NumberFormat('en-US'); mesh.gropzhou[num].name='文字轴心'+formatter.format(num); mesh.gropzhou[num].add( mesh.obj[num]) objMain.add( mesh.gropzhou[num] ) } ) }如何把mesh.obj[num]作为返回值返回
可以通过一个简单的函数返回 `mesh.obj[num]`。修改代码如下:
```
const addTextF = (srcText, sizef, heightn, num,objMain) => {
const loader = new FontLoader(manager);
loader.load('./mapData/FZXiYuan-M01S_Regular.json', (font) => {
let geometryText = []
let mesh = { obj: [], gropzhou:[] }
const color = 0xffffff;
const matLite = new THREE.MeshStandardMaterial({
color: color,
emissive: color,
emissiveIntensity: 15,
transparent: true,
opacity: 1,
side: THREE.DoubleSide
});
geometryText[num] = new TextGeometry(srcText, {
font: font,
size: sizef,
height: heightn,
curveSegments: 12,
bevelEnabled: false,
bevelThickness: 10,
bevelSize: 16,
bevelOffset: 0,
bevelSegments: 5
});
mesh.obj[num] = new THREE.Mesh(geometryText[num], matLite)
mesh.obj[num].name = '分支文字'
mesh.obj[num].material.name = '分支文字材质'
const box = new THREE.BoxHelper(mesh.obj[num], 0xffff00);
let TextLength = (box.geometry.attributes.position.array[9] - box.geometry.attributes.position.array[6]) / 2//通过边界框计算出了生成数据长度
mesh.obj[num].position.x -= TextLength
mesh.obj[num].position.z=0.4
mesh.obj[num].rotation.x=-90/180 *Math.PI
mesh.gropzhou[num]=new THREE.Group()
const formatter = new Intl.NumberFormat('en-US');
mesh.gropzhou[num].name='文字轴心'+formatter.format(num);
mesh.gropzhou[num].add(mesh.obj[num])
objMain.add(mesh.gropzhou[num])
})
return mesh.obj[num];
}
```
这样调用该函数时,就可以得到 `mesh.obj[num]`。
const loader = new MMDLoader();loader.load()的四个参数分别是什么
`MMDLoader` 的 `load` 方法的四个参数分别是:
1. `modelUrl` (必需) - 要加载的 MMD 模型的 URL 地址;
2. `vmdUrls` (可选) - 包含要加载的 VMD 动画的 URL 地址的数组;
3. `onLoad` (可选) - 当模型和动画加载完成时要调用的回调函数;
4. `onProgress` (可选) - 加载过程中要调用的回调函数,在加载过程中,可以使用它来显示加载进度。
例如:
```javascript
loader.load(
'model.pmx',
['animation1.vmd', 'animation2.vmd'],
function (object) {
// 模型和动画加载完成后的回调函数
},
function ( xhr ) {
// 加载过程中的回调函数,可以用来显示加载进度
}
);
```
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)