|
@ -1,4 +1,4 @@ |
|
|
import { vec2, vec3, vec4, mat4 } from "../math"; |
|
|
|
|
|
|
|
|
import { vec2, vec3, vec4, mat4, Util } from "../math"; |
|
|
import { GLAttribBits, GLAttribState } from "../webgl/WebGLAttribState"; |
|
|
import { GLAttribBits, GLAttribState } from "../webgl/WebGLAttribState"; |
|
|
import { GLStaticMesh } from "../webgl/WebGLMesh"; |
|
|
import { GLStaticMesh } from "../webgl/WebGLMesh"; |
|
|
|
|
|
|
|
@ -122,7 +122,105 @@ export class GeometryData { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
let mesh: GLStaticMesh = new GLStaticMesh(gl, bits, buffer, this.indices.length > 0 ? new Uint16Array(this.indices) : null); |
|
|
let mesh: GLStaticMesh = new GLStaticMesh(gl, bits, buffer, this.indices.length > 0 ? new Uint16Array(this.indices) : null); |
|
|
|
|
|
|
|
|
|
|
|
this.buildBoundingBoxTo(mesh.mins, mesh.maxs); |
|
|
return mesh; |
|
|
return mesh; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* 获取包围盒数据 |
|
|
|
|
|
* @param mins |
|
|
|
|
|
* @param maxs |
|
|
|
|
|
*/ |
|
|
|
|
|
public buildBoundingBoxTo(mins: vec3, maxs: vec3): void { |
|
|
|
|
|
for (let i: number = 0; i < this.positions.length; i++) { |
|
|
|
|
|
Util.boundBoxAddPoint(this.positions[i], mins, maxs); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
export class Cube { |
|
|
|
|
|
/** |
|
|
|
|
|
* @var 半宽 |
|
|
|
|
|
*/ |
|
|
|
|
|
public halfWidth: number; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* @var 半高 |
|
|
|
|
|
*/ |
|
|
|
|
|
public halfHeight: number; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* @var 半深 |
|
|
|
|
|
*/ |
|
|
|
|
|
public halfDepth: number; |
|
|
|
|
|
|
|
|
|
|
|
public constructor(halfWidth: number = 0.2, halfHeight: number = 0.2, halfDepth: number = 0.2) { |
|
|
|
|
|
this.halfWidth = halfWidth; |
|
|
|
|
|
this.halfHeight = halfHeight; |
|
|
|
|
|
this.halfDepth = halfDepth; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/* |
|
|
|
|
|
/3--------/7 | |
|
|
|
|
|
/ | / | |
|
|
|
|
|
/ | / | |
|
|
|
|
|
1---------5 | |
|
|
|
|
|
| /2- - -|- -6 |
|
|
|
|
|
| / | / |
|
|
|
|
|
|/ | / |
|
|
|
|
|
0---------4/ |
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
|
|
public makeGeometryDataWithTextureCoord(): GeometryData { |
|
|
|
|
|
let ret: GeometryData = new GeometryData(); |
|
|
|
|
|
ret.positions = [ |
|
|
|
|
|
new vec3([-this.halfWidth, -this.halfHeight, this.halfDepth]), // 0
|
|
|
|
|
|
new vec3([this.halfWidth, -this.halfHeight, this.halfDepth]), // 4
|
|
|
|
|
|
new vec3([this.halfWidth, this.halfHeight, this.halfDepth]) // 5
|
|
|
|
|
|
]; |
|
|
|
|
|
|
|
|
|
|
|
ret.uvs = [ |
|
|
|
|
|
new vec2([0, 0]), |
|
|
|
|
|
new vec2([1, 0]), |
|
|
|
|
|
new vec2([1, 1]) |
|
|
|
|
|
]; |
|
|
|
|
|
return ret; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public makeGeometryData(): GeometryData { |
|
|
|
|
|
let ret: GeometryData = new GeometryData(); |
|
|
|
|
|
|
|
|
|
|
|
ret.positions.push(new vec3([-this.halfWidth, -this.halfHeight, this.halfDepth])); //0
|
|
|
|
|
|
ret.uvs.push(new vec2([1, 0])); |
|
|
|
|
|
|
|
|
|
|
|
ret.positions.push(new vec3([-this.halfWidth, this.halfHeight, this.halfDepth])); //1
|
|
|
|
|
|
ret.uvs.push(new vec2([1, 1])); |
|
|
|
|
|
|
|
|
|
|
|
ret.positions.push(new vec3([-this.halfWidth, -this.halfHeight, -this.halfDepth])); //2
|
|
|
|
|
|
ret.uvs.push(new vec2([0, 0])); |
|
|
|
|
|
|
|
|
|
|
|
ret.positions.push(new vec3([-this.halfWidth, this.halfHeight, -this.halfDepth])); //3
|
|
|
|
|
|
ret.uvs.push(new vec2([0, 1])); |
|
|
|
|
|
|
|
|
|
|
|
ret.positions.push(new vec3([this.halfWidth, -this.halfHeight, this.halfDepth])); //4
|
|
|
|
|
|
ret.uvs.push(new vec2([0, 0])); |
|
|
|
|
|
|
|
|
|
|
|
ret.positions.push(new vec3([this.halfWidth, this.halfHeight, this.halfDepth])); //5
|
|
|
|
|
|
ret.uvs.push(new vec2([0, 1])); |
|
|
|
|
|
|
|
|
|
|
|
ret.positions.push(new vec3([this.halfWidth, -this.halfHeight, -this.halfDepth])); //6
|
|
|
|
|
|
ret.uvs.push(new vec2([1, 0])); |
|
|
|
|
|
|
|
|
|
|
|
ret.positions.push(new vec3([this.halfWidth, this.halfHeight, -this.halfDepth])); //7
|
|
|
|
|
|
ret.uvs.push(new vec2([1, 1])); |
|
|
|
|
|
|
|
|
|
|
|
ret.indices.push(0, 1, 3, 0, 3, 2); // 左边
|
|
|
|
|
|
ret.indices.push(3, 7, 6, 3, 6, 2); // 后面
|
|
|
|
|
|
ret.indices.push(6, 7, 5, 6, 5, 4); // 右面
|
|
|
|
|
|
ret.indices.push(5, 1, 0, 5, 0, 4); // 前面
|
|
|
|
|
|
ret.indices.push(1, 5, 7, 1, 7, 3); // 上面
|
|
|
|
|
|
ret.indices.push(2, 6, 4, 2, 4, 0); // 下面
|
|
|
|
|
|
return ret; |
|
|
|
|
|
} |
|
|
} |
|
|
} |