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

fix(rendering): replicate SkeletalMesh fields, fix debug skeleton scale #4897

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
3f181eb
bugfix: resolve SkeletonRenderer for multiplayer and correct debug sk…
pollend Sep 7, 2021
2d59d7a
Merge branch 'develop' into bugfix/correct-SkeletonRenderer-debug-res…
pollend Sep 7, 2021
5c86c10
chore: cache matrix and vector
pollend Sep 8, 2021
70b323b
Merge branch 'bugfix/correct-SkeletonRenderer-debug-resolve-update' o…
pollend Sep 8, 2021
19ed92d
Merge branch 'develop' into bugfix/correct-SkeletonRenderer-debug-res…
pollend Sep 10, 2021
54496d9
Merge branch 'develop' into bugfix/correct-SkeletonRenderer-debug-res…
pollend Sep 19, 2021
99f7015
Merge branch 'develop' into bugfix/correct-SkeletonRenderer-debug-res…
jdrueckert Sep 29, 2021
6a49a99
Merge branch 'develop' into bugfix/correct-SkeletonRenderer-debug-res…
jdrueckert Sep 29, 2021
a1d425c
feat: add offset to camera
pollend Oct 3, 2021
582e579
Merge branch 'bugfix/correct-SkeletonRenderer-debug-resolve-update' o…
pollend Oct 3, 2021
b6d94af
Merge branch 'develop' into bugfix/correct-SkeletonRenderer-debug-res…
pollend Oct 27, 2021
8cee37c
chore: update renderoverlay
pollend Oct 30, 2021
fe25375
chore: add todo
pollend Oct 30, 2021
be929fc
Merge branch 'develop' into bugfix/correct-SkeletonRenderer-debug-res…
pollend Oct 30, 2021
75e09b6
Merge branch 'develop' into bugfix/correct-SkeletonRenderer-debug-res…
jdrueckert Nov 2, 2021
c8d5c6d
chore: add comments to SkeletonRenderer
pollend Nov 7, 2021
171a1ad
Merge branch 'develop' into bugfix/correct-SkeletonRenderer-debug-res…
pollend Nov 8, 2021
492e81d
chore: update docs
pollend Nov 14, 2021
783e162
Merge branch 'bugfix/correct-SkeletonRenderer-debug-resolve-update' o…
pollend Nov 14, 2021
60668de
Merge branch 'develop' into bugfix/correct-SkeletonRenderer-debug-res…
jdrueckert Nov 14, 2021
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
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@ public class SkeletalMeshComponent implements VisualComponent<SkeletalMeshCompon
public EntityRef rootBone = EntityRef.NULL;
public float animationTime;

@Replicate
public Vector3f scale = new Vector3f(1, 1, 1);
@Replicate
public Vector3f translate = new Vector3f();

@Replicate
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -310,9 +310,9 @@ public void renderOpaque() {
} else {
logger.warn("Unable to resolve bone \"{}\"", bone.getName());
boneTransforms[bone.getIndex()] = new Matrix4f();

}
}

((OpenGLSkeletalMesh) skeletalMesh.mesh).setScaleTranslate(skeletalMesh.scale, skeletalMesh.translate);
((OpenGLSkeletalMesh) skeletalMesh.mesh).render(Arrays.asList(boneTransforms));
}
Expand Down Expand Up @@ -340,10 +340,15 @@ public void renderOverlay() {
int index = 0;
for (EntityRef entity : entityManager.getEntitiesWith(SkeletalMeshComponent.class, LocationComponent.class)) {
SkeletalMeshComponent skeletalMesh = entity.getComponent(SkeletalMeshComponent.class);
LocationComponent locationComponent = entity.getComponent(LocationComponent.class);
if (skeletalMesh.boneEntities == null) {
continue;
}

Vector3f location = locationComponent.getWorldPosition(new Vector3f());
Quaternionf rotation = locationComponent.getWorldRotation(new Quaternionf());
Matrix4f transform = new Matrix4f().translationRotateScale(location, rotation, 1.0f);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any reason to create new instances for the location vector, the rotation quaternion, and the transformation matrix with each render call for each entity?

You often raise concerns about code like this, so I'm wondering about all the instantiations in this code render code block that gets called quite often (if the debug feature is enabled).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

umm, I guess I could use a temporary Matrix. this is because we have custom offset and translation for the SkeletonComponent :/

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So we need individual vectors here and cannot reuse a single temporary object instance for rendering the skeleton for all entities?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nope, we can cache it, I was just getting lazy. was looking at this at 10 something.


for (Bone bone : skeletalMesh.mesh.getBones()) {
Bone parentBone = bone.getParent();
EntityRef boneEntity = skeletalMesh.boneEntities.get(bone.getName());
Expand All @@ -356,8 +361,21 @@ public void renderOverlay() {
LocationComponent locCompA = boneEntity.getComponent(LocationComponent.class);
LocationComponent locCompB = boneParentEntity.getComponent(LocationComponent.class);

Vector3f worldPosA = locCompA.getWorldPosition(new Vector3f());
Vector3f worldPosB = locCompB.getWorldPosition(new Vector3f());
Matrix4f m1 = new Matrix4f();
Matrix4f m2 = new Matrix4f();

locCompA.getRelativeTransform(m1, entity);
locCompB.getRelativeTransform(m2, entity);


Vector3f worldPosA = new Matrix4f(transform)
.mul(new Matrix4f().scale(skeletalMesh.scale).translate(skeletalMesh.translate).mul(m1))
.transformPosition(new Vector3f());

Vector3f worldPosB =
new Matrix4f(transform)
.mul(new Matrix4f().scale(skeletalMesh.scale).translate(skeletalMesh.translate).mul(m2))
.transformPosition(new Vector3f());

meshData.color0.put(Color.white);
meshData.color0.put(Color.white);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,15 +140,11 @@ public void doRender(List<Vector3f> verts, List<Vector3f> normals) {
}

public void render() {
// preRender();
pollend marked this conversation as resolved.
Show resolved Hide resolved
doRender(data.getBindPoseVertexPositions(), data.getBindPoseVertexNormals());
// postRender();
}

public void render(List<Matrix4f> boneTransforms) {
// preRender();
doRender(data.getVertexPositions(boneTransforms), data.getVertexNormals(boneTransforms));
// postRender();
}

@Override
Expand Down