Skip to content

Commit

Permalink
Slim skins now work correctly on reference models
Browse files Browse the repository at this point in the history
FIxes #2037
  • Loading branch information
JannisX11 committed Jan 3, 2024
1 parent 932ab3f commit be9abef
Show file tree
Hide file tree
Showing 2 changed files with 164 additions and 9 deletions.
88 changes: 82 additions & 6 deletions js/display_mode.js
Original file line number Diff line number Diff line change
Expand Up @@ -1605,11 +1605,13 @@ function updateDisplaySkin(feedback) {
let {material} = PreviewModel.models.attachable_reference_player;
material.map.image.src = skin;
material.map.needsUpdate = true;
PreviewModel.models.attachable_reference_player.updateArmVariant(slim);
}
if (PreviewModel.models.minecraft_player) {
let {material} = PreviewModel.models.minecraft_player;
material.map.image.src = skin;
material.map.needsUpdate = true;
PreviewModel.models.minecraft_player.updateArmVariant(slim);
}
}
if (!val || typeof val !== 'string') {
Expand Down Expand Up @@ -1649,6 +1651,7 @@ function updateDisplaySkin(feedback) {
setPSkin(val, slim);
}
}
DisplayMode.updateDisplaySkin = updateDisplaySkin;

BARS.defineActions(function() {
new Action('add_display_preset', {
Expand Down Expand Up @@ -1949,7 +1952,7 @@ Interface.definePanels(function() {
// Bedrock Attachables
BARS.defineActions(function() {

let player_preview_model = new PreviewModel('attachable_reference_player', {
let player_attachable_reference_model = new PreviewModel('attachable_reference_player', {
texture: './assets/player_skin.png',
texture_size: [64, 64],
cubes: [
Expand Down Expand Up @@ -2005,12 +2008,15 @@ BARS.defineActions(function() {
"down": {"uv": [36, 32, 28, 36]}
}
},


// ======= Wide Arms
{
// Right Arm
"position": [4, 12, -2],
"size": [4, 12, 4],
"origin": [5, 22, 0],
"rotation": [15, 0, 0],
"rotation": [-1, 0, 3],
"faces": {
"north": {"uv": [44, 20, 48, 32]},
"east": {"uv": [40, 20, 44, 32]},
Expand All @@ -2025,7 +2031,7 @@ BARS.defineActions(function() {
"position": [3.75, 11.75, -2.25],
"size": [4.5, 12.5, 4.5],
"origin": [5, 22, 0],
"rotation": [15, 0, 0],
"rotation": [-1, 0, 3],
"faces": {
"north": {"uv": [44, 36, 48, 48]},
"east": {"uv": [40, 36, 44, 48]},
Expand All @@ -2039,6 +2045,8 @@ BARS.defineActions(function() {
// Left Arm
"position": [-8, 12, -2],
"size": [4, 12, 4],
"origin": [-5, 22, 0],
"rotation": [1, 0, -3],
"faces": {
"north": {"uv": [36, 52, 40, 64]},
"east": {"uv": [32, 52, 36, 64]},
Expand All @@ -2052,6 +2060,8 @@ BARS.defineActions(function() {
// Arm Layer
"position": [-8.25, 11.75, -2.25],
"size": [4.5, 12.5, 4.5],
"origin": [-5, 22, 0],
"rotation": [1, 0, -3],
"faces": {
"north": {"uv": [52, 52, 56, 64]},
"east": {"uv": [48, 52, 52, 64]},
Expand All @@ -2061,6 +2071,71 @@ BARS.defineActions(function() {
"down": {"uv": [60, 48, 56, 52]}
}
},


// ======= Slim Arms
{
// Right Arm
"position": [4, 11.5, -2],
"size": [3, 12, 4],
"origin": [5, 21.5, 0],
"rotation": [-1, 0, 3],
"faces": {
"north": {"uv": [44,20,47,32]},
"east": {"uv": [40,20,44,32]},
"south": {"uv": [51,20,54,32]},
"west": {"uv": [47,20,51,32]},
"up": {"uv": [47,20,44,16]},
"down": {"uv": [50,16,47,20]}
}
},
{
// Arm Layer
"position": [3.75, 11.25, -2.25],
"size": [3.5, 12.5, 4.5],
"origin": [5, 21.5, 0],
"rotation": [-1, 0, 3],
"faces": {
"north": {"uv": [44,36,47,48]},
"east": {"uv": [40,36,44,48]},
"south": {"uv": [51,36,54,48]},
"west": {"uv": [47,36,51,48]},
"up": {"uv": [47,36,44,32]},
"down": {"uv": [50,32,47,36]}
}
},
{
// Left Arm
"position": [-7, 11.5, -2],
"size": [3, 12, 4],
"origin": [-5, 21.5, 0],
"rotation": [1, 0, -3],
"faces": {
"north": {"uv": [36,52,39,64]},
"east": {"uv": [32,52,36,64]},
"south": {"uv": [43,52,46,64]},
"west": {"uv": [39,52,43,64]},
"up": {"uv": [39,52,36,48]},
"down": {"uv": [42,48,39,52]}
}
},
{
// Arm Layer
"position": [-7.25, 11.25, -2.25],
"size": [3.5, 12.5, 4.5],
"origin": [-5, 21.5, 0],
"rotation": [1, 0, -3],
"faces": {
"north": {"uv": [52,52,55,64]},
"east": {"uv": [48,52,52,64]},
"south": {"uv": [59,52,62,64]},
"west": {"uv": [55,52,59,64]},
"up": {"uv": [55,52,52,48]},
"down": {"uv": [58,48,55,52]}
}
},


{
// Right Leg
"position": [-0.1, 0, -2],
Expand Down Expand Up @@ -2116,7 +2191,8 @@ BARS.defineActions(function() {
]
})

window.player_preview_model = player_preview_model;
window.player_attachable_reference_model = player_attachable_reference_model;
player_attachable_reference_model.updateArmVariant = player_preview_model.updateArmVariant;

let camera_preset_1st = {
name: tl('action.bedrock_animation_mode.attachable_first'),
Expand Down Expand Up @@ -2164,14 +2240,14 @@ BARS.defineActions(function() {
Project.model_3d.position.set(5, 22, 0).add(arm_offset);
}
Project.model_3d.rotation.set(angle, 0, 0);
player_preview_model.enable()
player_attachable_reference_model.enable()

if (!player_skin_setup) {
updateDisplaySkin();
player_skin_setup = true;
}
} else {
player_preview_model.disable()
player_attachable_reference_model.disable()
}

if (mode != 'attachable_first' && mode != 'attachable_third' && Format.id == 'bedrock') {
Expand Down
85 changes: 82 additions & 3 deletions js/preview/preview_scenes.js
Original file line number Diff line number Diff line change
Expand Up @@ -271,17 +271,15 @@ class PreviewModel {
}

let indices = [];
let j = 0;
mesh.geometry.faces = [];
mesh.geometry.clearGroups();
Canvas.face_order.forEach((fkey, i) => {
if (cube.faces[fkey]) {
indices.push(0 + i*4, 2 + i*4, 1 + i*4, 2 + i*4, 3 + i*4, 1 + i*4);
mesh.geometry.faces.push(fkey)
j++;
}
})
mesh.geometry.setIndex(indices)
mesh.geometry.setIndex(indices);

for (let face in cube.faces) {
let uv_array = getUVArray(cube.faces[face]);
Expand Down Expand Up @@ -451,6 +449,10 @@ let player_preview_model = new PreviewModel('minecraft_player', {
scale: [0.9375, 0.9375, 0.9375],
onUpdate() {
this.material.color.copy(Canvas.global_light_color);
if (!this.was_set_up) {
DisplayMode.updateDisplaySkin();
this.was_set_up = true;
}
},
cubes: [
{
Expand Down Expand Up @@ -507,6 +509,9 @@ let player_preview_model = new PreviewModel('minecraft_player', {
"down": {"uv": [36, 32, 28, 36]}
}
},


// ======= Wide Arms
{
// Right Arm
"position": [4, 12, -2],
Expand Down Expand Up @@ -567,6 +572,72 @@ let player_preview_model = new PreviewModel('minecraft_player', {
"down": {"uv": [60, 48, 56, 52]}
}
},


// ======= Slim Arms
{
// Right Arm
"position": [4, 11.5, -2],
"size": [3, 12, 4],
"origin": [5, 21.5, 0],
"rotation": [-1, 0, 3],
"faces": {
"north": {"uv": [44,20,47,32]},
"east": {"uv": [40,20,44,32]},
"south": {"uv": [51,20,54,32]},
"west": {"uv": [47,20,51,32]},
"up": {"uv": [47,20,44,16]},
"down": {"uv": [50,16,47,20]}
}
},
{
// Arm Layer
"position": [3.75, 11.25, -2.25],
"size": [3.5, 12.5, 4.5],
"origin": [5, 21.5, 0],
"rotation": [-1, 0, 3],
"faces": {
"north": {"uv": [44,36,47,48]},
"east": {"uv": [40,36,44,48]},
"south": {"uv": [51,36,54,48]},
"west": {"uv": [47,36,51,48]},
"up": {"uv": [47,36,44,32]},
"down": {"uv": [50,32,47,36]}
}
},
{
// Left Arm
"position": [-7, 11.5, -2],
"size": [3, 12, 4],
"origin": [-5, 21.5, 0],
"rotation": [1, 0, -3],
"faces": {
"north": {"uv": [36,52,39,64]},
"east": {"uv": [32,52,36,64]},
"south": {"uv": [43,52,46,64]},
"west": {"uv": [39,52,43,64]},
"up": {"uv": [39,52,36,48]},
"down": {"uv": [42,48,39,52]}
}
},
{
// Arm Layer
"position": [-7.25, 11.25, -2.25],
"size": [3.5, 12.5, 4.5],
"origin": [-5, 21.5, 0],
"rotation": [1, 0, -3],
"faces": {
"north": {"uv": [52,52,55,64]},
"east": {"uv": [48,52,52,64]},
"south": {"uv": [59,52,62,64]},
"west": {"uv": [55,52,59,64]},
"up": {"uv": [55,52,52,48]},
"down": {"uv": [58,48,55,52]}
}
},



{
// Right Leg
"position": [-0.1, 0, -2],
Expand Down Expand Up @@ -622,6 +693,14 @@ let player_preview_model = new PreviewModel('minecraft_player', {
]
})

player_preview_model.updateArmVariant = function(slim) {
for (let i = 4; i < 8; i++) {
this.model_3d.children[i].visible = !slim;
}
for (let i = 8; i < 12; i++) {
this.model_3d.children[i].visible = !!slim;
}
}

StateMemory.init('minecraft_eula_accepted', 'object');
const MinecraftEULA = {
Expand Down

0 comments on commit be9abef

Please sign in to comment.