Godlander / Godlander/objmc

Normals become out of sync with entity rotation

Open
#92 0 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
Python
Stars
645
Forks
59
PR merge metrics
No merged PRs in 30d

Description

**Description**
OBJMC item models that have received transformations in-game on the `roll` colour channel become out of sync with the entity rotation (yaw and pitch). As demonstrated below in code, the main include shader for OBJMC could theoretically recalculate normals using the `rotation` vector as a scalar of reference for the roll.

**Reproduction**
- Summon an item display with a tinted OBJMC item model exported with roll colour behaviour (during my test, blue channel was used)
```mcfunction
/summon item_display ~ ~ ~ {item:{id:"stick",components:{item_model:"example_objmc_model",custom_model_data:{colors:[I;0]}}}}
```
- Face the entity directly at the player using a repeating command block:
```mcfunction
/tp [entity] ^ ^ ^ facing entity @p eyes
```
- Set the roll colour value of the model used so that it is flipped on Z axis (e.g. 0.5 = 180°).
```mcfunction
/data modify entity [entity] item.components."minecraft:custom_model_data".colors[0] set value [[0.0,0.0,0.5]]
```
**Screenshots**
![Image](https://github.com/user-attachments/assets/27aab8d7-3d5d-43c5-805c-9d69fe0cda90)

**Environment:**
- Windows 10
- Minecraft 1.21.4 (vanilla)
- i5-7200U, Intel Graphics 620

**Additional context**
GLSL code from `objmc_main.glsl` that fixes the issue :
- Rotations are inverted based on roll colour behaviour (works best at every right angle)

```glsl
if (any(greaterThan(autorotate,vec2(0)))) {

//normal estimated rotation calculation from The Der Discohund
float yaw = -atan(Normal.x, Normal.z);
float pitch = -atan(Normal.y, length(Normal.xz));

// recalculate normal rotation based on roll
float roll = max(0.0, min(rotation.z, 1.0));
yaw = yaw * (1 - roll) - yaw * roll;
pitch = pitch * (1 - roll) - pitch * roll;

posoffset = rotate(vec3(vec2(pitch,yaw)*autorotate,0) + rotation) * posoffset;
}
```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.