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)
相关推荐
weixin_409383124 小时前
godot等轴视角tilemaplayer的学习 isocheric的素材xy大小怎么调
学习·游戏引擎·godot
WarrenMondeville7 小时前
2.Unity面向对象- 开闭原则
unity·游戏引擎·开闭原则
呆呆敲代码的小Y8 小时前
UnityMCP+Claude+VSCode,构建最强AI游戏开发环境
人工智能·vscode·游戏·unity·游戏引擎·u3d·mcp
C蔡博士8 小时前
Unity TextMeshPro 中文本地化:动态生成最小字体集(解决边缘模糊、乱码问题)
unity·游戏引擎
m0_630182468 小时前
Unity TMP 中文字体生成
unity·游戏引擎
weixin_409383128 小时前
godot y排序定位 sprite原点 等轴视角地图块测试 isometric 碰撞测试 初学godot
游戏引擎·godot
万兴丶9 小时前
Unity用C#完成抖音小游戏接入引力引擎(Gravity Engine)完整指南,一篇文章讲清楚!
unity·c#·游戏引擎·抖音
WarrenMondeville13 小时前
3.Unity面向对象-里氏替换原则
unity·游戏引擎·里氏替换原则
张老师带你学1 天前
UnityVR弯曲UI
科技·游戏·unity·游戏引擎·模型
张老师带你学1 天前
unity作业,街角小场景
科技·游戏·unity·游戏引擎·模型