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)
相关推荐
Brianna Home1 天前
Godot4.3开发2D游戏全记录
游戏·游戏引擎·godot·游戏程序·动画
王维志1 天前
使用Asp.Net WebApi(.net 8)托管Unity WebGL
unity·游戏引擎·webgl
开发游戏的老王1 天前
虚幻引擎入门教程:虚幻引擎的安装
游戏引擎·虚幻
muyouking111 天前
Unreal Engine 中的旋转表示:FQuat 与 FRotator 全面解析
游戏引擎·虚幻
霜绛2 天前
Unity:Json笔记——Json文件格式、JsonUtlity序列化和反序列化
学习·unity·json·游戏引擎
开发游戏的老王2 天前
虚幻引擎虚拟制片入门教程 之 创建项目及启用插件
游戏引擎·虚幻
L X..2 天前
Unity反射调用 ReactiveProperty<T>(泛型类型)内部方法时崩溃
unity·c#·游戏引擎·.net
开发游戏的老王2 天前
虚幻引擎虚拟制片入门教程 之 模型资源的导入
java·游戏引擎·虚幻
向宇it3 天前
【推荐100个unity插件】将您的场景渲染为美丽的冬季风景——Global Snow 2
unity·游戏引擎·风景
浅丿忆十一3 天前
关于unity一个场景中存在多个相机时Game视图的画面问题
unity·游戏引擎