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)
相关推荐
qq_205279053 小时前
Unity TileMap 使用经验
unity·游戏引擎
心灵宝贝6 小时前
Mac Unity 2018.dmg游戏工具 安装步骤 简单易懂教程(附安装包)
macos·unity·游戏引擎
TO_ZRG7 小时前
Unity SDK 通过 Registry 分发及第三方依赖处理指南
unity·游戏引擎
7***n7511 小时前
C++在游戏中的Cocos2d-x
游戏·游戏引擎·cocos2d
龙智DevSecOps解决方案17 小时前
Perforce《2025游戏技术现状报告》Part 1:游戏引擎技术的广泛影响以及生成式AI的成熟之路
人工智能·unity·游戏引擎·游戏开发·perforce
Y***K4341 天前
C在游戏中的Godot
游戏·游戏引擎·godot
Q***f6352 天前
C++在游戏引擎开发中的实践
游戏引擎
6***x5452 天前
C++在计算机视觉中的图像处理
c++·图像处理·计算机视觉·游戏引擎·logback·milvus
霜绛2 天前
Unity:lua热更新(三)——Lua语法(续)
unity·游戏引擎·lua
evolution_language2 天前
Unity场景(Scene)的注意事项和易错点
unity·游戏引擎·scene