Skip to content

Commit

Permalink
-disable dof
Browse files Browse the repository at this point in the history
  • Loading branch information
neuroprod committed Dec 7, 2023
1 parent b1194bb commit b3bc471
Show file tree
Hide file tree
Showing 9 changed files with 109 additions and 625 deletions.
658 changes: 40 additions & 618 deletions frontend/public/roomFinal.json

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions frontend/src/GLFTLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export default class GLFTLoader {
public root: Object3D;
public models: Array<Model> = []
public modelsGlass: Array<Model> = []
public modelsHit: Array<Model> = []
public modelsByName: { [name: string]: Model } = {};

public modelData: Array<ModelData> = [];
Expand Down Expand Up @@ -126,6 +127,7 @@ export default class GLFTLoader {
if (m.model.mesh.hitTestObject) {
m.model.hitTestObject = m.model.mesh.hitTestObject;
m.model.canHitTest = true;
this.modelsHit.push(m.model);
}
m.model.material = this.makeMaterial(m.model.mesh.label, m.skinID) //this.materials[m.meshID]
if (m.model.label.includes("_G")) {
Expand Down
11 changes: 7 additions & 4 deletions frontend/src/Main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import PostRenderPass from "./renderPasses/PostRenderPass";
import FXAARenderPass from "./renderPasses/FXAARenderPass";
import GameModel, {Scenes, Transitions} from "./GameModel";
import GameCamera from "./GameCamera";
import Ray from "./lib/Ray";


export default class Main {
Expand Down Expand Up @@ -80,18 +81,18 @@ export default class Main {
private animationMixer: AnimationMixer;
private characterHandler: CharacterHandler;

private sceneHeight = 3;

private room: Room;
private outside: Outside;
private sceneIndex: number = 0


private lightOutsidePass: LightOutsideRenderPass;
private shadowPass: ShadowPass;
private dofPass: DOFPass;
private postPass: PostRenderPass;
private FXAAPass: FXAARenderPass;
private gameCamera: GameCamera;

public mouseRay:Ray;
constructor(canvas: HTMLCanvasElement) {

this.canvasManager = new CanvasManager(canvas);
Expand All @@ -109,6 +110,7 @@ export default class Main {
this.startPreload.bind(this)
);
this.camera = new Camera(this.renderer, "mainCamera")
this.mouseRay =new Ray(this.renderer);
this.renderer.camera = this.camera;
this.gameCamera =new GameCamera(this.camera,this.renderer)
this.timeStampQuery = new TimeStampQuery(this.renderer, this.numberOfQueries)
Expand Down Expand Up @@ -263,13 +265,14 @@ export default class Main {


this.characterHandler.update(this.mouseListener.mousePos.clone(), this.mouseListener.isDownThisFrame)

this.gameCamera.update();
this.mouseRay.setFromCamera(this.camera,this.mouseListener.mousePos)
//this.shadowPassCube.setLightPos(this.room.mainLight.getWorldPos());
this.shadowPass.update(this.lightOutsidePass.sunDir,this.gameCamera.posSmooth)
//this.updateCamera();
if (GameModel.currentScene== Scenes.ROOM) {
this.room.update();
this.room.checkMouseHit(this.mouseRay);
this.shadowPassCube.setLightPos(this.room.mainLight.getWorldPos());
} else {
this.outside.update()
Expand Down
7 changes: 7 additions & 0 deletions frontend/src/Room.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {LaptopScreen} from "./extras/LaptopScreen";
import {FpsScreen} from "./extras/FpsScreen";
import ModelRenderer from "./lib/model/ModelRenderer";
import Mill from "./extras/Mill";
import Ray from "./lib/Ray";

export default class Room {
leftHolder: Object3D;
Expand Down Expand Up @@ -82,4 +83,10 @@ export default class Room {
this.glFTLoader.root.setPosition(0, -1.5, 0)
this.mill.update();
}

checkMouseHit(mouseRay: Ray) {
for (let m of this.glFTLoader.modelsHit) {
m.checkHit(mouseRay);
}
}
}
27 changes: 27 additions & 0 deletions frontend/src/lib/Ray.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import {Vector2, Vector3, Vector4} from "math.gl";
import Camera from "./Camera";
import Renderer from "./Renderer";

export default class Ray{
private renderer: Renderer;
private rayStart: Vector3;
private rayDir: Vector3;

constructor(renderer:Renderer) {
this.renderer =renderer;

}
setFromCamera(camera:Camera,mousePosIn:Vector2)
{
let mousePos = mousePosIn.clone().scale(new Vector2(2 / (this.renderer.width / this.renderer.pixelRatio), 2 / (this.renderer.height / this.renderer.pixelRatio)))
let pos = new Vector4(mousePos.x - 1, (mousePos.y - 1) * -1, 1, 1);
if (camera.viewProjectionInv) {
pos.transform(camera.viewProjectionInv);
this.rayStart = camera.cameraWorld.clone()
this.rayDir = new Vector3(pos.x - this.rayStart.x, pos.y - this.rayStart.y, pos.z - this.rayStart.z).normalize()
}
}



}
3 changes: 3 additions & 0 deletions frontend/src/lib/core/Object3D.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export default class Object3D extends ObjectGPU {
private _scale = new Vector3(1, 1, 1);
private _rotation = new Quaternion(0, 0, 0, 1);
public castShadow :boolean=true;
public worldMatrixInv: Matrix4;
constructor(renderer: Renderer, label: string = "") {
super(renderer, label);
}
Expand Down Expand Up @@ -98,6 +99,8 @@ export default class Object3D extends ObjectGPU {
} else {
this._worldMatrix.copy(this._localMatrix)
}
this.worldMatrixInv = this._worldMatrix.clone();
this.worldMatrixInv.invert();
this._dirty = false;
}

Expand Down
18 changes: 17 additions & 1 deletion frontend/src/lib/meshes/HitTestObject.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {Vector3} from "math.gl";
import {Matrix4, Vector3} from "math.gl";
import Ray from "../Ray";

export default class HitTestObject{

Expand All @@ -7,5 +8,20 @@ export default class HitTestObject{
constructor() {


}
checkHit(ray:Ray,invModel:Matrix4){
/*
const t2 = (this.max.x - this.ro.x) / this.rd.x;
const t3 = (min.y - this.ro.y) / this.rd.y;
const t4 = (max.y - this.ro.y) / this.rd.y;
const t5 = (min.z - this.ro.z) / this.rd.z;
const t6 = (max.z - this.ro.z) / this.rd.z;
const tmin = Math.max(Math.max(Math.min(t1, t2), Math.min(t3, t4)), Math.min(t5, t6));
const tmax = Math.min(Math.min(Math.max(t1, t2), Math.max(t3, t4)), Math.max(t5, t6));
if (tmax < 0) return false;
if (tmin > tmax) return false;*/

}
}
6 changes: 5 additions & 1 deletion frontend/src/lib/model/Model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import Mesh from "../core/Mesh";
import Object3D from "../core/Object3D";
import ModelTransform from "./ModelTransform";
import HitTestObject from "../meshes/HitTestObject";
import Ray from "../Ray";


export default class Model extends Object3D
Expand Down Expand Up @@ -34,7 +35,10 @@ export default class Model extends Object3D

this.modelTransform.setWorldMatrix(this.worldMatrix);
}

public checkHit(ray:Ray)
{
this.hitTestObject.checkHit(ray,this.worldMatrixInv)
}
destroy() {
if(this.parent)this.parent.removeChild(this);
}
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/renderPasses/PostRenderPass.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export default class PostRenderPass extends RenderPass {
this.colorAttachments = [this.colorAttachment];

this.blitMaterial = new Material(this.renderer, "blitPost", new PostShader(this.renderer, "post"))
this.blitMaterial.uniforms.setTexture("colorTexture",this.renderer.texturesByLabel["DOF"])
this.blitMaterial.uniforms.setTexture("colorTexture",this.renderer.texturesByLabel["CombinePass"])
this.blitMaterial.uniforms.setTexture("bloomTexture",this.renderer.texturesByLabel["BlurBloom"])


Expand Down

0 comments on commit b3bc471

Please sign in to comment.