LayaBox1.8.4实现自定义3DMesh

实现mesh的原理可参考我写的Unity中的自定义mesh的原理,

碰撞检测算法------分离轴算法在Unity中实现(一)_unity 自定义高性能碰撞检测方案-CSDN博客

实现可传入shader两张贴图的顶点声明如下:

cpp 复制代码
	var vertexDeclaration=Laya.VertexPositionNormalTexture0Texture1.vertexDeclaration;

默认的顶点声明如下:

cpp 复制代码
	var vertexDeclaration=VertexPositionNormalTexture.vertexDeclaration;

实现代码:

cpp 复制代码
var CustomMesh=(function(_super){
	function CustomMesh(long,width){
		/**@private */
		this._long=NaN;
		/**@private */
		this._width=NaN;
		(long===void 0)&& (long=1);
		(width===void 0)&& (width=1);
		RoadMesh.__super.call(this);
		this._long=long;
		this._width=width;
		this.activeResource();
		this._positions=this._getPositions();
		this._generateBoundingObject();
	}

	Laya.class(CustomMesh,'laya.d3.resource.models.CustomMesh',_super);
	var __proto=RoadMesh.prototype;
	__proto.recreateResource=function(){
		this._numberVertices=4;
		this._numberIndices=6;
		var vertexDeclaration=Laya.VertexPositionNormalTexture0Texture1.vertexDeclaration;
		var vertexFloatStride=vertexDeclaration.vertexStride / 4;
        
		var vertices=new Float32Array([
		0,0,0,0,0,1,0,0,0,0,
        this._width,0,0,0,0,1,1,0,1,0,
        0,0,this._long,0,0,1,0,1,0,1,
        this._width,0,this._long,0,0,1,1,1,1,1]);
		
        var indices=new Uint16Array([
		0,1,2,3,2,1,]);

		this._vertexBuffer=new Laya.VertexBuffer3D(vertexDeclaration,this._numberVertices,/*laya.webgl.WebGLContext.STATIC_DRAW*/0x88E4,true);
		this._indexBuffer=new Laya.IndexBuffer3D(/*laya.d3.graphics.IndexBuffer3D.INDEXTYPE_USHORT*/"ushort",this._numberIndices,/*laya.webgl.WebGLContext.STATIC_DRAW*/0x88E4,true);
		this._vertexBuffer.setData(vertices);
		this._indexBuffer.setData(indices);
		this.memorySize=(this._vertexBuffer._byteLength+this._indexBuffer._byteLength)*2;
		this.completeCreate();
	}

	return CustomMesh;
})(Laya.PrimitiveMesh)
相关推荐
B0URNE1 天前
【Unity基础详解】(5)Unity核心:Coroutines协程
unity·游戏引擎
xiaotao1311 天前
unity hub在ubuntu 22.0.4上启动卡住
ubuntu·unity·游戏引擎
小句1 天前
通过图表和详细流程解释XXL-JOB中任务从创建到执行的完整过程
unity·游戏引擎
!chen2 天前
Unity颜色曲线ColorCurves
unity·游戏引擎
B0URNE2 天前
【Unity基础详解】(4)Unity核心类:MonoBehaviour
unity·游戏引擎
AA陈超3 天前
虚幻引擎5 GAS开发俯视角RPG游戏 P06-29 属性信息委托
c++·游戏·ue5·游戏引擎·虚幻
AA陈超3 天前
虚幻引擎5 GAS开发俯视角RPG游戏 P06-31 映射标签到属性
c++·游戏·ue5·游戏引擎·虚幻
gshh__3 天前
SuperMap Hi-Fi 3D SDK for Unreal 使用蓝图接口加载多源数据
ue5·游戏引擎·supermap
EQ-雪梨蛋花汤3 天前
【MRTK3踩坑记录】Unity 2022 中 MRTK3 Input Simulator 无法使用 WASD 控制相机的完整排查记录
数码相机·unity·游戏引擎
星夜泊客3 天前
Unity 游戏开发中的防御性编程与空值处理实践
unity·设计模式·游戏引擎