@galacean/engine-design 2.0.0-alpha.5 → 2.0.0-alpha.50

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@galacean/engine-design",
3
- "version": "2.0.0-alpha.5",
3
+ "version": "2.0.0-alpha.50",
4
4
  "publishConfig": {
5
5
  "access": "public",
6
6
  "registry": "https://registry.npmjs.org"
@@ -17,7 +17,7 @@
17
17
  ],
18
18
  "types": "types/index.d.ts",
19
19
  "dependencies": {
20
- "@galacean/engine-math": "2.0.0-alpha.5"
20
+ "@galacean/engine-math": "2.0.0-alpha.50"
21
21
  },
22
22
  "scripts": {
23
23
  "b:types": "tsc"
package/types/index.d.ts CHANGED
@@ -2,5 +2,5 @@ export type { IClone } from "./IClone";
2
2
  export * from "./input/index";
3
3
  export * from "./physics/index";
4
4
  export * from "./renderingHardwareInterface/index";
5
- export * from "./shader-lab/index";
5
+ export * from "./shader-compiler/index";
6
6
  export * from "./xr/index";
@@ -2,13 +2,16 @@
2
2
  * Interface of collision.
3
3
  */
4
4
  export interface ICollision {
5
- /** The unique id of the first collider. */
5
+ /** The unique ID of the first shape in the contact pair. */
6
6
  shape0Id: number;
7
- /** The unique id of the second collider. */
7
+ /** The unique ID of the second shape in the contact pair. */
8
8
  shape1Id: number;
9
9
  /** Count of contact points. */
10
10
  contactCount: number;
11
- /** Get contact points. */
11
+ /**
12
+ * Get contact points.
13
+ * @remarks Contact normals and impulses must point from the second shape in the pair to the first.
14
+ */
12
15
  getContacts(): VectorContactPairPoint;
13
16
  }
14
17
  interface VectorContactPairPoint {
@@ -98,20 +98,16 @@ export interface IDynamicCollider extends ICollider {
98
98
  * @param value - Number of position iterations the solver should perform for this body
99
99
  */
100
100
  setSolverIterations(value: number): void;
101
- /**
102
- * Sets the colliders' collision detection mode.
103
- * @param value - rigid body flag
104
- */
105
- setCollisionDetectionMode(value: number): void;
106
101
  /**
107
102
  * Whether the collider is affected by gravity.
108
103
  */
109
104
  setUseGravity(value: boolean): void;
110
105
  /**
111
- * Controls whether physics affects the dynamic collider.
112
- * @param value - is or not
106
+ * Sets the kinematic state and requested collision detection mode in one native transition.
107
+ * @param isKinematic - Whether the dynamic collider is kinematic
108
+ * @param collisionDetectionMode - The requested collision detection mode
113
109
  */
114
- setIsKinematic(value: boolean): void;
110
+ setMotionState(isKinematic: boolean, collisionDetectionMode: number): void;
115
111
  /**
116
112
  * Raises or clears a particular rigid dynamic lock flag.
117
113
  * @param flags - the flag to raise(set) or clear
@@ -122,6 +118,12 @@ export interface IDynamicCollider extends ICollider {
122
118
  * @param force - The force make the collider move
123
119
  */
124
120
  addForce(force: Vector3): void;
121
+ /**
122
+ * Apply a force to the dynamic collider at a world-space position.
123
+ * @param force - The force make the collider move
124
+ * @param position - The world-space position where the force is applied
125
+ */
126
+ addForceAtPosition(force: Vector3, position: Vector3): void;
125
127
  /**
126
128
  * Apply a torque to the dynamic collider.
127
129
  * @param torque - The force make the collider rotate
@@ -8,7 +8,6 @@ import { IPhysicsScene } from "./IPhysicsScene";
8
8
  import { IStaticCollider } from "./IStaticCollider";
9
9
  import { IFixedJoint, IHingeJoint, ISpringJoint } from "./joints";
10
10
  import { IBoxColliderShape, ICapsuleColliderShape, IMeshColliderShape, IPlaneColliderShape, ISphereColliderShape } from "./shape";
11
- import { ICollision } from "./ICollision";
12
11
  /**
13
12
  * The interface of physics creation.
14
13
  */
@@ -25,14 +24,8 @@ export interface IPhysics {
25
24
  /**
26
25
  * Create physics scene.
27
26
  * @param physicsManager - The physics manager
28
- * @param onContactEnter - Function called when contact begin
29
- * @param onContactExit - Function called when contact end
30
- * @param onContactStay - Function called when contact stay
31
- * @param onTriggerEnter - Function called when trigger begin
32
- * @param onTriggerExit - Function called when trigger end
33
- * @param onTriggerStay - Function called when trigger stay
34
- */
35
- createPhysicsScene(physicsManager: IPhysicsManager, onContactEnter?: (collision: ICollision) => void, onContactExit?: (collision: ICollision) => void, onContactStay?: (collision: ICollision) => void, onTriggerEnter?: (obj1: number, obj2: number) => void, onTriggerExit?: (obj1: number, obj2: number) => void, onTriggerStay?: (obj1: number, obj2: number) => void): IPhysicsScene;
27
+ */
28
+ createPhysicsScene(physicsManager: IPhysicsManager): IPhysicsScene;
36
29
  /**
37
30
  * Create dynamic collider.
38
31
  * @param position - The global position
@@ -0,0 +1,25 @@
1
+ import { ICollision } from "./ICollision";
2
+ /**
3
+ * A buffered contact event from the physics backend.
4
+ */
5
+ export interface IContactEvent extends ICollision {
6
+ /** 0 = Enter, 1 = Stay, 2 = Exit */
7
+ state: number;
8
+ }
9
+ /**
10
+ * A buffered trigger event from the physics backend.
11
+ */
12
+ export interface ITriggerEvent {
13
+ index1: number;
14
+ index2: number;
15
+ /** The state snapshot for dispatch. 0 = Enter, 1 = Stay, 2 = Exit */
16
+ dispatchState: number;
17
+ }
18
+ /**
19
+ * Physics events returned by IPhysicsScene.updateEvents().
20
+ */
21
+ export interface IPhysicsEvents {
22
+ contactEvents: ReadonlyArray<IContactEvent>;
23
+ contactEventCount: number;
24
+ triggerEvents: ReadonlyArray<ITriggerEvent>;
25
+ }
@@ -1,6 +1,7 @@
1
- import { Quaternion, Ray, Vector3 } from "@galacean/engine-math";
1
+ import { Quaternion, Vector3 } from "@galacean/engine-math";
2
2
  import { ICharacterController } from "./ICharacterController";
3
3
  import { ICollider } from "./ICollider";
4
+ import { IPhysicsEvents } from "./IPhysicsEvents";
4
5
  /**
5
6
  * Interface for physics manager.
6
7
  */
@@ -35,15 +36,26 @@ export interface IPhysicsScene {
35
36
  * @param elapsedTime - Step time of update.
36
37
  */
37
38
  update(elapsedTime: number): void;
39
+ /**
40
+ * Enable contact event delivery.
41
+ * @param enabled - Whether collision contact events should be delivered for dispatch.
42
+ */
43
+ setContactEventEnabled(enabled: boolean): void;
44
+ /**
45
+ * Collect buffered collision and trigger events.
46
+ * Must be called after update() and after syncing transforms back from physics.
47
+ */
48
+ updateEvents(): IPhysicsEvents;
38
49
  /**
39
50
  * Casts a ray through the Scene and returns the first hit.
40
- * @param ray - The ray
51
+ * @param origin - The origin of the ray
52
+ * @param direction - The direction of the ray, which must be normalized
41
53
  * @param distance - The max distance the ray should check
42
54
  * @param onRaycast - The raycast result callback which pre filter result
43
55
  * @param outHitResult - If true is returned, outHitResult will contain more detailed collision information
44
56
  * @returns Returns True if the ray intersects with a collider, otherwise false
45
57
  */
46
- raycast(ray: Ray, distance: number, onRaycast: (obj: number) => boolean, outHitResult?: (shapeUniqueID: number, distance: number, point: Vector3, normal: Vector3) => void): boolean;
58
+ raycast(origin: Vector3, direction: Vector3, distance: number, onRaycast: (obj: number) => boolean, outHitResult?: (shapeUniqueID: number, distance: number, point: Vector3, normal: Vector3) => void): boolean;
47
59
  /**
48
60
  * Casts a box through the scene and returns true if there is any hit.
49
61
  */
@@ -71,6 +83,10 @@ export interface IPhysicsScene {
71
83
  * Returns an array of shape unique IDs.
72
84
  */
73
85
  overlapCapsuleAll(center: Vector3, radius: number, height: number, orientation: Quaternion, onOverlap: (obj: number) => boolean): number[];
86
+ /**
87
+ * Trim internal object pools after a GC cycle.
88
+ */
89
+ gc(): void;
74
90
  /**
75
91
  * Destroy the physics scene.
76
92
  */
@@ -7,5 +7,6 @@ export type { IPhysicsScene } from "./IPhysicsScene";
7
7
  export type { IPhysicsManager } from "./IPhysicsManager";
8
8
  export type { IStaticCollider } from "./IStaticCollider";
9
9
  export type { ICollision } from "./ICollision";
10
+ export type { IContactEvent, ITriggerEvent, IPhysicsEvents } from "./IPhysicsEvents";
10
11
  export * from "./joints/index";
11
12
  export * from "./shape/index";
@@ -7,7 +7,7 @@ export interface IJoint {
7
7
  /**
8
8
  * The connected collider.
9
9
  */
10
- setConnectedCollider(value: ICollider): void;
10
+ setConnectedCollider(value: ICollider | null | undefined): void;
11
11
  /**
12
12
  * The connected anchor position.
13
13
  * @remarks If connectedCollider is set, this anchor is relative offset, or the anchor is world position.
@@ -2,5 +2,6 @@
2
2
  * Hardware graphics API renderer.
3
3
  */
4
4
  export interface IHardwareRenderer {
5
+ readonly maxUniformBlockSize: number;
5
6
  [key: string]: any;
6
7
  }
@@ -0,0 +1,50 @@
1
+ /**
2
+ * #ifdef MACRO
3
+ */
4
+ export interface DefinedCondition {
5
+ t: "def";
6
+ m: string;
7
+ }
8
+ /**
9
+ * #ifndef MACRO
10
+ */
11
+ export interface NotDefinedCondition {
12
+ t: "ndef";
13
+ m: string;
14
+ }
15
+ /**
16
+ * #if MACRO op value (e.g., SCENE_FOG_MODE > 0)
17
+ */
18
+ export interface CompareCondition {
19
+ t: "cmp";
20
+ m: string;
21
+ op: string;
22
+ v: number;
23
+ }
24
+ export interface AndCondition {
25
+ t: "and";
26
+ l: Condition;
27
+ r: Condition;
28
+ }
29
+ export interface OrCondition {
30
+ t: "or";
31
+ l: Condition;
32
+ r: Condition;
33
+ }
34
+ export interface NotCondition {
35
+ t: "not";
36
+ c: Condition;
37
+ }
38
+ /**
39
+ * Constant boolean produced when numeric literals resolve statically
40
+ * (e.g. #define FOO 3 → #if 3 == 3 → always true)
41
+ */
42
+ export interface BoolCondition {
43
+ t: "bool";
44
+ v: boolean;
45
+ }
46
+ export type Condition = DefinedCondition | NotDefinedCondition | CompareCondition | AndCondition | OrCondition | NotCondition | BoolCondition;
47
+ /**
48
+ * Preprocessor instruction tuple: `[directive, ...operands]`
49
+ */
50
+ export type ShaderInstruction = readonly [number, ...(string | number | string[] | Condition)[]];
@@ -0,0 +1,22 @@
1
+ import type { ShaderInstruction } from "./ICondition";
2
+ export interface IPrecompiledShader {
3
+ name: string;
4
+ platformTarget: number;
5
+ subShaders: IPrecompiledSubShader[];
6
+ }
7
+ export interface IPrecompiledSubShader {
8
+ name: string;
9
+ tags?: Record<string, number | string | boolean>;
10
+ passes: IPrecompiledPass[];
11
+ }
12
+ export interface IPrecompiledPass {
13
+ name: string;
14
+ isUsePass: boolean;
15
+ tags?: Record<string, number | string | boolean>;
16
+ renderStates: {
17
+ constantMap: Record<string, number | string | boolean | number[]>;
18
+ variableMap: Record<string, string>;
19
+ };
20
+ vertexShaderInstructions?: ShaderInstruction[];
21
+ fragmentShaderInstructions?: ShaderInstruction[];
22
+ }
@@ -0,0 +1,25 @@
1
+ import { IPrecompiledShader } from "./IPrecompiledShader";
2
+ import { IShaderProgramSource } from "./IShaderProgramSource";
3
+ import { IShaderSource } from "./shaderSource/IShaderSource";
4
+ /**
5
+ * Shader compiler interface.
6
+ */
7
+ export interface IShaderCompiler {
8
+ /**
9
+ * @internal
10
+ * Parse shader source code to get the source structure of shader.
11
+ */
12
+ _parseShaderSource(sourceCode: string): IShaderSource;
13
+ /**
14
+ * @internal
15
+ * Parse shader pass source code.
16
+ * @param basePathForIncludeKey - The base path to resolve the relative path of `#include` directives.
17
+ * Must follow the specifications of [URL.origin](https://developer.mozilla.org/en-US/docs/Web/API/URL/origin),
18
+ * like: `shaders://root/`.
19
+ */
20
+ _parseShaderPass(shaderPassSource: string, vertexEntry: string, fragmentEntry: string, backend: any, basePathForIncludeKey: string): IShaderProgramSource | undefined;
21
+ /**
22
+ * @internal
23
+ */
24
+ _precompile(sourceCode: string, platformTarget: any, basePathForIncludeKey: string): IPrecompiledShader;
25
+ }
@@ -0,0 +1,7 @@
1
+ import type { ShaderInstruction } from "./ICondition";
2
+ export interface IShaderProgramSource {
3
+ vertex: string;
4
+ fragment: string;
5
+ vertexShaderInstructions?: ShaderInstruction[];
6
+ fragmentShaderInstructions?: ShaderInstruction[];
7
+ }
@@ -1,4 +1,6 @@
1
- export type { IShaderLab } from "./IShaderLab";
1
+ export type { IShaderCompiler } from "./IShaderCompiler";
2
+ export type { Condition, DefinedCondition, NotDefinedCondition, CompareCondition, BoolCondition, ShaderInstruction } from "./ICondition";
3
+ export type { IPrecompiledShader, IPrecompiledSubShader, IPrecompiledPass } from "./IPrecompiledShader";
2
4
  export type { IShaderProgramSource as IShaderInfo } from "./IShaderProgramSource";
3
5
  export { IRenderStates } from "./shaderSource/IRenderStates";
4
6
  export { IShaderPassSource } from "./shaderSource/IShaderPassSource";
@@ -6,7 +6,7 @@ export interface IShaderPassSource {
6
6
  isUsePass: boolean;
7
7
  tags?: Record<string, number | string | boolean>;
8
8
  renderStates: IRenderStates;
9
- /** ShaderLab code source. */
9
+ /** Shader source code. */
10
10
  contents: string;
11
11
  vertexEntry: string;
12
12
  fragmentEntry: string;
@@ -20,7 +20,7 @@ export interface IXRDevice {
20
20
  * @param engine - The engine.
21
21
  * @param type - The type of the feature.
22
22
  */
23
- createPlatformFeature(type: number, ...args: any[]): IXRPlatformFeature;
23
+ createPlatformFeature(type: number, ...args: any[]): IXRPlatformFeature | null;
24
24
  /**
25
25
  * Request a session.
26
26
  * @param engine - The engine
@@ -16,11 +16,11 @@ export interface IXRSession {
16
16
  /**
17
17
  * Returns the current frame rate.
18
18
  */
19
- get frameRate(): number;
19
+ get frameRate(): number | undefined;
20
20
  /**
21
21
  * Returns the frame rate supported by the device.
22
22
  */
23
- get supportedFrameRates(): Float32Array;
23
+ get supportedFrameRates(): Float32Array | undefined;
24
24
  /**
25
25
  * Returns the device's default main framebuffer.
26
26
  */
@@ -41,7 +41,7 @@ export interface IXRSession {
41
41
  /**
42
42
  * Return fixed foveation of camera.
43
43
  */
44
- getFixedFoveation(): number;
44
+ getFixedFoveation(): number | undefined;
45
45
  /**
46
46
  * Add event listener for XR session.
47
47
  */
@@ -1,22 +0,0 @@
1
- import { IShaderProgramSource } from "./IShaderProgramSource";
2
- import { IShaderSource } from "./shaderSource/IShaderSource";
3
- /**
4
- * Shader lab interface.
5
- */
6
- export interface IShaderLab {
7
- /**
8
- * @internal
9
- * Parse shader source code to get the source structure of shader.
10
- */
11
- _parseShaderSource(sourceCode: string): IShaderSource;
12
- /**
13
- * @internal
14
- * Parse shader pass source code.
15
- * @param basePathForIncludeKey the base path to resolve the relative path of `#include` directive. Must follow the specifications of [URL.origin](https://developer.mozilla.org/en-US/docs/Web/API/URL/origin), like: `shaders://root/`
16
- */
17
- _parseShaderPass(shaderPassSource: string, vertexEntry: string, fragmentEntry: string, backend: any, basePathForIncludeKey: string): IShaderProgramSource;
18
- _parseMacros(context: string, macros: Array<{
19
- name: string;
20
- value: string;
21
- }>): string;
22
- }
@@ -1,4 +0,0 @@
1
- export interface IShaderProgramSource {
2
- vertex: string;
3
- fragment: string;
4
- }