three.js中的文字
1.三维文字
三维字体文字,使用的是FontLoader,字体文件通过来facetype.js生成
addCityText: function () {
var self = this;
var citys = self.citys[self.mapname];
var group = new THREE.Group();
group.name = "cityname";
//载入字体
var loader = new THREE.FontLoader();
loader.load("../assets/fonts/FZLanTingHeiS-UL-GB_Regular.json", function (font) {
//创建文字
for (city of citys) {
var textGeo = new THREE.TextGeometry(city.name, {
font: font,
size: 1.4,
height: 0.6,
weight: 'bold',
});
var txtMater = new THREE.MeshBasicMaterial({ color: 0xffffff });
var textMesh = new THREE.Mesh(textGeo, txtMater);
textMesh.name = "movealbe-element-city";
textMesh.data = city;
textMesh.rotation.z = -0.5 * Math.PI;
textMesh.position.set(city.x, city.y-4, city.z);
group.add(textMesh);
// self.objects.push(textMesh);
}
});
group.rotation.z = 0.5 * Math.PI;
self.scene.add(group);
},
2.通过canvas创建文字
createTextTexture: function (obj) {
let canvas = document.createElement("canvas");
canvas.width=obj.width||400;
canvas.height=obj.height||200;
let ctx = canvas.getContext("2d");
ctx.font = obj.font||"Bold 50px Arial";
ctx.fillStyle = obj.color||"#fff";
ctx.fillText(obj.text, 10, 100);
let texture = new THREE.Texture(canvas);
texture.needsUpdate = true;
texture.wrapS = THREE.RepeatWrapping;
texture.wrapT = THREE.RepeatWrapping;
return texture;
},
var self = this;
var material = new THREE.SpriteMaterial({
map: self.createTextTexture({
text:'文字内容',
width:700
}),
opacity: 0.8,
transparent: true
});
var particle = new THREE.Sprite(material);
particle.scale.set(25, 8, 10);
particle.position.set(-7, 13, 8);
self.scene.add(particle);
3.创建2D标签文本
示例代码:https://threejs.org/examples/#css2d_label,需要注意的是,这种方式还需要使用另外一个渲染器。那么在使用轨道控制器OrbitControls的时候,不要指明第二个参数,否则轨道控制机无法通过鼠标控制。
this.width = document.getElementById('WebGL-output').clientWidth;
this.height = document.getElementById('WebGL-output').clientHeight;
//渲染器
this.renderer = new THREE.WebGLRenderer({ antialias: true, alpha: true });
this.renderer.setClearColor('rgba(0,0,0,0.1)', 0.0);
this.renderer.setSize(this.width, this.height);
this.renderer.shadowMapEnabled = true;
document.getElementById("WebGL-output").appendChild(this.renderer.domElement);
this.labelRenderer = new THREE.CSS2DRenderer();
this.labelRenderer.setSize(this.width, this.height);
this.labelRenderer.domElement.style.position = 'absolute';
this.labelRenderer.domElement.style.top = 0;
document.getElementById("WebGL-output").appendChild(this.labelRenderer.domElement);
//点
var point1 = new THREE.Sprite(new THREE.SpriteMaterial({
map: self.createLightTexure({type:3}),
opacity: 0.8,
transparent: true
}));
point1.scale.set(1.2, 1.2, 1.2);
point1.position.set(-27, 15, 25);
point1.rotation.y = 0.05 * Math.PI;
group.add(point1); var tipDiv = document.createElement('div');
tipDiv.innerHTML=`
<div class="leftTip" style="">
<image src="../assets/image/camera.png" width="30px" height="30px">
<span>1</span>
</div>
<div class="leftTip" style="margin-top:20px;">
<image src="../assets/image/importantPeople.png" width="30px" height="30px">
<span>2</span>
</div>
<div class="leftTip" style="margin-top:20px;">
<image src="../assets/image/room.png" width="30px" height="30px">
<span>3</span>
</div>
`;
tipDiv.style.marginTop = '-1em';
var tipLabel = new THREE.CSS2DObject(tipDiv);
tipLabel.position.set(-4, -3.3, 0);
point1.add(tipLabel);
three.js中的文字的更多相关文章
- 关于three.js中添加文字的方式[转]
https://blog.csdn.net/qq563969790/article/details/76584976 网上资料大部分是通过引入外部font库进行文字效果的载入,但是在实际运行的时候发现 ...
- JS事件 内容选中事件(onselect)选中事件,当文本框或者文本域中的文字被选中时,触发onselect事件,同时调用的程序就会被执行。
内容选中事件(onselect) 选中事件,当文本框或者文本域中的文字被选中时,触发onselect事件,同时调用的程序就会被执行. 如下代码,当选中用户文本框内的文字时,触发onselect 事件, ...
- 实现password框中显示文字提示的方式
其实实际上实现中并不能让password中显示文字提示,但是我们在工作中有这样的需求,当没输入东西的时候,框内有提示输入密码,但是当输入东西的时候又显示的是*号,那么是如何实现的呢?其实原理很简单,就 ...
- JS中innerHTML,innerText,value
一·.JS初学者易混淆的问题:innerHTML,innerText,value(他们和JQ的区别:JS→value,JQ→value()) 1.getElementById("a" ...
- js中NAN、NULL、undefined的区别
NaN:保留字(表明数据类型不是数字) undefined:对象属性或方法不存在,或声明了变量但从未赋值.即当你使用了对象未定的属性或者未定义的方法时或当你声明一个变量,但你确从未对其进行赋值,便对其 ...
- 聊一下JS中的作用域scope和闭包closure
聊一下JS中的作用域scope和闭包closure scope和closure是javascript中两个非常关键的概念,前者JS用多了还比较好理解,closure就不一样了.我就被这个概念困扰了很久 ...
- JS中基本window.document对象操作以及常用事件!
一.找到元素 1.document.getELementById("id"):根据id找,最多找一个. var a=document.getELementById("id ...
- js-分享107个js中的非常实用的小技巧(借鉴保存)
转载原文:http://***/Show.aspx?id=285 1.document.write(""); 输出语句 2.JS中的注释为// 3.传统的HTML文档顺序是:doc ...
- (转)JS中innerHTML,innerText,value
原文:http://holysonll.blog.163.com/blog/static/21413909320134111054352/ JS中innerHTML,innerText,value 2 ...
随机推荐
- django项目中购物车的实现
对于做项目而言,最重要的是分析清楚自己负责模块的思路,确定思路后,把每一步实现的步骤确定后,根据步骤,去实现代码,测试. 购物车的逻辑: 登录用户可以添加购物车,未登陆用户页可以添加到购物车 ...
- ejabberd之开题篇
ejabberd是基于Jabber/XMPP协议的即时通讯服务器.采用Erlang/OTP开发.它的特点是,跨平台,容错,集群和模块化. 因为自己本身是基于erlang工作,而且听到有不少的公 ...
- bbs项目学习到的知识点(orm中的extra)
注册 form组件给input 的标签 添加样式类 参见这篇博客(点击) 上传图像 1.解决 一点击图像就会直接打开上传文件的按钮 #这儿利用了 label标签和input的特殊的联动功能 < ...
- python基础1-转自金角大王
Python之路,Day1 - Python基础1---转自金角大王 本节内容 Python介绍 发展史 Python 2 or 3? 安装 Hello World程序 变量 用户输入 模块初识 ...
- hive从本地导入数据时出现「Execution Error, return code 1 from org.apache.hadoop.hive.ql.exec.MoveTask」错误
现象 通过load data local导入本地文件时报无法导入的错误 hive> load data local inpath '/home/hadoop/out/mid_test.txt' ...
- s21day20 python笔记
s21day20 python笔记 一.内容回顾 面向对象的三大特性 封装 函数封装到类 数据封装到对象 继承 多态 二.成员 2.1 类成员 类变量(静态字段) 定义:写在类的下一级,和方法同一级 ...
- slf4j的使用2
一.Log4J的配置文件(Configuration File)就是用来设置记录器的级别.存放器和布局的,它可接key=value格式的设置或xml格式的设置信息.通过配置,可以创建出Log4J的运行 ...
- js判断页面在pc端打开还是移动端打开
js判断页面在pc端打开还是移动端打开,分别跳转不同的index.html window.addEventListener('load', function() { // true为手机,false为 ...
- 真tm郁闷
昨天这时还是信心满满,今天这时就已经彻底颓了. 感觉这次是最接近的了,4个题目都做出来了,怎么还会fail,那边也不说为什么,到底是哪里不足,尽说些没用的. 前后都当了4次炮灰了,以后也不会再冲动了, ...
- routeros DDNS 动态域名更新IP
:local ednsuser "账号":local ednspass "密码":local ednshost "域名":local edn ...