mirror of
https://github.com/JannisX11/blockbench.git
synced 2025-01-30 15:42:42 +08:00
Add preview scene player model option
This commit is contained in:
parent
86b4bb720e
commit
85eb7a04bf
@ -1393,7 +1393,7 @@
|
||||
opacity: 0.8;
|
||||
}
|
||||
#timeline_graph_editor svg .main_graph:not(.selected) {
|
||||
opacity: 0.25;
|
||||
opacity: 0.35;
|
||||
}
|
||||
#timeline_graph_editor svg .loop_graph:not(.selected) {
|
||||
opacity: 0.25;
|
||||
|
@ -1612,6 +1612,11 @@ function updateDisplaySkin(feedback) {
|
||||
material.map.image.src = skin;
|
||||
material.map.needsUpdate = true;
|
||||
}
|
||||
if (PreviewModel.models.minecraft_player) {
|
||||
let {material} = PreviewModel.models.minecraft_player;
|
||||
material.map.image.src = skin;
|
||||
material.map.needsUpdate = true;
|
||||
}
|
||||
}
|
||||
if (!val || typeof val !== 'string') {
|
||||
setPSkin('assets/player_skin.png')
|
||||
|
@ -101,9 +101,6 @@ class PreviewScene {
|
||||
await this.lazyLoadFromWeb()
|
||||
}
|
||||
if (PreviewScene.active) PreviewScene.active.unselect();
|
||||
this.preview_models.forEach(model => {
|
||||
model.enable();
|
||||
})
|
||||
|
||||
Canvas.global_light_color.copy(this.light_color);
|
||||
Canvas.global_light_side = this.light_side;
|
||||
@ -112,6 +109,13 @@ class PreviewScene {
|
||||
if (this.fov) {
|
||||
Preview.selected.setFOV(this.fov);
|
||||
}
|
||||
// Update independent models
|
||||
PreviewModel.getActiveModels().forEach(model => {
|
||||
model.update();
|
||||
});
|
||||
this.preview_models.forEach(model => {
|
||||
model.enable();
|
||||
})
|
||||
PreviewScene.active = this;
|
||||
Blockbench.dispatchEvent('select_preview_scene', {scene: this});
|
||||
Canvas.updateShading();
|
||||
@ -159,11 +163,15 @@ class PreviewModel {
|
||||
this.condition = data.condition;
|
||||
this.model_3d = new THREE.Object3D();
|
||||
this.onUpdate = data.onUpdate;
|
||||
this.enabled = false;
|
||||
|
||||
this.build_data = {
|
||||
prefabs: data.prefabs,
|
||||
cubes: data.cubes || [],
|
||||
texture: data.texture,
|
||||
position: data.position,
|
||||
rotation: data.rotation,
|
||||
scale: data.scale,
|
||||
}
|
||||
this.color = data.color || '#ffffff';
|
||||
this.shading = data.shading !== false;
|
||||
@ -174,16 +182,26 @@ class PreviewModel {
|
||||
}
|
||||
enable() {
|
||||
Canvas.scene.add(this.model_3d);
|
||||
this.enabled = true;
|
||||
this.update();
|
||||
}
|
||||
disable() {
|
||||
Canvas.scene.remove(this.model_3d);
|
||||
this.enabled = false;
|
||||
}
|
||||
update() {
|
||||
if (typeof this.onUpdate == 'function') {
|
||||
this.onUpdate();
|
||||
}
|
||||
this.model_3d.position.x = this.model_3d.position.z = Format.centered_grid ? 0 : 8;
|
||||
if (this.build_data.position) {
|
||||
this.model_3d.position.fromArray(this.build_data.position);
|
||||
} else {
|
||||
this.model_3d.position.set(0, 0, 0);
|
||||
}
|
||||
let offset = Format.centered_grid ? 0 : 8;
|
||||
this.model_3d.position.x += offset;
|
||||
this.model_3d.position.z += offset;
|
||||
|
||||
this.model_3d.visible = !!Condition(this.condition);
|
||||
}
|
||||
buildModel() {
|
||||
@ -209,6 +227,10 @@ class PreviewModel {
|
||||
this.material.color.copy(this.color);
|
||||
}
|
||||
|
||||
if (this.build_data.position) this.model_3d.position.fromArray(this.build_data.position);
|
||||
if (this.build_data.rotation) this.model_3d.rotation.fromArray(this.build_data.rotation.map(r => Math.degToRad(r)));
|
||||
if (this.build_data.scale) this.model_3d.scale.fromArray(this.build_data.scale);
|
||||
|
||||
this.build_data.cubes.forEach(cube => {
|
||||
if (cube.prefab) {
|
||||
if (!this.build_data.prefabs[cube.prefab]) console.error(`Invalid prefab "${cube.prefab}"`)
|
||||
@ -289,10 +311,14 @@ class PreviewModel {
|
||||
}
|
||||
PreviewModel.models = {};
|
||||
PreviewModel.getActiveModels = function() {
|
||||
if (PreviewScene.active) {
|
||||
return PreviewScene.active.preview_models.filter(model => Condition(model.condition));
|
||||
let list = [];
|
||||
for (let id in PreviewModel.models) {
|
||||
let model = PreviewModel.models[id];
|
||||
if (model.enabled) {
|
||||
list.push(model);
|
||||
}
|
||||
}
|
||||
return [];
|
||||
return list;
|
||||
}
|
||||
|
||||
new PreviewModel('studio', {
|
||||
@ -417,6 +443,185 @@ new PreviewScene('minecraft_end', {
|
||||
});
|
||||
|
||||
|
||||
let player_preview_model = new PreviewModel('minecraft_player', {
|
||||
texture: './assets/player_skin.png',
|
||||
texture_size: [64, 64],
|
||||
position: [30, 0, 8],
|
||||
rotation: [0, 20, 0],
|
||||
scale: [0.9375, 0.9375, 0.9375],
|
||||
onUpdate() {
|
||||
this.material.color.copy(Canvas.global_light_color);
|
||||
},
|
||||
cubes: [
|
||||
{
|
||||
// "Head
|
||||
"position": [-4, 24, -4],
|
||||
"size": [8, 8, 8],
|
||||
"rotation": [0, 18, 0],
|
||||
"faces": {
|
||||
"north": {"uv": [8, 8, 16, 16]},
|
||||
"east": {"uv": [0, 8, 8, 16]},
|
||||
"south": {"uv": [24, 8, 32, 16]},
|
||||
"west": {"uv": [16, 8, 24, 16]},
|
||||
"up": {"uv": [16, 8, 8, 0]},
|
||||
"down": {"uv": [24, 0, 16, 8]}
|
||||
}
|
||||
},
|
||||
{
|
||||
// Hat Layer
|
||||
"position": [-4.5, 23.5, -4.5],
|
||||
"size": [9, 9, 9],
|
||||
"rotation": [0, 18, 0],
|
||||
"faces": {
|
||||
"north": {"uv": [40, 8, 48, 16]},
|
||||
"east": {"uv": [32, 8, 40, 16]},
|
||||
"south": {"uv": [56, 8, 64, 16]},
|
||||
"west": {"uv": [48, 8, 56, 16]},
|
||||
"up": {"uv": [48, 8, 40, 0]},
|
||||
"down": {"uv": [56, 0, 48, 8]}
|
||||
}
|
||||
},
|
||||
{
|
||||
// "Body
|
||||
"position": [-4, 12, -2],
|
||||
"size": [8, 12, 4],
|
||||
"faces": {
|
||||
"north": {"uv": [20, 20, 28, 32]},
|
||||
"east": {"uv": [16, 20, 20, 32]},
|
||||
"south": {"uv": [32, 20, 40, 32]},
|
||||
"west": {"uv": [28, 20, 32, 32]},
|
||||
"up": {"uv": [28, 20, 20, 16]},
|
||||
"down": {"uv": [36, 16, 28, 20]}
|
||||
}
|
||||
},
|
||||
{
|
||||
// Body Layer
|
||||
"position": [-4.25, 11.75, -2.25],
|
||||
"size": [8.5, 12.5, 4.5],
|
||||
"faces": {
|
||||
"north": {"uv": [20, 36, 28, 48]},
|
||||
"east": {"uv": [16, 36, 20, 48]},
|
||||
"south": {"uv": [32, 36, 40, 48]},
|
||||
"west": {"uv": [28, 36, 32, 48]},
|
||||
"up": {"uv": [28, 36, 20, 32]},
|
||||
"down": {"uv": [36, 32, 28, 36]}
|
||||
}
|
||||
},
|
||||
{
|
||||
// Right Arm
|
||||
"position": [4, 12, -2],
|
||||
"size": [4, 12, 4],
|
||||
"origin": [5, 22, 0],
|
||||
"rotation": [-1, 0, 3],
|
||||
"faces": {
|
||||
"north": {"uv": [44, 20, 48, 32]},
|
||||
"east": {"uv": [40, 20, 44, 32]},
|
||||
"south": {"uv": [52, 20, 56, 32]},
|
||||
"west": {"uv": [48, 20, 52, 32]},
|
||||
"up": {"uv": [48, 20, 44, 16]},
|
||||
"down": {"uv": [52, 16, 48, 20]}
|
||||
}
|
||||
},
|
||||
{
|
||||
// Arm Layer
|
||||
"position": [3.75, 11.75, -2.25],
|
||||
"size": [4.5, 12.5, 4.5],
|
||||
"origin": [5, 22, 0],
|
||||
"rotation": [-1, 0, 3],
|
||||
"faces": {
|
||||
"north": {"uv": [44, 36, 48, 48]},
|
||||
"east": {"uv": [40, 36, 44, 48]},
|
||||
"south": {"uv": [52, 36, 56, 48]},
|
||||
"west": {"uv": [48, 36, 52, 48]},
|
||||
"up": {"uv": [48, 36, 44, 32]},
|
||||
"down": {"uv": [52, 32, 48, 36]}
|
||||
}
|
||||
},
|
||||
{
|
||||
// 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]},
|
||||
"south": {"uv": [44, 52, 48, 64]},
|
||||
"west": {"uv": [40, 52, 44, 64]},
|
||||
"up": {"uv": [40, 52, 36, 48]},
|
||||
"down": {"uv": [44, 48, 40, 52]}
|
||||
}
|
||||
},
|
||||
{
|
||||
// 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]},
|
||||
"south": {"uv": [60, 52, 64, 64]},
|
||||
"west": {"uv": [56, 52, 60, 64]},
|
||||
"up": {"uv": [56, 52, 52, 48]},
|
||||
"down": {"uv": [60, 48, 56, 52]}
|
||||
}
|
||||
},
|
||||
{
|
||||
// Right Leg
|
||||
"position": [-0.1, 0, -2],
|
||||
"size": [4, 12, 4],
|
||||
"faces": {
|
||||
"north": {"uv": [4, 20, 8, 32]},
|
||||
"east": {"uv": [0, 20, 4, 32]},
|
||||
"south": {"uv": [12, 20, 16, 32]},
|
||||
"west": {"uv": [8, 20, 12, 32]},
|
||||
"up": {"uv": [8, 20, 4, 16]},
|
||||
"down": {"uv": [12, 16, 8, 20]}
|
||||
}
|
||||
},
|
||||
{
|
||||
// Leg Layer
|
||||
"position": [-0.35, -0.25, -2.25],
|
||||
"size": [4.5, 12.5, 4.5],
|
||||
"faces": {
|
||||
"north": {"uv": [4, 36, 8, 48]},
|
||||
"east": {"uv": [0, 36, 4, 48]},
|
||||
"south": {"uv": [12, 36, 16, 48]},
|
||||
"west": {"uv": [8, 36, 12, 48]},
|
||||
"up": {"uv": [8, 36, 4, 32]},
|
||||
"down": {"uv": [12, 32, 8, 36]}
|
||||
}
|
||||
},
|
||||
{
|
||||
// Left Leg
|
||||
"position": [-3.9, 0, -2],
|
||||
"size": [4, 12, 4],
|
||||
"faces": {
|
||||
"north": {"uv": [20, 52, 24, 64]},
|
||||
"east": {"uv": [16, 52, 20, 64]},
|
||||
"south": {"uv": [28, 52, 32, 64]},
|
||||
"west": {"uv": [24, 52, 28, 64]},
|
||||
"up": {"uv": [24, 52, 20, 48]},
|
||||
"down": {"uv": [28, 48, 24, 52]}
|
||||
}
|
||||
},
|
||||
{
|
||||
// Leg Layer
|
||||
"position": [-4.15, -0.25, -2.25],
|
||||
"size": [4.5, 12.5, 4.5],
|
||||
"faces": {
|
||||
"north": {"uv": [4, 52, 8, 64]},
|
||||
"east": {"uv": [0, 52, 4, 64]},
|
||||
"south": {"uv": [12, 52, 16, 64]},
|
||||
"west": {"uv": [8, 52, 12, 64]},
|
||||
"up": {"uv": [8, 52, 4, 48]},
|
||||
"down": {"uv": [12, 48, 8, 52]}
|
||||
}
|
||||
}
|
||||
]
|
||||
})
|
||||
|
||||
|
||||
StateMemory.init('minecraft_eula_accepted', 'boolean');
|
||||
const MinecraftEULA = {
|
||||
@ -480,22 +685,21 @@ BARS.defineActions(function() {
|
||||
})
|
||||
}
|
||||
}
|
||||
list.push(new MenuSeparator('individual_objects'));
|
||||
list.push({
|
||||
name: 'Minecraft Player',
|
||||
icon: player_preview_model.enabled ? 'check_box' : 'check_box_outline_blank',
|
||||
click() {
|
||||
if (!player_preview_model.enabled) {
|
||||
player_preview_model.enable();
|
||||
} else {
|
||||
player_preview_model.disable();
|
||||
}
|
||||
}
|
||||
})
|
||||
list.push(BarItems.toggle_all_grids);
|
||||
return list;
|
||||
|
||||
}/*: [
|
||||
{icon: 'radio_button_unchecked', name: 'Studio'},
|
||||
{icon: 'radio_button_unchecked', name: 'Landscape'},
|
||||
'_',
|
||||
{name: 'Minecraft Player', icon: 'check_box_outline_blank'},
|
||||
{icon: 'radio_button_unchecked', name: 'Overworld'},
|
||||
{icon: 'radio_button_unchecked', name: 'Snowy Tundra', click() {PreviewScene.scenes.minecraft_snowy_tundra.select()}},
|
||||
{icon: 'radio_button_unchecked', name: 'Lush Caves'},
|
||||
{icon: 'radio_button_unchecked', name: 'Deep Dark'},
|
||||
{icon: 'radio_button_unchecked', name: 'Nether'},
|
||||
{icon: 'radio_button_unchecked', name: 'Basalt Deltas'},
|
||||
{icon: 'radio_button_unchecked', name: 'Soul Sand Valley'},
|
||||
{icon: 'radio_button_unchecked', name: 'The End'},
|
||||
{icon: 'radio_button_unchecked', name: 'Overworld'},
|
||||
]*/
|
||||
}
|
||||
})
|
||||
})
|
||||
|
@ -306,7 +306,7 @@
|
||||
"message.save_codec_selector.project_file": "Blockbench Project (.bbmodel)",
|
||||
"message.save_codec_selector.both": "Both",
|
||||
|
||||
"message.display_skin.title": "Display Skin",
|
||||
"message.display_skin.title": "Minecraft Skin",
|
||||
"message.display_skin.message": "Select a skin file from your computer or enter a player name",
|
||||
"message.display_skin.upload": "Select File",
|
||||
"message.display_skin.username": "Username (Java)",
|
||||
@ -812,8 +812,8 @@
|
||||
"settings.control_size.desc": "Size of the transform gizmo",
|
||||
"settings.motion_trails": "Motion Trails",
|
||||
"settings.motion_trails.desc": "Show motion trails in the animation editor",
|
||||
"settings.display_skin": "Display Skin",
|
||||
"settings.display_skin.desc": "Skin used for the display reference player model",
|
||||
"settings.display_skin": "Minecraft Skin",
|
||||
"settings.display_skin.desc": "Skin used for the reference player model",
|
||||
"settings.seethrough_outline": "X-Ray Outlines",
|
||||
"settings.seethrough_outline.desc": "Show outlines through objects",
|
||||
"settings.brightness": "Brightness",
|
||||
|
Loading…
Reference in New Issue
Block a user