Skip to content
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

Adapter bone api change #240

Merged
merged 1 commit into from
Dec 13, 2023
Merged
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
24 changes: 9 additions & 15 deletions packages/skeleton-viewer/src/SkeletonViewer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,37 +159,31 @@ export class SkeletonViewer extends Script {
}

private _showSkeleton(renderer: SkinnedMeshRenderer): void {
// @ts-ignore
if (!renderer._jointEntities) {
renderer.update(0);
}
// @ts-ignore
const joints: Entity[] = renderer._jointEntities;

const bones = renderer.bones;
const spheres: Entity[][] = [];

let maxLength = 0;

for (let i = 0; i < joints.length; i++) {
const joint = joints[i];
const anchorPoint = joint.transform.worldPosition;
for (let i = 0; i < bones.length; i++) {
const bone = bones[i];
const anchorPoint = bone.transform.worldPosition;

// 球
const entity = joint.createChild();
const entity = bone.createChild();
const renderer = entity.addComponent(MeshRenderer);
renderer.receiveShadows = false;
renderer.castShadows = false;
renderer.mesh = PrimitiveMesh.createSphere(this.engine, this.ballSize, 16);
renderer.setMaterial(this._material);
renderer.priority = 1;

spheres.push([entity, joint]);
spheres.push([entity, bone]);

this._debugMesh.push(renderer);

// 连接体
for (let j = 0; j < joint.childCount; j++) {
const child = joint.children[j];
for (let j = 0; j < bone.children.length; j++) {
const child = bone.children[j];
const childPoint = child.transform.worldPosition;
const absoluteDirection = childPoint.clone().subtract(anchorPoint);
const direction = child.transform.position;
Expand All @@ -199,7 +193,7 @@ export class SkeletonViewer extends Script {
maxLength = distance;
}

const entity = joint;
const entity = bone;
const renderer = entity.addComponent(MeshRenderer);
renderer.receiveShadows = false;
renderer.castShadows = false;
Expand Down
Loading