Skip to content

Commit

Permalink
-hit triggers
Browse files Browse the repository at this point in the history
  • Loading branch information
neuroprod committed Dec 10, 2023
1 parent f95606a commit 9f81b5c
Show file tree
Hide file tree
Showing 45 changed files with 198 additions and 68 deletions.
Binary file modified frontend/public/textures/bigtree_Color.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified frontend/public/textures/bigtree_MRA.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified frontend/public/textures/bigtree_Normal.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified frontend/public/textures/birdHouse_Color.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified frontend/public/textures/birdHouse_MRA.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified frontend/public/textures/birdHouse_Normal.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified frontend/public/textures/can_Color.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified frontend/public/textures/can_MRA.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified frontend/public/textures/can_Normal.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified frontend/public/textures/fens_Color.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified frontend/public/textures/fens_MRA.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified frontend/public/textures/fens_Normal.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified frontend/public/textures/fern_AC_Color.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified frontend/public/textures/fern_AC_MRA.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified frontend/public/textures/fern_AC_Normal.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified frontend/public/textures/flowerBase_AC_Color.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified frontend/public/textures/grass_AC_Color.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified frontend/public/textures/grass_AC_MRA.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified frontend/public/textures/groundFront_Color.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified frontend/public/textures/groundFront_MRA.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified frontend/public/textures/groundFront_Normal.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified frontend/public/textures/ground_Color.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified frontend/public/textures/midGround_Color.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified frontend/public/textures/midGround_MRA.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified frontend/public/textures/midGround_Normal.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified frontend/public/textures/pineLeaves_AC_Color.png
Binary file modified frontend/public/textures/pineLeaves_AC_Normal.png
Binary file modified frontend/public/textures/shovel_Color.png
Binary file modified frontend/public/textures/shovel_MRA.png
Binary file modified frontend/public/textures/shovel_Normal.png
Binary file modified frontend/public/textures/smallPine_Color.png
Binary file modified frontend/public/textures/smallPine_MRA.png
38 changes: 36 additions & 2 deletions frontend/src/GameModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import {Vector2, Vector3} from "math.gl";
import Main from "./Main";
import GoInside from "./transitions/GoInside";
import mapRange = gsap.utils.mapRange;
import Trigger from "./trigers/Trigger";
import HitTrigger from "./trigers/HitTrigger";
import UI from "./lib/UI/UI";



