Skip to content

Commit

Permalink
射线检测增加一个提前的包围盒检测。
Browse files Browse the repository at this point in the history
没有计划的版本迭代随着我的心情升级到0.4.0。
  • Loading branch information
QinChengMaoXian authored and QinChengMaoXian committed Apr 21, 2019
1 parent 04bec77 commit b5404a7
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 7 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# cheng3d
# ver. 0.4.0
#
# Setup nodejs.
#
# Run 'npm install'
# Run 'npm run start-dev'
# Open url into your brower '127.0.0.1:8000'
# Brower open '127.0.0.1:8000'
1 change: 1 addition & 0 deletions TODO
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# Shadowed spot light and point light lum attenuation
# Animation
# Raycaster to line and point
# Particle
# UI render
# Mesh componentized
# WebGL 2.0 support
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "cheng3d",
"description": "A WEB 3D ENGINE BASED ON WEBGL",
"version": "0.3.0",
"version": "0.4.0",
"main": "test.ts",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
Expand Down
5 changes: 5 additions & 0 deletions src/bounding/AABB.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { SphereBounding } from './SphereBounding';
import { Vector3 } from '../math/Vector3';
import { Matrix4 } from '../math/Matrix4';
import { Box } from '../math/Box';
import { Ray } from '../math/Ray';

export class AABB extends Bounding {
protected _box: Box = new Box();
Expand All @@ -16,6 +17,10 @@ export class AABB extends Bounding {
this._box.applyMatrix(mat);
}

public intersectRay(ray: Ray) {
return ray.isIntersectBox(this._box);
}

public intersect(bounding: Bounding) {
const type = bounding.getType();
switch(type) {
Expand Down
5 changes: 5 additions & 0 deletions src/bounding/Bounding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { AABB } from './AABB';
import { SphereBounding } from './SphereBounding';

import { Matrix4 } from '../math/Matrix4';
import { Ray } from '../math/Ray';

export enum BoundingType {
TYPE_SPHERE = 0,
Expand Down Expand Up @@ -41,6 +42,10 @@ export class Bounding {
return null;
}

public intersectRay(ray: Ray) {
return true;
}

private static _obb1Pos: Vector3[] = [new Vector3(), new Vector3(), new Vector3(), new Vector3(), new Vector3(), new Vector3(), new Vector3(), new Vector3()];
private static _obb2Pos: Vector3[] = [new Vector3(), new Vector3(), new Vector3(), new Vector3(), new Vector3(), new Vector3(), new Vector3(), new Vector3()];

Expand Down
5 changes: 5 additions & 0 deletions src/bounding/SphereBounding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { OBB } from './OBB'
import { Vector3 } from '../math/Vector3';
import { Matrix4 } from '../math/Matrix4';
import { Sphere } from '../math/Sphere';
import { Ray } from '../math/Ray';

export class SphereBounding extends Bounding {
protected _sphere: Sphere = new Sphere();
Expand All @@ -20,6 +21,10 @@ export class SphereBounding extends Bounding {
public applyMatrix(mat: Matrix4) {
this._sphere.applyMatrix(mat);
}

public intersectRay(ray: Ray) {
return ray.isInstersectSphere(this._sphere);
}

public intersect(bounding: Bounding) {
const type = bounding.getType();
Expand Down
4 changes: 4 additions & 0 deletions src/object/Mesh.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ Mesh.prototype.raycast = function() {
return;
}

if (this._bounding && (!this._bounding.intersectRay(raycaster.ray))) {
return;
}

let backCulling = true;
if (!cullmode || cullmode === CGE.ZERO) {
backCulling = false;
Expand Down
2 changes: 0 additions & 2 deletions src/renderer/pipeline/ShadowMapPipeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ import { LogBlurMaterial } from "../../material/LogBlurMaterial";
import { Mesh } from "../../object/Mesh";
import { ScreenGeometry } from "../../util/GeometryUtil";
import { Texture2D } from '../../graphics/Texture2D';
import { GaussianBlurMaterial } from '../../material/GaussianBlurMaterial';
import { DownSample4Material } from '../../material/DownSample4Material';
import { PointLight } from '../../light/PointLight';
import { CubeVectors } from '../../graphics/TextureCube';

Expand Down
6 changes: 3 additions & 3 deletions test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ let gb = Math.pow(0.5, 2.2);
renderer.setClearColor(1.0, gb, gb, 1.0);
// renderer.setClearColor(0, 0, 0, 1.0);

camera.lookAt(new CGE.Vector3(0, 1, 10));
// camera.lookAt(new CGE.Vector3(0, 1, 10));
mainScene.setActiveCamera(camera);

document.body.appendChild(renderer.getCanvas());
Expand Down Expand Up @@ -261,7 +261,7 @@ for(let i = 0; i < 4; i++) {
p.setPosition(20, 20, 20);
p.setDir(-1, 1, 1);
p.angle = 0.5 * Math.PI * 0.5;
p.enableShadow();
// p.enableShadow();
p.setFactor(0.9999);
mainScene.addChild(p);
window['sss'] = p;
Expand All @@ -271,7 +271,7 @@ for(let i = 0; i < 4; i++) {
let p = new CGE.PointLight();
p.setColor(4, 0, 0);
p.setPosition(150, -30, 20);
p.enableShadow();
// p.enableShadow();
p.setFactor(0.9999);
mainScene.addChild(p);
window['ppp'] = p;
Expand Down

0 comments on commit b5404a7

Please sign in to comment.