Skip to content

Commit

Permalink
refactor: move VRMSpring classes
Browse files Browse the repository at this point in the history
  • Loading branch information
Yuki Shimada committed Aug 19, 2023
1 parent c8642b7 commit a300b41
Show file tree
Hide file tree
Showing 12 changed files with 52 additions and 49 deletions.
2 changes: 1 addition & 1 deletion src/foundation/components/Physics/PhysicsComponent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { applyMixins, EntityRepository } from '../../core/EntityRepository';
import { WellKnownComponentTIDs } from '../WellKnownComponentTIDs';
import { ProcessStage } from '../../definitions/ProcessStage';
import { ComponentTID, ComponentSID, EntityUID } from '../../../types/CommonTypes';
import { VRMSpringBonePhysicsStrategy } from '../../physics/VRMSpringBonePhysicsStrategy';
import { VRMSpringBonePhysicsStrategy } from '../../physics/VRMSpring/VRMSpringBonePhysicsStrategy';
import { PhysicsStrategy } from '../../physics/PhysicsStrategy';
import { IEntity } from '../../core/Entity';
import { ComponentToComponentMethods } from '../ComponentTypes';
Expand Down
25 changes: 12 additions & 13 deletions src/foundation/importer/Vrm0xImporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@ import { GltfLoadOption, RnM2 } from '../../types';
import { RenderPass } from '../renderer/RenderPass';
import { Texture } from '../textures/Texture';
import { EntityRepository } from '../core/EntityRepository';
import { VRMSpringBonePhysicsStrategy } from '../physics/VRMSpringBonePhysicsStrategy';
import { VRMSpringBonePhysicsStrategy } from '../physics/VRMSpring/VRMSpringBonePhysicsStrategy';
import { PhysicsComponent } from '../components/Physics/PhysicsComponent';
import { SceneGraphComponent } from '../components/SceneGraph/SceneGraphComponent';
import { SphereCollider } from '../physics/SphereCollider';
import { SphereCollider } from '../physics/VRMSpring/SphereCollider';
import { Vector3 } from '../math/Vector3';
import { VRMColliderGroup } from '../physics/VRMColliderGroup';
import { VRMSpring } from '../physics/VRMSpring';
import { VRMColliderGroup } from '../physics/VRMSpring/VRMColliderGroup';
import { VRMSpring } from '../physics/VRMSpring/VRMSpring';
import { assertIsOk, Err, IResult, Ok } from '../misc/Result';
import { VrmComponent, VrmExpression } from '../components/Vrm/VrmComponent';
import { Sampler } from '../textures/Sampler';
import { VRMSpringBone } from '../physics/VRMSpringBone';
import { VRMSpringBone } from '../physics/VRMSpring/VRMSpringBone';

