Skip to content

Updated types to match native code #336

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 24 additions & 13 deletions components/Types/ViroUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,15 @@ export type ViroRotation = [
number // z position
];

/**
* 3D Vector, stored as [x, y, z].
*/
export type Viro3DVector = [
number, // x component
number, // y component
number // z component
];

/**
* The scale of the container in 3D space, specified as [x,y,z]. A scale of
* 1 represents the current size of the container. A scale value of < 1
Expand Down Expand Up @@ -98,19 +107,18 @@ export type ViroPhysicsBody = {
* If an array of forces is provided, the corresponding net force will be applied.
* Force units are in newtons.
*/
force?: number[];
force?: ViroForce[];
/**
* A single torque vector or an array of torque vectors applied to the physics body.
* If an array of torque is provided, the corresponding net torque will be applied.
* A single 3D torque vector applied to the physics body.
* Torque units are in newton meters.
*/
torque?: number[];
torque?: ViroTorque;
/**
* Used to directly move an object without applying a force.
* Units are m/s. Doing so will override any forces that are already
* applied on this physics body.
*/
velocity?: number[];
velocity?: Viro3DVector;
};

export type ViroPhysicsBodyType = "Dynamic" | "Kinematic" | "Static";
Expand All @@ -123,13 +131,12 @@ export type ViroPhysicsBodyShape = {
export type ViroPhysicsBodyShapeType = "Box" | "Sphere" | "Compound";

/**
* A single force vector or an array of force vectors applied to the physics body.
* If an array of forces is provided, the corresponding net force will be applied.
* A single force vector applied to the physics body.
* Force units are in newtons.
*/
export type ViroForce = {
value: Array<number>;
position: Array<number>;
value: Viro3DVector;
position: Viro3DPoint;
};

export type ViroSource = ImageSourcePropType;
Expand All @@ -145,15 +152,19 @@ export type ViroSoundRoom = {
};

export type ViroPhysicsWorld = {
gravity: number;
gravity: Viro3DVector;
drawBounds?: boolean;
};

export type ViroRay = any;
export type ViroRay = Viro3DVector;

export type ViroTorque = any;
/**
* A single 3D torque vector applied to the physics body.
* Torque units are in newton meters.
*/
export type ViroTorque = Viro3DVector;

export type ViroVelocity = any;
export type ViroVelocity = Viro3DVector;

export type Viro2DPoint = [number, number];

Expand Down
6 changes: 3 additions & 3 deletions components/ViroBase.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -157,11 +157,11 @@ export class ViroBase<T> extends React.Component<ViroBaseProps & T> {
);
};

