web3d-three.js场景设计器-mesh网格添加多模型-模型描述随动

给场景中的模型加上广告牌描述,可以在模型的MESH里添加Sprite,配上相应的文字,

描述Sprite的位置则是在mesh中的相对位置,比如模型高10,那么我们可以给一个y等于10 来进行适配,这样在移动模型mesh网格时可以整体移动。

function createBox(data) {

const geometry = new THREE.BoxGeometry(data.width, data.height, data.length)

var material

var materials = []

if (data.groundTexture && data.groundTexture != '') {

const textures = data.groundTextures ? data.groundTextures : []

if (textures.length > 1) {

textures.forEach(element => {

if(element==''){

const tmpMaterial = new THREE.MeshStandardMaterial({

color: data.color,

opacity: data.opacity,

transparent: data.opacity < 1,

roughness: 1.0,

metalness: 0.0

})

materials.push(tmpMaterial)

}else{

var map = new THREE.TextureLoader().load(element)

map.wrapS = data.wrapType

map.wrapT = data.wrapType

map.repeat.set(data.repeatX, data.repeatY)

const tmpMaterial = new THREE.MeshStandardMaterial({

map: map

})

materials.push(tmpMaterial)

}

})

} else {

var map = new THREE.TextureLoader().load(data.groundTexture)

map.wrapS = data.wrapType

map.wrapT = data.wrapType

map.repeat.set(data.repeatX, data.repeatY)

material = new THREE.MeshStandardMaterial({

map: map

})

}

} else {

material = new THREE.MeshStandardMaterial({

color: data.color,

opacity: data.opacity,

transparent: data.opacity < 1,

roughness: 1.0,

metalness: 0.0

})

}

const box = new THREE.Mesh(geometry, materials.length > 0 ? materials : material)

// 创建立方体描述

if(data.text&&data.text!='')

createSprite({text:data.text, fontSize:100, textColor: '#ffffff', color: '#1781b5', imageUrl:''

,position:{x:0, y:0, z:0},rotate:{x:0, y:0, z:0},scale:{x:1, y:1, z:1}}).then(sprite=>{

sprite.position.y=data.height;

sprite.visible=true;

sprite.userData.text=data.text;

box.add(sprite)

})

box.name = data.name

box.castShadow = true

box.userData.height = data.height

return box

}

相关推荐
nbsaas-boot1 小时前
Java 正则表达式白皮书:语法详解、工程实践与常用表达式库
开发语言·python·mysql
chao_7891 小时前
二分查找篇——搜索旋转排序数组【LeetCode】两次二分查找
开发语言·数据结构·python·算法·leetcode
一斤代码2 小时前
vue3 下载图片(标签内容可转图)
前端·javascript·vue
风无雨2 小时前
GO 启动 简单服务
开发语言·后端·golang
中微子2 小时前
React Router 源码深度剖析解决面试中的深层次问题
前端·react.js
光影少年2 小时前
从前端转go开发的学习路线
前端·学习·golang
斯普信专业组2 小时前
Go语言包管理完全指南:从基础到最佳实践
开发语言·后端·golang
中微子2 小时前
React Router 面试指南:从基础到实战
前端·react.js·前端框架
3Katrina2 小时前
深入理解 useLayoutEffect:解决 UI "闪烁"问题的利器
前端·javascript·面试
前端_学习之路3 小时前
React--Fiber 架构
前端·react.js·架构