Expand All @@ -26,6 +29,7 @@ class GameModel {


public currentScene:Scenes =Scenes.ROOM

public yMouseCenter: number = 1;
public yMouseScale: number = 1;
public sceneHeight =3;
Expand All @@ -36,11 +40,26 @@ class GameModel {
public characterPos: Vector3 = new Vector3(0, 0, 0);
dayNight: number = 0;
lockView: boolean =false;
constructor() {
}


private triggers:Array<Trigger>=[]

private _hitObjectLabel: string ="";
public hitStateChange: boolean =false;
public hitObjectLabelPrev: string ="";
constructor() {

this.makeTriggers();
}
private makeTriggers() {
this.triggers.push(new HitTrigger(Scenes.ROOM, "door_HO"))
}
update(){
for(let t of this.triggers){
t.check();
}
this.hitStateChange =false;
}


public setScene(scenes:Scenes){
Expand All @@ -53,6 +72,21 @@ class GameModel {
transitionComplete(){
// console.log("complete")
}
get hitObjectLabel(): string {
return this._hitObjectLabel;
}

set hitObjectLabel(value: string) {
if(value == this._hitObjectLabel){
return;
}
UI.logEvent("HIT",value)

this.hitStateChange =true;
this.hitObjectLabelPrev = this._hitObjectLabel;
this._hitObjectLabel = value;
}


}

Expand Down
3 changes: 2 additions & 1 deletion frontend/src/Main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -309,10 +309,11 @@ export default class Main {
this.shadowPassCube.setLightPos(this.room.mainLight.getWorldPos());
} else {
this.outside.update()

this.shadowPassCube.setLightPos(this.outside.lightGrave.getWorldPos());
}


GameModel.update()



Expand Down
2 changes: 2 additions & 0 deletions frontend/src/Outside.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,6 @@ export default class Outside {

}
}


}
7 changes: 6 additions & 1 deletion frontend/src/Room.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {FpsScreen} from "./extras/FpsScreen";
import ModelRenderer from "./lib/model/ModelRenderer";
import Mill from "./extras/Mill";
import Ray from "./lib/Ray";
import GameModel from "./GameModel";

export default class Room {
leftHolder: Object3D;
Expand Down Expand Up @@ -86,7 +87,11 @@ export default class Room {

checkMouseHit(mouseRay: Ray) {
for (let m of this.glFTLoader.modelsHit) {
m.checkHit(mouseRay);
if( m.checkHit(mouseRay)){

return;
}
}
GameModel.hitObjectLabel =""
}
}
2 changes: 1 addition & 1 deletion frontend/src/lib/Camera.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export default class Camera extends UniformGroup {
public far = 100;
public ratio = 1
public lensShift = new Vector2(0, 0)
public viewProjectionInv!: Matrix4;
public viewProjectionInv= new Matrix4();
public viewInv!: Matrix4;
public projectionInv!: Matrix4;
public perspective: boolean = true;
Expand Down
83 changes: 56 additions & 27 deletions frontend/src/lib/Ray.ts
Original file line number Diff line number Diff line change
@@ -1,52 +1,81 @@
import {Vector2, Vector3, Vector4} from "math.gl";
import {Matrix4, Vector2, Vector3, Vector4} from "math.gl";
import Camera from "./Camera";
import Renderer from "./Renderer";

export default class Ray{
export default class Ray {
public hit: boolean = false;
public hitPos: Vector3 = new Vector3();
private renderer: Renderer;
private rayStart: Vector3 =new Vector3();
private rayDir: Vector3 =new Vector3();
public hit:boolean=false;
public hitPos:Vector3 =new Vector3();
constructor(renderer:Renderer) {
this.renderer =renderer;
private rayStart: Vector3 = new Vector3();
private rayDir: Vector3 = new Vector3();

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

}

clone() {
let r = new Ray(this.renderer)
r.rayStart = this.rayStart;
r.rayDir = this.rayDir;
return r;
}
setFromCamera(camera:Camera,mousePosIn:Vector2)
{

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()
}

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()

}

intersectPlane(position:Vector3,normal:Vector3){
intersectPlane(position: Vector3, normal: Vector3) {

let denom = normal.dot(this.rayDir);
if (Math.abs(denom) > 0.0001) // your favorite epsilon
{

let t = (position.clone().subtract(this.rayStart)).dot(normal) / denom;
if (t < 0) {
this.hit = false;
return;
let t = (position.clone().subtract(this.rayStart)).dot(normal) / denom;
if (t < 0) {
this.hit = false;
return;
} else {
this.hit = true;
this.rayDir.clone().scale(t);
this.hitPos = this.rayStart.clone().add(this.rayDir.clone().scale(t)).subtract(position);
}

} else {
this.hit =true;
this.rayDir.clone().scale(t);
this.hitPos = this.rayStart.clone().add( this.rayDir.clone().scale(t)).subtract(position);
this.hit = false;
}

}

intersectsBox(min: Vector3, max: Vector3) {

}
const t1 = (min.x - this.rayStart.x) / this.rayDir.x;
const t2 = (max.x - this.rayStart.x) / this.rayDir.x;
const t3 = (min.y - this.rayStart.y) / this.rayDir.y;
const t4 = (max.y - this.rayStart.y) / this.rayDir.y;
const t5 = (min.z - this.rayStart.z) / this.rayDir.z;
const t6 = (max.z - this.rayStart.z) / this.rayDir.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));

} else {
this.hit = false;
if (tmax < 0) return false;
if (tmin > tmax) return false;
return true;
}

transform(invModel: Matrix4) {

}
this.rayDir.add(this.rayStart);
this.rayDir.transform(invModel);
this.rayStart.transform(invModel);
this.rayDir.subtract(this.rayStart);

}
}
2 changes: 1 addition & 1 deletion frontend/src/lib/core/Object3D.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +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;
public worldMatrixInv: Matrix4=new Matrix4();
constructor(renderer: Renderer, label: string = "") {
super(renderer, label);
}
Expand Down
23 changes: 11 additions & 12 deletions frontend/src/lib/meshes/HitTestObject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,17 @@ export default class HitTestObject{

}
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;*/

let rayT = ray.clone();
rayT.transform(invModel);
if(rayT.intersectsBox(this.min,this.max))
{

return true;

}

return false;

}
}
48 changes: 27 additions & 21 deletions frontend/src/lib/model/Model.ts
Original file line number Diff line number Diff line change
@@ -1,45 +1,51 @@

