From 669be56ed60da74a6cc4b2c5b64277a3f454b02f Mon Sep 17 00:00:00 2001 From: JannisX11 Date: Sat, 21 May 2022 17:43:08 +0200 Subject: [PATCH] WIP preview scenes --- index.html | 1 + js/interface/menu.js | 1 + js/io/format.js | 1 + js/io/formats/bedrock.js | 1 + js/io/formats/bedrock_old.js | 2 +- js/preview/canvas.js | 2 ++ js/preview/preview.js | 2 +- js/preview/preview_scenes.js | 63 ++++++++++++++++++++++++++++++++++++ js/texturing/textures.js | 15 ++++++--- lang/en.json | 2 ++ 10 files changed, 83 insertions(+), 7 deletions(-) create mode 100644 js/preview/preview_scenes.js diff --git a/index.html b/index.html index 2f72154d..a6e453e8 100644 --- a/index.html +++ b/index.html @@ -131,6 +131,7 @@ + diff --git a/js/interface/menu.js b/js/interface/menu.js index 2d220bce..656215ca 100644 --- a/js/interface/menu.js +++ b/js/interface/menu.js @@ -875,6 +875,7 @@ const MenuBar = { 'fullscreen', '_', 'view_mode', + 'preview_scene', 'toggle_shading', 'toggle_motion_trails', 'toggle_ground_plane', diff --git a/js/io/format.js b/js/io/format.js index 584b6530..195d1038 100644 --- a/js/io/format.js +++ b/js/io/format.js @@ -223,6 +223,7 @@ new Property(ModelFormat, 'boolean', 'canvas_limit'); new Property(ModelFormat, 'boolean', 'rotation_limit'); new Property(ModelFormat, 'boolean', 'uv_rotation'); new Property(ModelFormat, 'boolean', 'animation_files'); +new Property(ModelFormat, 'boolean', 'preview_scenes'); new Property(ModelFormat, 'boolean', 'pose_mode'); new Property(ModelFormat, 'boolean', 'display_mode'); new Property(ModelFormat, 'boolean', 'animation_mode'); diff --git a/js/io/formats/bedrock.js b/js/io/formats/bedrock.js index 6fe624fe..32cc566c 100644 --- a/js/io/formats/bedrock.js +++ b/js/io/formats/bedrock.js @@ -1068,6 +1068,7 @@ var format = new ModelFormat({ animated_textures: true, animation_files: true, animation_mode: true, + preview_scenes: true, locators: true, texture_meshes: true, codec diff --git a/js/io/formats/bedrock_old.js b/js/io/formats/bedrock_old.js index 31efd46d..3112ccfd 100644 --- a/js/io/formats/bedrock_old.js +++ b/js/io/formats/bedrock_old.js @@ -498,10 +498,10 @@ var format = new ModelFormat({ animated_textures: true, animation_files: true, animation_mode: true, + preview_scenes: true, locators: true, codec, }) -//Object.defineProperty(format, 'single_texture', {get: _ => !settings.layered_textures.value}) codec.format = format; BARS.defineActions(function() { diff --git a/js/preview/canvas.js b/js/preview/canvas.js index 82a0099b..3b0c659b 100644 --- a/js/preview/canvas.js +++ b/js/preview/canvas.js @@ -408,6 +408,8 @@ const Canvas = { }) })(), transparentMaterial: new THREE.MeshBasicMaterial({visible: false, name: 'invisible'}), + global_light_color: new THREE.Color(0xffffff), + gridMaterial: new THREE.LineBasicMaterial({color: gizmo_colors.grid}), buildGrid() { three_grid.children.length = 0; diff --git a/js/preview/preview.js b/js/preview/preview.js index 208ee80a..8e123fb6 100644 --- a/js/preview/preview.js +++ b/js/preview/preview.js @@ -2009,7 +2009,7 @@ function updateShading() { Texture.all.forEach(tex => { let material = tex.getMaterial(); material.uniforms.SHADE.value = settings.shading.value; - material.uniforms.BRIGHTNESS.value = settings.brightness.value / 50; + material.uniforms.LIGHTCOLOR.value.copy(Canvas.global_light_color).multiplyScalar(settings.brightness.value / 50); }) Canvas.emptyMaterials.forEach(material => { material.uniforms.SHADE.value = settings.shading.value; diff --git a/js/preview/preview_scenes.js b/js/preview/preview_scenes.js new file mode 100644 index 00000000..3a7c2642 --- /dev/null +++ b/js/preview/preview_scenes.js @@ -0,0 +1,63 @@ +class PreviewScene { + constructor(id, data) { + PreviewScene.scenes[id] = this; + this.id = id; + + this.name = tl(data.name || `preview_scene.${id}`); + this.light_color = data.light_color || {r: 1, g: 1, b: 1}; + this.condition = data.condition; + } + select() { + console.log(this.light_color) + Canvas.global_light_color.copy(this.light_color); + updateShading(); + } + unselect() { + Canvas.global_light_color.set(0xffffff); + updateShading(); + } +} +PreviewScene.scenes = {}; +PreviewScene.active = null; + + + +new PreviewScene('minecraft_nether', { + light_color: {r: 0.68, g: 0.61, b: 0.49} +}); +new PreviewScene('minecraft_end', { + light_color: {r: 0.45, g: 0.52, b: 0.48} +}); + + +BARS.defineActions(function() { + new BarSelect('preview_scene', { + category: 'view', + condition: () => Format && Format.preview_scenes, + value: 'none', + options: { + none: tl('generic.none'), + minecraft_nether: 'Nether', + minecraft_end: 'The End' + }, + /* + options() { + let opts = { + none: tl('generic.none') + } + for (let id in PreviewScene.scenes) { + let scene = PreviewScene.scenes[id]; + opts[id] = scene.name; + } + return opts; + },*/ + onChange() { + let scene = PreviewScene.scenes[this.value]; + if (scene) { + scene.select(); + } else if (PreviewScene.active) { + PreviewScene.active.unselect(); + } + } + }) +}) diff --git a/js/texturing/textures.js b/js/texturing/textures.js index bd1f6e3d..214530d9 100644 --- a/js/texturing/textures.js +++ b/js/texturing/textures.js @@ -109,7 +109,7 @@ class Texture { uniform bool SHADE; uniform bool EMISSIVE; - uniform float BRIGHTNESS; + uniform vec3 LIGHTCOLOR; varying vec2 vUv; varying float light; @@ -123,12 +123,17 @@ class Texture { if (EMISSIVE == false) { - gl_FragColor = vec4(lift + color.rgb * light * BRIGHTNESS, color.a); + gl_FragColor = vec4(lift + color.rgb * light, color.a); + gl_FragColor.r = gl_FragColor.r * LIGHTCOLOR.r; + gl_FragColor.g = gl_FragColor.g * LIGHTCOLOR.g; + gl_FragColor.b = gl_FragColor.b * LIGHTCOLOR.b; } else { - float light2 = (light * BRIGHTNESS) + (1.0 - light * BRIGHTNESS) * (1.0 - color.a); - gl_FragColor = vec4(lift + color.rgb * light2, 1.0); + float light_r = (light * LIGHTCOLOR.r) + (1.0 - light * LIGHTCOLOR.r) * (1.0 - color.a); + float light_g = (light * LIGHTCOLOR.g) + (1.0 - light * LIGHTCOLOR.g) * (1.0 - color.a); + float light_b = (light * LIGHTCOLOR.b) + (1.0 - light * LIGHTCOLOR.b) * (1.0 - color.a); + gl_FragColor = vec4(lift + color.r * light_r, lift + color.g * light_g, lift + color.b * light_b, 1.0); } @@ -141,7 +146,7 @@ class Texture { uniforms: { map: {type: 't', value: tex}, SHADE: {type: 'bool', value: settings.shading.value}, - BRIGHTNESS: {type: 'bool', value: settings.brightness.value / 50}, + LIGHTCOLOR: {type: 'vec3', value: new THREE.Color().copy(Canvas.global_light_color).multiplyScalar(settings.brightness.value / 50)}, EMISSIVE: {type: 'bool', value: this.render_mode == 'emissive'} }, vertexShader: vertShader, diff --git a/lang/en.json b/lang/en.json index ac2931e1..9001d935 100644 --- a/lang/en.json +++ b/lang/en.json @@ -1196,6 +1196,8 @@ "action.view_mode.wireframe": "Wireframe", "action.view_mode.uv": "UV Preview", "action.view_mode.normal": "Face Normal", + "action.preview_scene": "Preview Scene", + "action.preview_scene.desc": "Change the model preview scene", "action.screenshot_model": "Screenshot Model", "action.screenshot_model.desc": "Take a cropped screenshot of the model from the current angle", "action.record_model_gif": "Record GIF...",