你的浏览器禁用了JavaScript, 请开启后刷新浏览器获得更好的体验!
输入关键字进行搜索
搜索:
发现
话题
全文搜索
登录
[0]有没有实现的,类似Laya.TextMesh?
如题,想实现动态3d文字,请大佬执教一下!
没有找到相关结果
已邀请:
与内容相关的链接
提交
4 个回复
丫头别闹放下灯
赞同来自:
/**
* 生成3D文字贴图
* @param plane plane模型
* @param num 生成的文字
* @param width 贴图的宽
* @param height 贴图的高
* @param size 字体的大小
* @param Addy 下偏移
*/
public static Texture3DUI(plane: Laya.MeshSprite3D, num: string, width: number = 256, height: number = 256, size: number = 50, Addy: number = 20) {
let cav = Laya.Browser.createElement("canvas");
let cxt = cav.getContext("2d");
cav.width = width;
cav.height = height;
cxt.fillStyle = 'rgb(' + '255' + ',' + '255' + ',255)';
cxt.font = "bold " + size + "px 黑体";
cxt.textAlign = "center";//文本的对齐方式
cxt.textBaseline = "center";//文本相对于起点的位置
cxt.fillText(num, width / 2, height / 2 + Addy);
let texture2D = new Laya.Texture2D(width, height);
texture2D.loadImageSource(cav);
let mat = new Laya.UnlitMaterial();
plane.meshRenderer.sharedMaterial = mat;
mat.renderMode = Laya.UnlitMaterial.RENDERMODE_TRANSPARENT;
mat.albedoTexture = texture2D;
plane.meshRenderer.sharedMaterial.cull = Laya.RenderState.CULL_NONE;
}
丫头别闹放下灯
赞同来自:
file:///C:\Users\Administrator\AppData\Roaming\Tencent\QQ\Temp\%W@GJ$ACOF(TYDYECOKVDYB.png
https://layaair2.ldc2.layabox. ... xture
参考案例
丫头别闹放下灯
赞同来自:
上面是我封装使用过
无雨之地
赞同来自:
createText(text: string = "", color: string, fontSize: number = 60, canClear: boolean = true): Laya.Sprite3D {
if (!this.fontList) {
this.fontList = new Array<Laya.Sprite3D>();
}
let textNode: Laya.Sprite3D = new Laya.Sprite3D("textNode");
let textMesh: Laya.MeshSprite3D = new Laya.MeshSprite3D(Laya.PrimitiveMesh.createPlane(2, 2), "textMesh");
textNode.addChild(textMesh);
textMesh.meshRenderer.castShadow = false;
textMesh.meshRenderer.receiveShadow = false;
textNode.transform.localPosition = new Laya.Vector3(0, 0, 0);
textMesh.transform.localRotationEuler = new Laya.Vector3(90, 180, 0);
this.changeText(textNode, text, color, fontSize);
if (canClear) {
this.fontList.push(textNode);
}
return textNode;
}
/**修改文本 */
changeText(node: Laya.Sprite3D, text: string, color: string, fontSize: number) {
if (!node) {
// console.log('请初始化名字对象后修改');
} else {
let textMesh = node.getChildAt(0) as Laya.MeshSprite3D;
let cav = Laya.Browser.createElement("canvas");
let ctx: CanvasRenderingContext2D = cav.getContext("2d");
cav.width = 256;
cav.height = 256;
ctx.fillStyle = color;
if (text.length > 3) {
fontSize = Math.floor(3 / text.length * 60);
}
ctx.font = "bold " + fontSize + "px " + this.fontName;
ctx.textAlign = "center";//文本的对齐方式
ctx.textBaseline = "middle";//文本相对于起点的位置
//设置文字,位置
ctx.fillText(text, 128, 128, 256);
//设置描边
ctx.lineWidth = 0.6;
ctx.strokeStyle = '#fff';
ctx.strokeText(text, 128, 128, 256);
let texture2D = new Laya.Texture2D(256, 256);
texture2D.loadImageSource(cav);
ctx.clearRect(0, 0, 256, 256);
Laya.Browser.removeElement(cav);
let oldMat = textMesh.meshRenderer.sharedMaterial as Laya.UnlitMaterial;
if (oldMat) {
let oldTexture = oldMat.albedoTexture;
oldTexture.destroy();
oldMat.albedoTexture = texture2D;
} else {
let mat: Laya.UnlitMaterial;
mat = new Laya.UnlitMaterial();
mat.renderMode = Laya.UnlitMaterial.RENDERMODE_TRANSPARENT;
mat.albedoTexture = texture2D;
textMesh.meshRenderer.sharedMaterial = mat;
textMesh.meshRenderer.receiveShadow = false;
textMesh.meshRenderer.castShadow = false;
}
(<Laya.BlinnPhongMaterial>textMesh.meshRenderer.sharedMaterial).cull = Laya.RenderState.CULL_NONE;
}
}
该问题目前已经被锁定, 无法添加新回复
发起人
138*****161
相关问题
微信关系链:LayaAir引擎针对微信小游戏好友关系链实现方案
2d拖尾效果的实现方案
如何实现微信登录?
有什么容器能够实现当子元素达到显示上限后自动滚屏,使得新添加的元素始终保持在最底部显示?
Tween如何实现无限循环改变alpha?
有无类似flashfirebug、firebug的H5 canvas Inspector?
LayaFlash:求ByteArray.jas ->readMultiByte对gb2312的实现翻译
分享,扩展Laya.Text组件实现简单的富文本
关于Laya实现Matter.js官方案例凹多边形的问题
屏幕适配怎样实现铺满全屏,又不被拉伸?
2D场景加载3d人物,3d人物如何实现动态半透明
问题状态
最新活动:
2022-04-12 11:41
浏览:
954
关注:
3
人
商务合作
4 个回复
丫头别闹放下灯
赞同来自:
* 生成3D文字贴图
* @param plane plane模型
* @param num 生成的文字
* @param width 贴图的宽
* @param height 贴图的高
* @param size 字体的大小
* @param Addy 下偏移
*/
public static Texture3DUI(plane: Laya.MeshSprite3D, num: string, width: number = 256, height: number = 256, size: number = 50, Addy: number = 20) {
let cav = Laya.Browser.createElement("canvas");
let cxt = cav.getContext("2d");
cav.width = width;
cav.height = height;
cxt.fillStyle = 'rgb(' + '255' + ',' + '255' + ',255)';
cxt.font = "bold " + size + "px 黑体";
cxt.textAlign = "center";//文本的对齐方式
cxt.textBaseline = "center";//文本相对于起点的位置
cxt.fillText(num, width / 2, height / 2 + Addy);
let texture2D = new Laya.Texture2D(width, height);
texture2D.loadImageSource(cav);
let mat = new Laya.UnlitMaterial();
plane.meshRenderer.sharedMaterial = mat;
mat.renderMode = Laya.UnlitMaterial.RENDERMODE_TRANSPARENT;
mat.albedoTexture = texture2D;
plane.meshRenderer.sharedMaterial.cull = Laya.RenderState.CULL_NONE;
}
丫头别闹放下灯
赞同来自:
参考案例
丫头别闹放下灯
赞同来自:
无雨之地
赞同来自:
if (!this.fontList) {
this.fontList = new Array<Laya.Sprite3D>();
}
let textNode: Laya.Sprite3D = new Laya.Sprite3D("textNode");
let textMesh: Laya.MeshSprite3D = new Laya.MeshSprite3D(Laya.PrimitiveMesh.createPlane(2, 2), "textMesh");
textNode.addChild(textMesh);
textMesh.meshRenderer.castShadow = false;
textMesh.meshRenderer.receiveShadow = false;
textNode.transform.localPosition = new Laya.Vector3(0, 0, 0);
textMesh.transform.localRotationEuler = new Laya.Vector3(90, 180, 0);
this.changeText(textNode, text, color, fontSize);
if (canClear) {
this.fontList.push(textNode);
}
return textNode;
}
/**修改文本 */
changeText(node: Laya.Sprite3D, text: string, color: string, fontSize: number) {
if (!node) {
// console.log('请初始化名字对象后修改');
} else {
let textMesh = node.getChildAt(0) as Laya.MeshSprite3D;
let cav = Laya.Browser.createElement("canvas");
let ctx: CanvasRenderingContext2D = cav.getContext("2d");
cav.width = 256;
cav.height = 256;
ctx.fillStyle = color;
if (text.length > 3) {
fontSize = Math.floor(3 / text.length * 60);
}
ctx.font = "bold " + fontSize + "px " + this.fontName;
ctx.textAlign = "center";//文本的对齐方式
ctx.textBaseline = "middle";//文本相对于起点的位置
//设置文字,位置
ctx.fillText(text, 128, 128, 256);
//设置描边
ctx.lineWidth = 0.6;
ctx.strokeStyle = '#fff';
ctx.strokeText(text, 128, 128, 256);
let texture2D = new Laya.Texture2D(256, 256);
texture2D.loadImageSource(cav);
ctx.clearRect(0, 0, 256, 256);
Laya.Browser.removeElement(cav);
let oldMat = textMesh.meshRenderer.sharedMaterial as Laya.UnlitMaterial;
if (oldMat) {
let oldTexture = oldMat.albedoTexture;
oldTexture.destroy();
oldMat.albedoTexture = texture2D;
} else {
let mat: Laya.UnlitMaterial;
mat = new Laya.UnlitMaterial();
mat.renderMode = Laya.UnlitMaterial.RENDERMODE_TRANSPARENT;
mat.albedoTexture = texture2D;
textMesh.meshRenderer.sharedMaterial = mat;
textMesh.meshRenderer.receiveShadow = false;
textMesh.meshRenderer.castShadow = false;
}
(<Laya.BlinnPhongMaterial>textMesh.meshRenderer.sharedMaterial).cull = Laya.RenderState.CULL_NONE;
}
}