applyImpulse = (force: ViroForce, position: Viro3DPoint) => {
applyImpulse = (force: ViroForce) => {
NativeModules.VRTNodeModule.applyImpulse(
findNodeHandle(this),
force,
position
force.value,
force.position
);
};

Expand Down
4 changes: 2 additions & 2 deletions components/ViroButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ export class ViroButton extends React.Component<Props, State> {
buttonType: ViroButtonStateTypes.BTN_TYPE_NORMAL,
};

applyImpulse = (force: ViroForce, atPosition: Viro3DPoint) => {
this._component?.applyImpulse(force, atPosition);
applyImpulse = (force: ViroForce) => {
this._component?.applyImpulse(force);
};

applyTorqueImpulse = (torque: ViroTorque) => {
Expand Down
36 changes: 23 additions & 13 deletions dist/components/Types/ViroUtils.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@ export type ViroRotation = [
number,
number
];
/**
* 3D Vector, stored as [x, y, z].
*/
export type Viro3DVector = [
number,
number,
number
];
/**
* The scale of the container in 3D space, specified as [x,y,z]. A scale of
* 1 represents the current size of the container. A scale value of < 1
Expand Down Expand Up @@ -88,19 +96,18 @@ export type ViroPhysicsBody = {
* If an array of forces is provided, the corresponding net force will be applied.
* Force units are in newtons.
*/
force?: number[];
force?: ViroForce[];
/**
* A single torque vector or an array of torque vectors applied to the physics body.
* If an array of torque is provided, the corresponding net torque will be applied.
* A single 3D torque vector applied to the physics body.
* Torque units are in newton meters.
*/
torque?: number[];
torque?: ViroTorque;
/**
* Used to directly move an object without applying a force.
* Units are m/s. Doing so will override any forces that are already
* applied on this physics body.
*/
velocity?: number[];
velocity?: Viro3DVector;
};
export type ViroPhysicsBodyType = "Dynamic" | "Kinematic" | "Static";
export type ViroPhysicsBodyShape = {
Expand All @@ -109,13 +116,12 @@ export type ViroPhysicsBodyShape = {
};
export type ViroPhysicsBodyShapeType = "Box" | "Sphere" | "Compound";
/**
* A single force vector or an array of force vectors applied to the physics body.
* If an array of forces is provided, the corresponding net force will be applied.
* A single force vector applied to the physics body.
* Force units are in newtons.
*/
export type ViroForce = {
value: Array<number>;
position: Array<number>;
value: Viro3DVector;
position: Viro3DPoint;
};
export type ViroSource = ImageSourcePropType;
export type ViroARPlaneType = any;
Expand All @@ -126,12 +132,16 @@ export type ViroSoundRoom = {
floorMaterial: string;
};
export type ViroPhysicsWorld = {
gravity: number;
gravity: Viro3DVector;
drawBounds?: boolean;
};
export type ViroRay = any;
export type ViroTorque = any;
export type ViroVelocity = any;
export type ViroRay = Viro3DVector;
/**
* A single 3D torque vector applied to the physics body.
* Torque units are in newton meters.
*/
export type ViroTorque = Viro3DVector;
export type ViroVelocity = Viro3DVector;
export type Viro2DPoint = [number, number];
export type ViroUVCoordinate = [number, number, number, number];
export type ViroSoundMap = {
Expand Down
4 changes: 2 additions & 2 deletions dist/components/ViroBase.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as React from "react";
import { NativeSyntheticEvent } from "react-native";
import { ViroCommonProps, ViroObjectProps } from "./AR/ViroCommonProps";
import { ViroHoverEvent, ViroClickEvent, ViroClickStateEvent, ViroTouchEvent, ViroScrollEvent, ViroSwipeEvent, ViroPinchEvent, ViroRotateEvent, ViroDragEvent, ViroFuseEvent, ViroAnimationStartEvent, ViroAnimationFinishEvent, ViroCollisionEvent, ViroNativeTransformUpdateEvent, ViroErrorEvent } from "./Types/ViroEvents";
import { ViroNativeRef, ViroForce, Viro3DPoint, ViroTorque, ViroVelocity } from "./Types/ViroUtils";
import { ViroNativeRef, ViroForce, ViroTorque, ViroVelocity } from "./Types/ViroUtils";
export type ViroBaseProps = ViroCommonProps & ViroObjectProps;
export declare class ViroBase<T> extends React.Component<ViroBaseProps & T> {
_component: ViroNativeRef;
Expand All @@ -21,7 +21,7 @@ export declare class ViroBase<T> extends React.Component<ViroBaseProps & T> {
_onError: (event: NativeSyntheticEvent<ViroErrorEvent>) => void;
getTransformAsync: () => Promise<any>;
getBoundingBoxAsync: () => Promise<any>;
applyImpulse: (force: ViroForce, position: Viro3DPoint) => void;
applyImpulse: (force: ViroForce) => void;
applyTorqueImpulse: (torque: ViroTorque) => void;
setVelocity: (velocity: ViroVelocity) => void;
_onCollision: (event: NativeSyntheticEvent<ViroCollisionEvent>) => void;
Expand Down
4 changes: 2 additions & 2 deletions dist/components/ViroBase.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,8 @@ class ViroBase extends React.Component {
getBoundingBoxAsync = async () => {
return await react_native_1.NativeModules.VRTNodeModule.getBoundingBox((0, react_native_1.findNodeHandle)(this));
};
applyImpulse = (force, position) => {
react_native_1.NativeModules.VRTNodeModule.applyImpulse((0, react_native_1.findNodeHandle)(this), force, position);
applyImpulse = (force) => {
react_native_1.NativeModules.VRTNodeModule.applyImpulse((0, react_native_1.findNodeHandle)(this), force.value, force.position);
};
applyTorqueImpulse = (torque) => {
react_native_1.NativeModules.VRTNodeModule.applyTorqueImpulse((0, react_native_1.findNodeHandle)(this), torque);
Expand Down
2 changes: 1 addition & 1 deletion dist/components/ViroButton.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export declare class ViroButton extends React.Component<Props, State> {
state: {
buttonType: ViroButtonStateTypes;
};
applyImpulse: (force: ViroForce, atPosition: Viro3DPoint) => void;
applyImpulse: (force: ViroForce) => void;
applyTorqueImpulse: (torque: ViroTorque) => void;
setVelocity: (velocity: ViroVelocity) => void;
_onAnimationStart: () => void;
Expand Down
4 changes: 2 additions & 2 deletions dist/components/ViroButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ class ViroButton extends React.Component {
state = {
buttonType: ViroButtonStateTypes.BTN_TYPE_NORMAL,
};
applyImpulse = (force, atPosition) => {
this._component?.applyImpulse(force, atPosition);
applyImpulse = (force) => {
this._component?.applyImpulse(force);
};
applyTorqueImpulse = (torque) => {
this._component?.applyTorqueImpulse(torque);
Expand Down