/**
* The VRM Importer class.
Expand Down Expand Up @@ -234,18 +234,20 @@ export class Vrm0xImporter {
this.__addSpringBoneRecursively(vrmSpringBoneGroup, entity, boneGroup, addedEntities);
}



boneGroups.push(vrmSpringBoneGroup);
}

for (const boneGroup of boneGroups) {
this.__addPhysicsComponent(boneGroup, boneGroup.rootBone);
}

}

private static __addSpringBoneRecursively(vrmSpring: VRMSpring, entity: ISceneGraphEntity, boneGroup: Vrm0xBoneGroup, addedEntities: ISceneGraphEntity[]): void {
private static __addSpringBoneRecursively(
vrmSpring: VRMSpring,
entity: ISceneGraphEntity,
boneGroup: Vrm0xBoneGroup,
addedEntities: ISceneGraphEntity[]
): void {
const sg = entity.getSceneGraph();
const children = sg.children;

Expand All @@ -269,10 +271,7 @@ export class Vrm0xImporter {
}
}

private static __addPhysicsComponent(
boneGroup: VRMSpring,
sg: SceneGraphComponent
): void {
private static __addPhysicsComponent(boneGroup: VRMSpring, sg: SceneGraphComponent): void {
const entity = sg.entity;
const newEntity = EntityRepository.addComponentToEntity(PhysicsComponent, entity);
const physicsComponent = newEntity.getPhysics();
Expand Down
12 changes: 6 additions & 6 deletions src/foundation/importer/VrmImporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,20 @@ import { GltfLoadOption, RnM2, Vrm0x, Vrm0xMaterialProperty } from '../../types'
import { RenderPass } from '../renderer/RenderPass';
import { Texture } from '../textures/Texture';
import { EntityRepository } from '../core/EntityRepository';
import { VRMSpringBonePhysicsStrategy } from '../physics/VRMSpringBonePhysicsStrategy';
import { VRMSpringBonePhysicsStrategy } from '../physics/VRMSpring/VRMSpringBonePhysicsStrategy';
import { PhysicsComponent } from '../components/Physics/PhysicsComponent';
import { SceneGraphComponent } from '../components/SceneGraph/SceneGraphComponent';
import { SphereCollider } from '../physics/SphereCollider';
import { SphereCollider } from '../physics/VRMSpring/SphereCollider';
import { Vector3 } from '../math/Vector3';
import { VRMColliderGroup } from '../physics/VRMColliderGroup';
import { VRMSpring } from '../physics/VRMSpring';
import { VRMColliderGroup } from '../physics/VRMSpring/VRMColliderGroup';
import { VRMSpring } from '../physics/VRMSpring/VRMSpring';
import { Vrm1, Vrm1SpringBone_Joint, Vrm1_Materials_MToon } from '../../types/VRM1';
import { assertIsOk, Err, IResult, Ok } from '../misc/Result';
import { Gltf2Importer } from './Gltf2Importer';
import { Sampler } from '../textures/Sampler';
import { VrmComponent, VrmExpression, VrmExpressionMorphBind } from '../components';
import { VRMSpringBone } from '../physics/VRMSpringBone';
import { CapsuleCollider } from '../physics/CapsuleCollider';
import { VRMSpringBone } from '../physics/VRMSpring/VRMSpringBone';
import { CapsuleCollider } from '../physics/VRMSpring/CapsuleCollider';
import { ConstraintComponent } from '../components/Constraint';
import { VrmRollConstraint } from '../constraints/VrmRollConstraint';
import { VrmAimConstraint } from '../constraints/VrmAimConstraint';
Expand Down
2 changes: 1 addition & 1 deletion src/foundation/physics/PhysicsStrategy.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { VRMSpring } from "./VRMSpring";
import { VRMSpring } from './VRMSpring/VRMSpring';

export interface PhysicsStrategy {
update(): void;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { SceneGraphComponent } from '../components/SceneGraph/SceneGraphComponent';
import { Vector3 } from '../math/Vector3';
import { SceneGraphComponent } from '../../components/SceneGraph/SceneGraphComponent';
import { Vector3 } from '../../math/Vector3';

export class CapsuleCollider {
public position = Vector3.zero();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { SceneGraphComponent } from '../components/SceneGraph/SceneGraphComponent';
import { Vector3 } from '../math/Vector3';
import { SceneGraphComponent } from '../../components/SceneGraph/SceneGraphComponent';
import { Vector3 } from '../../math/Vector3';

export class SphereCollider {
public position = Vector3.zero();
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Vector3 } from '../math/Vector3';
import { SceneGraphComponent } from '../components/SceneGraph/SceneGraphComponent';
import { RnObject } from '../core/RnObject';
import { Index } from '../../types/CommonTypes';
import { Vector3 } from '../../math/Vector3';
import { SceneGraphComponent } from '../../components/SceneGraph/SceneGraphComponent';
import { RnObject } from '../../core/RnObject';
import { Index } from '../../../types/CommonTypes';
import { VRMSpringBone } from './VRMSpringBone';
import { VRMColliderGroup } from './VRMColliderGroup';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import { SceneGraphComponent } from "../components";
import { RnObject } from "../core/RnObject";
import { ISceneGraphEntity } from "../helpers/EntityHelper";
import { IVector3, Matrix44, Quaternion } from "../math";
import { Vector3 } from "../math/Vector3";
import { SceneGraphComponent } from '../../components';
import { RnObject } from '../../core/RnObject';
import { ISceneGraphEntity } from '../../helpers/EntityHelper';
import { IVector3, Matrix44, Quaternion } from '../../math';
import { Vector3 } from '../../math/Vector3';

export class VRMSpringBone extends RnObject {
stiffnessForce = 0.5;
gravityPower = 0;
gravityDir = Vector3.fromCopyArray([0, -1.0, 0]);
dragForce = 0.05;
hitRadius = 0.02;
node: ISceneGraphEntity
node: ISceneGraphEntity;

currentTail: Vector3 = Vector3.zero(); // In World Space
prevTail: Vector3 = Vector3.zero(); // In World Space
Expand All @@ -29,7 +29,8 @@ export class VRMSpringBone extends RnObject {
const scenegraph = this.node.getSceneGraph();
this.node.getTransform()._backupTransformAsRest();
const worldChildPosition = scenegraph.getWorldPositionOf(localChildPosition);
this.currentTail = center != null ? center.getLocalPositionOf(worldChildPosition) : worldChildPosition;
this.currentTail =
center != null ? center.getLocalPositionOf(worldChildPosition) : worldChildPosition;
this.prevTail = this.currentTail.clone();
this.boneAxis = Vector3.normalize(localChildPosition);
this.boneLength = localChildPosition.length();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import { Vector3 } from '../math/Vector3';
import { MutableVector3 } from '../math/MutableVector3';
import { SceneGraphComponent } from '../components/SceneGraph/SceneGraphComponent';
import { Quaternion } from '../math/Quaternion';
import { Time } from '../misc/Time';
import { Vector3 } from '../../math/Vector3';
import { MutableVector3 } from '../../math/MutableVector3';
import { SceneGraphComponent } from '../../components/SceneGraph/SceneGraphComponent';
import { Quaternion } from '../../math/Quaternion';
import { Time } from '../../misc/Time';
import { VRMSpring } from './VRMSpring';
import { VRMColliderGroup } from './VRMColliderGroup';
import { Index } from '../../types/CommonTypes';
import { PhysicsStrategy } from './PhysicsStrategy';
import { MutableQuaternion } from '../math/MutableQuaternion';
import { Is } from '../misc/Is';
import { Index } from '../../../types/CommonTypes';
import { PhysicsStrategy } from '../PhysicsStrategy';
import { MutableQuaternion } from '../../math/MutableQuaternion';
import { Is } from '../../misc/Is';
import { VRMSpringBone } from './VRMSpringBone';
import { Matrix44 } from '../math/Matrix44';
import { Matrix44 } from '../../math/Matrix44';

export class VRMSpringBonePhysicsStrategy implements PhysicsStrategy {
private static __tmp_vec3 = MutableVector3.zero();
Expand Down
6 changes: 6 additions & 0 deletions src/foundation/physics/VRMSpring/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export * from './CapsuleCollider';
export * from './SphereCollider';
export * from './VRMColliderGroup';
export * from './VRMSpring';
export * from './VRMSpringBone';
export * from './VRMSpringBonePhysicsStrategy';
3 changes: 0 additions & 3 deletions src/foundation/physics/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,2 @@
export * from './PhysicsStrategy';
export * from './SphereCollider';
export * from './VRMColliderGroup';
export * from './VRMSpring';
export * from './VRMSpringBonePhysicsStrategy';

0 comments on commit a300b41

Please sign in to comment.