import Renderer from "../Renderer";
import Material from "../core/Material";
import Mesh from "../core/Mesh";
import Object3D from "../core/Object3D";
import ModelTransform from "./ModelTransform";
import HitTestObject from "../meshes/HitTestObject";
import Ray from "../Ray";
import GameModel from "../../GameModel";


export default class Model extends Object3D
{
export default class Model extends Object3D {
material!: Material;
mesh!:Mesh
mesh!: Mesh

public modelTransform: ModelTransform;
public visible: boolean =true;
public visible: boolean = true;
public hitTestObject: HitTestObject;
public canHitTest: boolean =false;
public canHitTest: boolean = false;

constructor(renderer:Renderer,label:string) {
super(renderer,label);
this.modelTransform =new ModelTransform(renderer,label+"_transform")
constructor(renderer: Renderer, label: string) {
super(renderer, label);
this.modelTransform = new ModelTransform(renderer, label + "_transform")

this.renderer.addModel(this);
}
public update()
{
if(!this._dirty)return;
this.updateMatrices()

}
protected updateMatrices(){
super.updateMatrices();
public update() {
if (!this._dirty) return;
this.updateMatrices()

this.modelTransform.setWorldMatrix(this.worldMatrix);
}
public checkHit(ray:Ray)
{
this.hitTestObject.checkHit(ray,this.worldMatrixInv)

public checkHit(ray: Ray) {
if(!this.visible) return false;
if(this.hitTestObject.checkHit(ray, this.worldMatrixInv)){
GameModel.hitObjectLabel =this.label;
return true;
}
return false;
}

destroy() {
if(this.parent)this.parent.removeChild(this);
if (this.parent) this.parent.removeChild(this);
}

protected updateMatrices() {
super.updateMatrices();

this.modelTransform.setWorldMatrix(this.worldMatrix);
}
}
2 changes: 1 addition & 1 deletion frontend/src/renderPasses/LightOutsideRenderPass.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export default class LightOutsideRenderPass extends RenderPass {
private globalLightMaterial: Material;
private blitGlobalLight: Blit;

private sunLightColor: ColorV = new ColorV(1.00,0.71,0.39,1.00);
private sunLightColor: ColorV = new ColorV(1.00,0.83,0.63,1.00);
private sunLightStrength: number =5.6;

private topColorDay: ColorV = new ColorV( 0.73,0.99,0.95,0.40);
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/shaders/GlobalLightOutsideShader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ fn mainFragment(@location(0) uv0: vec2f) -> @location(0) vec4f
for (var y = -1; y <= 1; y++) {
for (var x = -1; x <= 1; x++) {
let offset = vec2<f32>(vec2i(x, y)) * oneOverShadowDepthTextureSize;
shadowVal += textureSampleCompare(shadow, mySamplerComp, shadowUV+offset, shadowProjN.z-0.003);
shadowVal += textureSampleCompare(shadow, mySamplerComp, shadowUV+offset, shadowProjN.z-0.007);
}
}
shadowVal/=9.0;
Expand Down
36 changes: 36 additions & 0 deletions frontend/src/trigers/HitTrigger.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import Trigger from "./Trigger";
import GameModel, {Scenes} from "../GameModel";
import UI from "../lib/UI/UI";

export default class HitTrigger extends Trigger{
private objectLabel: string;
constructor(scene:Scenes,objectLabel:string) {
super(scene);
this.objectLabel =objectLabel;

}
check() {
if(!super.check())return false;
if(!GameModel.hitStateChange)return
if(GameModel.hitObjectLabel ==this.objectLabel) {
this.over()
return true;
}
if(GameModel.hitObjectLabelPrev ==this.objectLabel) {
this.out()
return true;
}




}

private over() {
//UI.logEvent("Over", this.objectLabel);
}

private out() {
// UI.logEvent("Out", this.objectLabel);
}
}
Loading

0 comments on commit 9f81b5c

Please sign in to comment.