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

[1.0] Fix v0 compatible render queue parsing #995

Merged
merged 2 commits into from
Jun 23, 2022
Merged

[1.0] Fix v0 compatible render queue parsing #995

merged 2 commits into from
Jun 23, 2022

Conversation

0b5vr
Copy link
Contributor

@0b5vr 0b5vr commented Jun 21, 2022

Description

This PR will make this parse v0 render queues properly.

It lists all render queues used in the VRM 0.0 model and creates a map to v1 compliant render queue offset in the same order.

See: https://github.com/vrm-c/vrm-specification/blob/master/specification/VRMC_materials_mtoon-1.0-beta/README.ja.md#render-queue

Points need review

  • Does it work well?
    • If you can bring a VRM 0.0 model with render queues that would be best.

@0b5vr 0b5vr added bug Something isn't working VRM 1.0 labels Jun 21, 2022
@0b5vr 0b5vr added this to the VRM 1.0 milestone Jun 21, 2022
@0b5vr 0b5vr self-assigned this Jun 21, 2022
Array.from(renderQueuesTransparent)
.sort()
.forEach((queue, i) => {
const newQueueOffset = Math.min(Math.max(i - renderQueuesTransparent.size + 1, -9), 0);
Copy link
Contributor

Choose a reason for hiding this comment

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

renderQueuesTransparent.sizeが10より大きい時は警告が出るが処理は継続する。
そのためnewQueueOffset-9が複数回セットされることはありあえる。

@@ -328,21 +344,88 @@ export class VRMMaterialsV0CompatPlugin implements GLTFLoaderPlugin {

/**
* Convert v0 render order into v1 render order.
* This uses a map from v0 render queue to v1 compliant render queue offset which is generated in {@link _populateRenderQueueMap}.
*/
private _v0ParseRenderQueue(materialProperties: V0Material): number {
const isTransparent = materialProperties.keywordMap?.['_ALPHABLEND_ON'] ?? false;
const enabledZWrite = materialProperties.floatProperties?.['_ZWrite'] === 1;

let offset = 0;
Copy link
Contributor

Choose a reason for hiding this comment

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

OPAQUEやMASKの場合はoffsetは0となる


if (v0Queue != null) {
if (enabledZWrite) {
offset = this._renderQueueMapTransparentZWrite.get(v0Queue)!;
Copy link
Contributor

Choose a reason for hiding this comment

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

isTransparent が true で、renderQueが存在するときのみ_renderQueueMapTransparent(ZWrite)にaddされる。

getは成功すると期待してよさそう。


// create a map from v0 render queue to v1 render queue offset
Array.from(renderQueuesTransparent)
.sort()
Copy link
Contributor

Choose a reason for hiding this comment

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

sortが入ってるのでrenderQueueの大小関係は維持される

Copy link
Contributor

@nyamadan nyamadan left a comment

Choose a reason for hiding this comment

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

みました!

@0b5vr 0b5vr merged commit ecace35 into 1.0 Jun 23, 2022
@0b5vr 0b5vr deleted the fix-renderqueue branch June 23, 2022 03:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working VRM 1.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants