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)
相关推荐
极客柒11 小时前
Unity 塔防自用可视化路点寻路编辑器
unity·编辑器·游戏引擎
一线灵1 天前
跨平台游戏引擎 Axmol-2.8.1 发布
junit·游戏引擎
王家视频教程图书馆1 天前
2025年最新 unityHub游戏引擎开发2d手机游戏和桌面游戏教程
游戏·unity·游戏引擎
Xeon_CC3 天前
Unity中,软遮罩SoftMaskForUGUI的使用
unity·游戏引擎
DanmF--3 天前
NGUI--三大基础组件
unity·游戏引擎
Xeon_CC3 天前
Unity中,软遮罩SoftMaskForUGUI可移动遮罩形状实现方法
unity·游戏引擎
Yasin Chen3 天前
Unity Standard Shader 解析(五)之ShadowCaster
unity·游戏引擎
我想_iwant4 天前
android集成unity后动态导入 assetsBundle
android·unity·游戏引擎
EQ-雪梨蛋花汤4 天前
【踩坑记录】Unity 项目中 PlasticSCM 掩蔽列表引发的 文件缺失问题排查与解决
unity·游戏引擎
Thinbug4 天前
Unity 枪械红点瞄准器计算
unity·游戏引擎