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 10:05:32 浏览: 160
vue中使用input[type="file"]实现文件上传功能
5星 · 资源好评率100%
可以通过一个简单的函数返回 `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]`。
阅读全文