Skip to content
This repository has been archived by the owner on Sep 26, 2024. It is now read-only.

Commit

Permalink
Spherical coordinates
Browse files Browse the repository at this point in the history
  • Loading branch information
AzureRain committed Jan 11, 2022
1 parent 748840e commit a993645
Show file tree
Hide file tree
Showing 6 changed files with 567 additions and 238 deletions.
23 changes: 3 additions & 20 deletions src/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ import "@babylonjs/core/Debug";
import "@babylonjs/gui";
import "@babylonjs/inspector";
import * as Comlink from "comlink";
import {Poses} from "./worker/pose-processing";
import {CloneableQuaternion, Poses} from "./worker/pose-processing";
import {TransformNodeMap} from "v3d-core/dist/src/importer/babylon-vrm-loader/src";
import {DegToRad, NodeWorldMatrixMap, RadToDeg} from "./helper/utils";
import {DegToRad, NodeQuaternionMap, RadToDeg} from "./helper/utils";
const IS_DEBUG = true;
export let debugInfo: Nullable<DebugInfo>;

Expand Down Expand Up @@ -57,12 +57,11 @@ export async function createScene(
v3DCore.scene?.onBeforeRenderObservable.add(() => {
vrmManager.cameras[0].setTarget(vrmManager.rootMesh.getAbsolutePosition());
});
v3DCore.renderingPipeline.depthOfFieldEnabled = false;

// Render loop
engine.runRenderLoop(() => {
v3DCore.scene?.render();
workerPose.bindHumanoidWorldMatrix(
constructBoneQuaternionMap(vrmManager.humanoidBone.nodeMap));
});

// Model Transformation
Expand All @@ -79,25 +78,9 @@ export async function createScene(
// TODO: Debug only
// @ts-ignore
window['vrmManager'] = vrmManager;
// @ts-ignore
vrmManager.r = Quaternion.RotationYawPitchRoll;
// @ts-ignore
vrmManager.rtd = RadToDeg;
// @ts-ignore
vrmManager.dtr = DegToRad;

// Debug
if (IS_DEBUG && v3DCore.scene) debugInfo = new DebugInfo(v3DCore.scene);

return vrmManager;
}

export const constructBoneQuaternionMap = (
nodeMap: TransformNodeMap
) => {
const retMap: NodeWorldMatrixMap = {};
for (const [k, v] of Object.entries(nodeMap)) {
retMap[k] = v.getWorldMatrix();
}
return retMap;
}
18 changes: 11 additions & 7 deletions src/helper/debug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export function quaternionToDirectionVector(
resultQuaternion: CloneableQuaternion
): Vector3 {
const quaternion = cloneableQuaternionToQuaternion(resultQuaternion);
let result = Vector3.Zero();
const result = Vector3.Zero();
base.rotateByQuaternionToRef(quaternion, result);
return result.normalize();
}
Expand Down Expand Up @@ -273,19 +273,23 @@ export class DebugInfo {
resultPoseLandmarks: NormalizedLandmarkList
) {
if (resultLeftHandNormals) {
for (let i = 0; i < this.leftHandNormalArrows.length; ++i) {
for (let i = 0; i < Math.min(this.leftHandNormalArrows.length,
resultLeftHandNormals.length); ++i) {
this.leftHandNormalArrows[i].updateStartAndDirection(
normalizedLandmarkToVector(
resultPoseLandmarks[POSE_LANDMARKS.LEFT_WRIST]),
// normalizedLandmarkToVector(
// resultPoseLandmarks[POSE_LANDMARKS.LEFT_WRIST]),
Vector3.Zero(),
normalizedLandmarkToVector(resultLeftHandNormals[i]),
);
}
}
if (resultRightHandNormals) {
for (let i = 0; i < this.rightHandNormalArrows.length; ++i) {
for (let i = 0; i < Math.min(this.rightHandNormalArrows.length,
resultRightHandNormals.length); ++i) {
this.rightHandNormalArrows[i].updateStartAndDirection(
normalizedLandmarkToVector(
resultPoseLandmarks[POSE_LANDMARKS.RIGHT_WRIST]),
// normalizedLandmarkToVector(
// resultPoseLandmarks[POSE_LANDMARKS.RIGHT_WRIST]),
Vector3.Zero(),
normalizedLandmarkToVector(resultRightHandNormals[i]),
);
}
Expand Down
Loading

0 comments on commit a993645

Please sign in to comment.