@nativewrappers/fivem 0.0.31 → 0.0.32
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/client/Raycast.d.ts +23 -1
- package/client/Raycast.js +56 -10
- package/client/World.d.ts +24 -11
- package/client/World.js +30 -15
- package/client/enums/RaycastEnums.d.ts +27 -0
- package/client/enums/RaycastEnums.js +30 -0
- package/client/enums/index.d.ts +1 -1
- package/client/enums/index.js +1 -1
- package/client/index.d.ts +1 -1
- package/client/index.js +1 -1
- package/common/utils/Vector.d.ts +53 -3
- package/common/utils/Vector.js +89 -3
- package/package.json +1 -1
- package/client/enums/IntersectOptions.d.ts +0 -15
- package/client/enums/IntersectOptions.js +0 -16
package/client/Raycast.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ import { Vector3 } from './utils';
|
|
|
4
4
|
/**
|
|
5
5
|
* Class that represents the result of a raycast.
|
|
6
6
|
*/
|
|
7
|
-
|
|
7
|
+
declare abstract class RaycastResult {
|
|
8
8
|
/**
|
|
9
9
|
* Return the entity that was hit.
|
|
10
10
|
*/
|
|
@@ -33,6 +33,17 @@ export declare class RaycastResult {
|
|
|
33
33
|
* Raycast result's handle.
|
|
34
34
|
*/
|
|
35
35
|
get Result(): number;
|
|
36
|
+
/**
|
|
37
|
+
* @returns if the shape test handle was already discarded
|
|
38
|
+
*/
|
|
39
|
+
get WasDiscarded(): boolean;
|
|
40
|
+
/**
|
|
41
|
+
* NOTE: These will not be updated unless polled by `resolve` or the shape
|
|
42
|
+
* test is synchronous
|
|
43
|
+
* @returns if the raycast has been marked as ready by the engine
|
|
44
|
+
*/
|
|
45
|
+
get HasResolved(): boolean;
|
|
46
|
+
protected applyShapeTestResults(): void;
|
|
36
47
|
private handle;
|
|
37
48
|
private hitPositionArg;
|
|
38
49
|
private hitSomethingArg;
|
|
@@ -47,3 +58,14 @@ export declare class RaycastResult {
|
|
|
47
58
|
*/
|
|
48
59
|
constructor(handle: number);
|
|
49
60
|
}
|
|
61
|
+
export declare class SynchronousRaycastResult extends RaycastResult {
|
|
62
|
+
constructor(handle: number);
|
|
63
|
+
}
|
|
64
|
+
export declare class AsynchronousRaycastResult extends RaycastResult {
|
|
65
|
+
/**
|
|
66
|
+
* waits until the shape test handle is valid and then sets the expected
|
|
67
|
+
* values on the RaycastResult
|
|
68
|
+
*/
|
|
69
|
+
resolve(timeoutInMs?: number): Promise<void>;
|
|
70
|
+
}
|
|
71
|
+
export {};
|
package/client/Raycast.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
+
import { ShapeTestStatus } from './enums/RaycastEnums';
|
|
1
2
|
import { Game } from './Game';
|
|
2
|
-
import { Vector3 } from './utils';
|
|
3
|
+
import { Delay, Vector3 } from './utils';
|
|
3
4
|
/**
|
|
4
5
|
* Class that represents the result of a raycast.
|
|
5
6
|
*/
|
|
6
|
-
|
|
7
|
+
class RaycastResult {
|
|
7
8
|
/**
|
|
8
9
|
* Return the entity that was hit.
|
|
9
10
|
*/
|
|
@@ -46,7 +47,33 @@ export class RaycastResult {
|
|
|
46
47
|
get Result() {
|
|
47
48
|
return this.result;
|
|
48
49
|
}
|
|
49
|
-
|
|
50
|
+
/**
|
|
51
|
+
* @returns if the shape test handle was already discarded
|
|
52
|
+
*/
|
|
53
|
+
get WasDiscarded() {
|
|
54
|
+
return this.result === ShapeTestStatus.Discarded;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* NOTE: These will not be updated unless polled by `resolve` or the shape
|
|
58
|
+
* test is synchronous
|
|
59
|
+
* @returns if the raycast has been marked as ready by the engine
|
|
60
|
+
*/
|
|
61
|
+
get HasResolved() {
|
|
62
|
+
return this.result === ShapeTestStatus.Ready;
|
|
63
|
+
}
|
|
64
|
+
applyShapeTestResults() {
|
|
65
|
+
const [result, hit, endCoords, surfaceNormal, materialHash, entityHit] = GetShapeTestResultIncludingMaterial(this.handle);
|
|
66
|
+
this.result = result;
|
|
67
|
+
if (!this.HasResolved || this.WasDiscarded)
|
|
68
|
+
return;
|
|
69
|
+
this.hitSomethingArg = hit;
|
|
70
|
+
this.hitPositionArg = Vector3.fromArray(endCoords);
|
|
71
|
+
this.surfaceNormalArg = Vector3.fromArray(surfaceNormal);
|
|
72
|
+
this.materialArg = materialHash;
|
|
73
|
+
if (entityHit !== 0) {
|
|
74
|
+
this.entityHandleArg = Game.entityFromHandle(entityHit);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
50
77
|
/**
|
|
51
78
|
* Create a RaycastResult object that gets the results from a StartShapeTestRay()
|
|
52
79
|
*
|
|
@@ -59,12 +86,31 @@ export class RaycastResult {
|
|
|
59
86
|
this.entityHandleArg = null;
|
|
60
87
|
this.surfaceNormalArg = new Vector3(0, 0, 0);
|
|
61
88
|
this.materialArg = 0;
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
89
|
+
this.result = ShapeTestStatus.NotReady;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
export class SynchronousRaycastResult extends RaycastResult {
|
|
93
|
+
constructor(handle) {
|
|
94
|
+
super(handle);
|
|
95
|
+
// if we're using a synchronous call then we want to instantly update our
|
|
96
|
+
// data, if its invalid then the caller can deal with it.
|
|
97
|
+
this.applyShapeTestResults();
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
export class AsynchronousRaycastResult extends RaycastResult {
|
|
101
|
+
/**
|
|
102
|
+
* waits until the shape test handle is valid and then sets the expected
|
|
103
|
+
* values on the RaycastResult
|
|
104
|
+
*/
|
|
105
|
+
async resolve(timeoutInMs = 1000) {
|
|
106
|
+
const timeout = GetGameTimer() + timeoutInMs;
|
|
107
|
+
// this has to be polled every frame or the engien will mark the field shape
|
|
108
|
+
// test handle as discarded
|
|
109
|
+
while (!this.HasResolved && !this.WasDiscarded) {
|
|
110
|
+
this.applyShapeTestResults();
|
|
111
|
+
if (timeout < GetGameTimer())
|
|
112
|
+
break;
|
|
113
|
+
await Delay(0);
|
|
114
|
+
}
|
|
69
115
|
}
|
|
70
116
|
}
|
package/client/World.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { Model, Prop } from './';
|
|
2
2
|
import { Blip } from './Blip';
|
|
3
3
|
import { Camera } from './Camera';
|
|
4
|
-
import { CameraTypes, CloudHat,
|
|
4
|
+
import { CameraTypes, CloudHat, IntersectFlags, MarkerType, PickupType, RopeType, Weather } from './enums';
|
|
5
5
|
import { Ped, Vehicle } from './models';
|
|
6
6
|
import type { BaseEntity } from './models/BaseEntity';
|
|
7
7
|
import { Pickup } from './Pickup';
|
|
8
|
-
import {
|
|
8
|
+
import { AsynchronousRaycastResult, SynchronousRaycastResult } from './Raycast';
|
|
9
9
|
import { Rope } from './Rope';
|
|
10
10
|
import { Color, Vector3 } from './utils';
|
|
11
11
|
/**
|
|
@@ -340,24 +340,37 @@ export declare abstract class World {
|
|
|
340
340
|
*/
|
|
341
341
|
static drawPoly(vertexA: Vector3, vertexB: Vector3, vertexC: Vector3, color: Color): void;
|
|
342
342
|
/**
|
|
343
|
-
* Cast
|
|
343
|
+
* Cast a ray from {@param start} to {@param end}.
|
|
344
344
|
*
|
|
345
|
-
* @param
|
|
346
|
-
* @param
|
|
347
|
-
* @param
|
|
345
|
+
* @param start Starting position of raycast.
|
|
346
|
+
* @param end Direction to cast a ray to.
|
|
347
|
+
* @param losFlags The entity type(s) that the raycast should intersect with
|
|
348
|
+
* defaults to {@enum IntersectFlags.All}
|
|
348
349
|
* @param options Possible entity types to detect.
|
|
349
350
|
* @param ignoreEntity An entity to ignore (usually player's Ped).
|
|
350
|
-
* @returns
|
|
351
|
+
* @returns {@see SynchronousRaycastResult} object.
|
|
352
|
+
*/
|
|
353
|
+
static expensiveRaycast(start: Vector3, end: Vector3, losFlags?: IntersectFlags, shapeTestOptions?: number, ignoreEntity?: BaseEntity): SynchronousRaycastResult;
|
|
354
|
+
/**
|
|
355
|
+
* Cast a ray from {@param start} to {@param end} and returns the first hit
|
|
356
|
+
* entity or coordinate .
|
|
357
|
+
*
|
|
358
|
+
* @param start starting position of raycast.
|
|
359
|
+
* @param end the ending position to raycast to.
|
|
360
|
+
* @param losFlags The entity type(s) that the raycast should intersect with defaults to {@enum IntersectFlags.All}
|
|
361
|
+
* @param shapeTestOptions shape test collision modifiers defaults to ignoring glass, see through, and no collided entities
|
|
362
|
+
* @param ignoreEntity An entity to ignore (usually player's Ped).
|
|
363
|
+
* @returns {@see AsynchronousRaycastResult} object that must be awaited to get its results.
|
|
351
364
|
*/
|
|
352
|
-
static raycast(
|
|
365
|
+
static raycast(start: Vector3, end: Vector3, losFlags?: IntersectFlags, shapeTestOptions?: number, ignoreEntity?: BaseEntity): AsynchronousRaycastResult;
|
|
353
366
|
/**
|
|
354
367
|
* Cast a ray from the local players camera until it hits an entity
|
|
355
368
|
*
|
|
356
369
|
* @param maxDistance Max distance to cast the ray.
|
|
357
|
-
* @param
|
|
358
|
-
* @returns
|
|
370
|
+
* @param flags Possible entity types to detect.
|
|
371
|
+
* @returns SynchronousRaycast object.
|
|
359
372
|
*/
|
|
360
|
-
static raycastPlayerCamera(maxDistance: number,
|
|
373
|
+
static raycastPlayerCamera(maxDistance: number, flags: IntersectFlags): SynchronousRaycastResult;
|
|
361
374
|
/**
|
|
362
375
|
* Gets the closest object of this model
|
|
363
376
|
*/
|
package/client/World.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { Model, Prop } from './';
|
|
2
2
|
import { Blip } from './Blip';
|
|
3
3
|
import { Camera } from './Camera';
|
|
4
|
-
import { CameraTypes, CloudHat, Weather, } from './enums';
|
|
4
|
+
import { CameraTypes, CloudHat, IntersectFlags, SHAPE_TEST_DEFAULT, Weather, } from './enums';
|
|
5
5
|
import { GameplayCamera } from './GameplayCamera';
|
|
6
6
|
import { VehicleHash } from './hashes';
|
|
7
7
|
import { Ped, Vehicle } from './models';
|
|
8
8
|
import { Pickup } from './Pickup';
|
|
9
|
-
import {
|
|
9
|
+
import { AsynchronousRaycastResult, SynchronousRaycastResult } from './Raycast';
|
|
10
10
|
import { Rope } from './Rope';
|
|
11
|
-
import { Maths,
|
|
11
|
+
import { Maths, Wait } from './utils';
|
|
12
12
|
/**
|
|
13
13
|
* Class with common world manipulations.
|
|
14
14
|
*
|
|
@@ -570,32 +570,47 @@ export class World {
|
|
|
570
570
|
static drawPoly(vertexA, vertexB, vertexC, color) {
|
|
571
571
|
DrawPoly(vertexA.x, vertexA.y, vertexA.z, vertexB.x, vertexB.y, vertexB.z, vertexC.x, vertexC.y, vertexC.z, color.r, color.g, color.b, color.a);
|
|
572
572
|
}
|
|
573
|
+
// TODO: Add a raycast option for every type.
|
|
573
574
|
/**
|
|
574
|
-
* Cast
|
|
575
|
+
* Cast a ray from {@param start} to {@param end}.
|
|
575
576
|
*
|
|
576
|
-
* @param
|
|
577
|
-
* @param
|
|
578
|
-
* @param
|
|
577
|
+
* @param start Starting position of raycast.
|
|
578
|
+
* @param end Direction to cast a ray to.
|
|
579
|
+
* @param losFlags The entity type(s) that the raycast should intersect with
|
|
580
|
+
* defaults to {@enum IntersectFlags.All}
|
|
579
581
|
* @param options Possible entity types to detect.
|
|
580
582
|
* @param ignoreEntity An entity to ignore (usually player's Ped).
|
|
581
|
-
* @returns
|
|
583
|
+
* @returns {@see SynchronousRaycastResult} object.
|
|
582
584
|
*/
|
|
583
|
-
static
|
|
584
|
-
|
|
585
|
-
|
|
585
|
+
static expensiveRaycast(start, end, losFlags = IntersectFlags.All, shapeTestOptions = SHAPE_TEST_DEFAULT, ignoreEntity) {
|
|
586
|
+
return new SynchronousRaycastResult(StartExpensiveSynchronousShapeTestLosProbe(start.x, start.y, start.z, end.x, end.y, end.z, losFlags, ignoreEntity?.Handle ?? 0, shapeTestOptions));
|
|
587
|
+
}
|
|
588
|
+
/**
|
|
589
|
+
* Cast a ray from {@param start} to {@param end} and returns the first hit
|
|
590
|
+
* entity or coordinate .
|
|
591
|
+
*
|
|
592
|
+
* @param start starting position of raycast.
|
|
593
|
+
* @param end the ending position to raycast to.
|
|
594
|
+
* @param losFlags The entity type(s) that the raycast should intersect with defaults to {@enum IntersectFlags.All}
|
|
595
|
+
* @param shapeTestOptions shape test collision modifiers defaults to ignoring glass, see through, and no collided entities
|
|
596
|
+
* @param ignoreEntity An entity to ignore (usually player's Ped).
|
|
597
|
+
* @returns {@see AsynchronousRaycastResult} object that must be awaited to get its results.
|
|
598
|
+
*/
|
|
599
|
+
static raycast(start, end, losFlags = IntersectFlags.All, shapeTestOptions = SHAPE_TEST_DEFAULT, ignoreEntity) {
|
|
600
|
+
return new AsynchronousRaycastResult(StartShapeTestLosProbe(start.x, start.y, start.z, end.x, end.y, end.z, losFlags, ignoreEntity?.Handle ?? 0, shapeTestOptions));
|
|
586
601
|
}
|
|
587
602
|
/**
|
|
588
603
|
* Cast a ray from the local players camera until it hits an entity
|
|
589
604
|
*
|
|
590
605
|
* @param maxDistance Max distance to cast the ray.
|
|
591
|
-
* @param
|
|
592
|
-
* @returns
|
|
606
|
+
* @param flags Possible entity types to detect.
|
|
607
|
+
* @returns SynchronousRaycast object.
|
|
593
608
|
*/
|
|
594
|
-
static raycastPlayerCamera(maxDistance,
|
|
609
|
+
static raycastPlayerCamera(maxDistance, flags) {
|
|
595
610
|
const camera = GameplayCamera.Position;
|
|
596
611
|
const direction = GameplayCamera.ForwardVector;
|
|
597
612
|
const destination = direction.multiply(maxDistance).add(camera);
|
|
598
|
-
return new
|
|
613
|
+
return new SynchronousRaycastResult(StartExpensiveSynchronousShapeTestLosProbe(camera.x, camera.y, camera.z, destination.x, destination.y, destination.z, flags, PlayerPedId(), 7));
|
|
599
614
|
}
|
|
600
615
|
/**
|
|
601
616
|
* Gets the closest object of this model
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* List of possible entity intersections. Used for raycasting.
|
|
3
|
+
*/
|
|
4
|
+
export declare enum IntersectFlags {
|
|
5
|
+
None = 0,
|
|
6
|
+
World = 1,
|
|
7
|
+
Vehicles = 2,
|
|
8
|
+
Ped = 4,
|
|
9
|
+
Ragdoll = 8,
|
|
10
|
+
Object = 16,
|
|
11
|
+
Pickup = 32,
|
|
12
|
+
River = 128,
|
|
13
|
+
Foliage = 256,
|
|
14
|
+
All = 511
|
|
15
|
+
}
|
|
16
|
+
export declare enum ShapeTestOptions {
|
|
17
|
+
None = 0,
|
|
18
|
+
IgnoreGlass = 1,
|
|
19
|
+
IgnoreSeeThrough = 2,
|
|
20
|
+
IgnoreNoCollision = 4
|
|
21
|
+
}
|
|
22
|
+
export declare enum ShapeTestStatus {
|
|
23
|
+
Discarded = 0,
|
|
24
|
+
NotReady = 1,
|
|
25
|
+
Ready = 2
|
|
26
|
+
}
|
|
27
|
+
export declare const SHAPE_TEST_DEFAULT: number;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* List of possible entity intersections. Used for raycasting.
|
|
3
|
+
*/
|
|
4
|
+
export var IntersectFlags;
|
|
5
|
+
(function (IntersectFlags) {
|
|
6
|
+
IntersectFlags[IntersectFlags["None"] = 0] = "None";
|
|
7
|
+
IntersectFlags[IntersectFlags["World"] = 1] = "World";
|
|
8
|
+
IntersectFlags[IntersectFlags["Vehicles"] = 2] = "Vehicles";
|
|
9
|
+
IntersectFlags[IntersectFlags["Ped"] = 4] = "Ped";
|
|
10
|
+
IntersectFlags[IntersectFlags["Ragdoll"] = 8] = "Ragdoll";
|
|
11
|
+
IntersectFlags[IntersectFlags["Object"] = 16] = "Object";
|
|
12
|
+
IntersectFlags[IntersectFlags["Pickup"] = 32] = "Pickup";
|
|
13
|
+
IntersectFlags[IntersectFlags["River"] = 128] = "River";
|
|
14
|
+
IntersectFlags[IntersectFlags["Foliage"] = 256] = "Foliage";
|
|
15
|
+
IntersectFlags[IntersectFlags["All"] = 511] = "All";
|
|
16
|
+
})(IntersectFlags || (IntersectFlags = {}));
|
|
17
|
+
export var ShapeTestOptions;
|
|
18
|
+
(function (ShapeTestOptions) {
|
|
19
|
+
ShapeTestOptions[ShapeTestOptions["None"] = 0] = "None";
|
|
20
|
+
ShapeTestOptions[ShapeTestOptions["IgnoreGlass"] = 1] = "IgnoreGlass";
|
|
21
|
+
ShapeTestOptions[ShapeTestOptions["IgnoreSeeThrough"] = 2] = "IgnoreSeeThrough";
|
|
22
|
+
ShapeTestOptions[ShapeTestOptions["IgnoreNoCollision"] = 4] = "IgnoreNoCollision";
|
|
23
|
+
})(ShapeTestOptions || (ShapeTestOptions = {}));
|
|
24
|
+
export var ShapeTestStatus;
|
|
25
|
+
(function (ShapeTestStatus) {
|
|
26
|
+
ShapeTestStatus[ShapeTestStatus["Discarded"] = 0] = "Discarded";
|
|
27
|
+
ShapeTestStatus[ShapeTestStatus["NotReady"] = 1] = "NotReady";
|
|
28
|
+
ShapeTestStatus[ShapeTestStatus["Ready"] = 2] = "Ready";
|
|
29
|
+
})(ShapeTestStatus || (ShapeTestStatus = {}));
|
|
30
|
+
export const SHAPE_TEST_DEFAULT = ShapeTestOptions.IgnoreGlass | ShapeTestOptions.IgnoreSeeThrough | ShapeTestOptions.IgnoreNoCollision;
|
package/client/enums/index.d.ts
CHANGED
|
@@ -20,7 +20,7 @@ export { HelmetType } from './HelmetType';
|
|
|
20
20
|
export { HudColor } from './HudColor';
|
|
21
21
|
export { HudComponent } from './HudComponent';
|
|
22
22
|
export { InputMode } from './InputMode';
|
|
23
|
-
export {
|
|
23
|
+
export { IntersectFlags, ShapeTestOptions, SHAPE_TEST_DEFAULT } from './RaycastEnums';
|
|
24
24
|
export { InvertAxis, InvertAxisFlags } from './InvertAxis';
|
|
25
25
|
export { Language } from './Language';
|
|
26
26
|
export { LeaveVehicleFlags } from './LeaveVehicleFlags';
|
package/client/enums/index.js
CHANGED
|
@@ -20,7 +20,7 @@ export { HelmetType } from './HelmetType';
|
|
|
20
20
|
export { HudColor } from './HudColor';
|
|
21
21
|
export { HudComponent } from './HudComponent';
|
|
22
22
|
export { InputMode } from './InputMode';
|
|
23
|
-
export {
|
|
23
|
+
export { IntersectFlags, ShapeTestOptions, SHAPE_TEST_DEFAULT } from './RaycastEnums';
|
|
24
24
|
export { InvertAxisFlags } from './InvertAxis';
|
|
25
25
|
export { Language } from './Language';
|
|
26
26
|
export { LeaveVehicleFlags } from './LeaveVehicleFlags';
|
package/client/index.d.ts
CHANGED
|
@@ -10,7 +10,7 @@ export { GameplayCamera } from './GameplayCamera';
|
|
|
10
10
|
export { ParticleEffect } from './ParticleEffect';
|
|
11
11
|
export { ParticleEffectAsset } from './ParticleEffectAsset';
|
|
12
12
|
export { Pickup } from './Pickup';
|
|
13
|
-
export {
|
|
13
|
+
export { AsynchronousRaycastResult, SynchronousRaycastResult } from './Raycast';
|
|
14
14
|
export { RelationshipGroup } from './RelationshipGroup';
|
|
15
15
|
export { Tasks } from './Tasks';
|
|
16
16
|
export { TaskSequence } from './TaskSequence';
|
package/client/index.js
CHANGED
|
@@ -10,7 +10,7 @@ export { GameplayCamera } from './GameplayCamera';
|
|
|
10
10
|
export { ParticleEffect } from './ParticleEffect';
|
|
11
11
|
export { ParticleEffectAsset } from './ParticleEffectAsset';
|
|
12
12
|
export { Pickup } from './Pickup';
|
|
13
|
-
export {
|
|
13
|
+
export { AsynchronousRaycastResult, SynchronousRaycastResult } from './Raycast';
|
|
14
14
|
export { RelationshipGroup } from './RelationshipGroup';
|
|
15
15
|
export { Tasks } from './Tasks';
|
|
16
16
|
export { TaskSequence } from './TaskSequence';
|
package/common/utils/Vector.d.ts
CHANGED
|
@@ -55,9 +55,6 @@ export declare class Vector {
|
|
|
55
55
|
y: number;
|
|
56
56
|
z?: number | undefined;
|
|
57
57
|
w?: number | undefined;
|
|
58
|
-
/**
|
|
59
|
-
* The type identifier for vectors.
|
|
60
|
-
*/
|
|
61
58
|
type: ClassTypes;
|
|
62
59
|
protected static create(x: number, y?: number): Vector2;
|
|
63
60
|
protected static create(x: number, y?: number, z?: number): Vector3;
|
|
@@ -144,6 +141,35 @@ export declare class Vector {
|
|
|
144
141
|
* @returns A new vector with divided components.
|
|
145
142
|
*/
|
|
146
143
|
static divide<T extends VectorType, U extends VectorLike>(this: T, a: U, b: VectorLike | number): U;
|
|
144
|
+
/**
|
|
145
|
+
* Performs an operation between a vector and either another vector or scalar value converting the vector into absolute values.
|
|
146
|
+
* @param a - The first vector.
|
|
147
|
+
* @param b - The second vector or scalar value.
|
|
148
|
+
* @param operator - The function defining the operation to perform.
|
|
149
|
+
* @returns A new vector resulting from the operation.
|
|
150
|
+
*/
|
|
151
|
+
private static operateAbsolute;
|
|
152
|
+
/**
|
|
153
|
+
* Subtracts one vector from another or subtracts a scalar value from a vector.
|
|
154
|
+
* @param a - The vector.
|
|
155
|
+
* @param b - The second vector or scalar value.
|
|
156
|
+
* @returns A new vector with subtracted components.
|
|
157
|
+
*/
|
|
158
|
+
static subtractAbsolute<T extends VectorType, U extends VectorLike>(this: T, a: U, b: VectorLike | number): U;
|
|
159
|
+
/**
|
|
160
|
+
* Multiplies two vectors by their components, or multiplies a vector by a scalar value.
|
|
161
|
+
* @param a - The vector.
|
|
162
|
+
* @param b - The second vector or scalar value.
|
|
163
|
+
* @returns A new vector with multiplied components.
|
|
164
|
+
*/
|
|
165
|
+
static multiplyAbsolute<T extends VectorType, U extends VectorLike>(this: T, a: U, b: VectorLike | number): U;
|
|
166
|
+
/**
|
|
167
|
+
* Divides two vectors by their components, or divides a vector by a scalar value
|
|
168
|
+
* @param a - The vector.
|
|
169
|
+
* @param b - The second vector or scalar vector.
|
|
170
|
+
* @returns A new vector with divided components.
|
|
171
|
+
*/
|
|
172
|
+
static divideAbsolute<T extends VectorType, U extends VectorLike>(this: T, a: U, b: VectorLike | number): U;
|
|
147
173
|
/**
|
|
148
174
|
* Calculates the dot product of two vectors.
|
|
149
175
|
* @param a - The first vector.
|
|
@@ -246,6 +272,18 @@ export declare class Vector {
|
|
|
246
272
|
* @see Vector.divide
|
|
247
273
|
*/
|
|
248
274
|
divide(v: VectorLike | number): this;
|
|
275
|
+
/**
|
|
276
|
+
* @see Vector.subtractAbsolute
|
|
277
|
+
*/
|
|
278
|
+
subtractAbsolute(v: VectorLike): this;
|
|
279
|
+
/**
|
|
280
|
+
* @see Vector.multiply
|
|
281
|
+
*/
|
|
282
|
+
multiplyAbsolute(v: VectorLike | number): this;
|
|
283
|
+
/**
|
|
284
|
+
* @see Vector.divide
|
|
285
|
+
*/
|
|
286
|
+
divideAbsolute(v: VectorLike | number): this;
|
|
249
287
|
/**
|
|
250
288
|
* Converts the vector to an array of its components.
|
|
251
289
|
*/
|
|
@@ -296,6 +334,10 @@ export declare class Vector3 extends Vector implements Vec3 {
|
|
|
296
334
|
* @see Vector.crossProduct
|
|
297
335
|
*/
|
|
298
336
|
crossProduct(v: Vec3 | Vec4): Vec3 | Vec4;
|
|
337
|
+
/**
|
|
338
|
+
* @returns the x and y values as Vec2
|
|
339
|
+
*/
|
|
340
|
+
toVec2(): Vector2;
|
|
299
341
|
}
|
|
300
342
|
/**
|
|
301
343
|
* Represents a 4-dimensional vector.
|
|
@@ -325,5 +367,13 @@ export declare class Vector4 extends Vector {
|
|
|
325
367
|
* @see Vector.crossProduct
|
|
326
368
|
*/
|
|
327
369
|
crossProduct(v: Vec3 | Vec4): Vec3 | Vec4;
|
|
370
|
+
/**
|
|
371
|
+
* @returns the x and y values as Vec2
|
|
372
|
+
*/
|
|
373
|
+
toVec2(): Vector2;
|
|
374
|
+
/**
|
|
375
|
+
* @returns the x and y values as Vec3
|
|
376
|
+
*/
|
|
377
|
+
toVec3(): Vector3;
|
|
328
378
|
}
|
|
329
379
|
export {};
|
package/common/utils/Vector.js
CHANGED
|
@@ -145,6 +145,51 @@ export class Vector {
|
|
|
145
145
|
static divide(a, b) {
|
|
146
146
|
return this.operate(a, b, (x, y) => x / y);
|
|
147
147
|
}
|
|
148
|
+
/**
|
|
149
|
+
* Performs an operation between a vector and either another vector or scalar value converting the vector into absolute values.
|
|
150
|
+
* @param a - The first vector.
|
|
151
|
+
* @param b - The second vector or scalar value.
|
|
152
|
+
* @param operator - The function defining the operation to perform.
|
|
153
|
+
* @returns A new vector resulting from the operation.
|
|
154
|
+
*/
|
|
155
|
+
static operateAbsolute(a, b, operator) {
|
|
156
|
+
let { x, y, z, w } = a;
|
|
157
|
+
const isNumber = typeof b === 'number';
|
|
158
|
+
x = operator(Math.abs(x), isNumber ? b : Math.abs(b.x ?? 0));
|
|
159
|
+
y = operator(Math.abs(y), isNumber ? b : Math.abs(b.y ?? 0));
|
|
160
|
+
if (z)
|
|
161
|
+
z = operator(Math.abs(z), isNumber ? b : Math.abs(b.z ?? 0));
|
|
162
|
+
if (w)
|
|
163
|
+
w = operator(Math.abs(w), isNumber ? b : Math.abs(b.w ?? 0));
|
|
164
|
+
return this.create(x, y, z, w);
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* Subtracts one vector from another or subtracts a scalar value from a vector.
|
|
168
|
+
* @param a - The vector.
|
|
169
|
+
* @param b - The second vector or scalar value.
|
|
170
|
+
* @returns A new vector with subtracted components.
|
|
171
|
+
*/
|
|
172
|
+
static subtractAbsolute(a, b) {
|
|
173
|
+
return this.operateAbsolute(a, b, (x, y) => x - y);
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Multiplies two vectors by their components, or multiplies a vector by a scalar value.
|
|
177
|
+
* @param a - The vector.
|
|
178
|
+
* @param b - The second vector or scalar value.
|
|
179
|
+
* @returns A new vector with multiplied components.
|
|
180
|
+
*/
|
|
181
|
+
static multiplyAbsolute(a, b) {
|
|
182
|
+
return this.operateAbsolute(a, b, (x, y) => x * y);
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* Divides two vectors by their components, or divides a vector by a scalar value
|
|
186
|
+
* @param a - The vector.
|
|
187
|
+
* @param b - The second vector or scalar vector.
|
|
188
|
+
* @returns A new vector with divided components.
|
|
189
|
+
*/
|
|
190
|
+
static divideAbsolute(a, b) {
|
|
191
|
+
return this.operateAbsolute(a, b, (x, y) => x / y);
|
|
192
|
+
}
|
|
148
193
|
/**
|
|
149
194
|
* Calculates the dot product of two vectors.
|
|
150
195
|
* @param a - The first vector.
|
|
@@ -244,9 +289,8 @@ export class Vector {
|
|
|
244
289
|
this.y = y;
|
|
245
290
|
this.z = z;
|
|
246
291
|
this.w = w;
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
*/
|
|
292
|
+
// DO NOT USE, ONLY EXPOSED BECAUSE TS IS TRASH, THIS TYPE IS NOT GUARANTEED
|
|
293
|
+
// TO EXIST
|
|
250
294
|
this.type = ClassTypes.Vector2;
|
|
251
295
|
}
|
|
252
296
|
*[Symbol.iterator]() {
|
|
@@ -333,6 +377,24 @@ export class Vector {
|
|
|
333
377
|
divide(v) {
|
|
334
378
|
return Vector.divide(this, v);
|
|
335
379
|
}
|
|
380
|
+
/**
|
|
381
|
+
* @see Vector.subtractAbsolute
|
|
382
|
+
*/
|
|
383
|
+
subtractAbsolute(v) {
|
|
384
|
+
return Vector.subtractAbsolute(this, v);
|
|
385
|
+
}
|
|
386
|
+
/**
|
|
387
|
+
* @see Vector.multiply
|
|
388
|
+
*/
|
|
389
|
+
multiplyAbsolute(v) {
|
|
390
|
+
return Vector.multiplyAbsolute(this, v);
|
|
391
|
+
}
|
|
392
|
+
/**
|
|
393
|
+
* @see Vector.divide
|
|
394
|
+
*/
|
|
395
|
+
divideAbsolute(v) {
|
|
396
|
+
return Vector.divideAbsolute(this, v);
|
|
397
|
+
}
|
|
336
398
|
/**
|
|
337
399
|
* Converts the vector to an array of its components.
|
|
338
400
|
*/
|
|
@@ -371,6 +433,8 @@ export class Vector2 extends Vector {
|
|
|
371
433
|
*/
|
|
372
434
|
constructor(x, y = x) {
|
|
373
435
|
super(2, x, y);
|
|
436
|
+
// DO NOT USE, ONLY EXPOSED BECAUSE TS IS TRASH, THIS TYPE IS NOT GUARANTEED
|
|
437
|
+
// TO EXIST, CHANGING IT WILL BREAK STUFF
|
|
374
438
|
this.type = ClassTypes.Vector2;
|
|
375
439
|
}
|
|
376
440
|
}
|
|
@@ -387,6 +451,8 @@ export class Vector3 extends Vector {
|
|
|
387
451
|
*/
|
|
388
452
|
constructor(x, y = x, z = y) {
|
|
389
453
|
super(3, x, y, z);
|
|
454
|
+
// DO NOT USE, ONLY EXPOSED BECAUSE TS IS TRASH, THIS TYPE IS NOT GUARANTEED
|
|
455
|
+
// TO EXIST, CHANGING IT WILL BREAK STUFF
|
|
390
456
|
this.type = ClassTypes.Vector3;
|
|
391
457
|
this.z = z;
|
|
392
458
|
}
|
|
@@ -402,6 +468,12 @@ export class Vector3 extends Vector {
|
|
|
402
468
|
crossProduct(v) {
|
|
403
469
|
return Vector.crossProduct(this, v);
|
|
404
470
|
}
|
|
471
|
+
/**
|
|
472
|
+
* @returns the x and y values as Vec2
|
|
473
|
+
*/
|
|
474
|
+
toVec2() {
|
|
475
|
+
return new Vector2(this.x, this.y);
|
|
476
|
+
}
|
|
405
477
|
}
|
|
406
478
|
Vector3.Zero = new Vector3(0, 0, 0);
|
|
407
479
|
/**
|
|
@@ -417,6 +489,8 @@ export class Vector4 extends Vector {
|
|
|
417
489
|
*/
|
|
418
490
|
constructor(x, y = x, z = y, w = z) {
|
|
419
491
|
super(4, x, y, z, w);
|
|
492
|
+
// DO NOT USE, ONLY EXPOSED BECAUSE TS IS TRASH, THIS TYPE IS NOT GUARANTEED
|
|
493
|
+
// TO EXIST, CHANGING IT WILL BREAK STUFF
|
|
420
494
|
this.type = ClassTypes.Vector4;
|
|
421
495
|
this.z = z;
|
|
422
496
|
this.w = w;
|
|
@@ -439,5 +513,17 @@ export class Vector4 extends Vector {
|
|
|
439
513
|
crossProduct(v) {
|
|
440
514
|
return Vector.crossProduct(this, v);
|
|
441
515
|
}
|
|
516
|
+
/**
|
|
517
|
+
* @returns the x and y values as Vec2
|
|
518
|
+
*/
|
|
519
|
+
toVec2() {
|
|
520
|
+
return new Vector2(this.x, this.y);
|
|
521
|
+
}
|
|
522
|
+
/**
|
|
523
|
+
* @returns the x and y values as Vec3
|
|
524
|
+
*/
|
|
525
|
+
toVec3() {
|
|
526
|
+
return new Vector3(this.x, this.y, this.z);
|
|
527
|
+
}
|
|
442
528
|
}
|
|
443
529
|
Vector4.Zero = new Vector4(0, 0, 0, 0);
|
package/package.json
CHANGED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* List of possible entity intersections. Used for raycasting.
|
|
3
|
-
*/
|
|
4
|
-
export declare enum IntersectOptions {
|
|
5
|
-
Everything = -1,
|
|
6
|
-
None = 0,
|
|
7
|
-
World = 1,
|
|
8
|
-
Vehicles = 2,
|
|
9
|
-
PedsSimpleCollision = 4,
|
|
10
|
-
Peds = 8,
|
|
11
|
-
Objects = 16,
|
|
12
|
-
Water = 32,
|
|
13
|
-
Unk3 = 128,
|
|
14
|
-
Foliage = 256
|
|
15
|
-
}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* List of possible entity intersections. Used for raycasting.
|
|
3
|
-
*/
|
|
4
|
-
export var IntersectOptions;
|
|
5
|
-
(function (IntersectOptions) {
|
|
6
|
-
IntersectOptions[IntersectOptions["Everything"] = -1] = "Everything";
|
|
7
|
-
IntersectOptions[IntersectOptions["None"] = 0] = "None";
|
|
8
|
-
IntersectOptions[IntersectOptions["World"] = 1] = "World";
|
|
9
|
-
IntersectOptions[IntersectOptions["Vehicles"] = 2] = "Vehicles";
|
|
10
|
-
IntersectOptions[IntersectOptions["PedsSimpleCollision"] = 4] = "PedsSimpleCollision";
|
|
11
|
-
IntersectOptions[IntersectOptions["Peds"] = 8] = "Peds";
|
|
12
|
-
IntersectOptions[IntersectOptions["Objects"] = 16] = "Objects";
|
|
13
|
-
IntersectOptions[IntersectOptions["Water"] = 32] = "Water";
|
|
14
|
-
IntersectOptions[IntersectOptions["Unk3"] = 128] = "Unk3";
|
|
15
|
-
IntersectOptions[IntersectOptions["Foliage"] = 256] = "Foliage";
|
|
16
|
-
})(IntersectOptions || (IntersectOptions = {}));
|