mirror of
https://github.com/JannisX11/blockbench.git
synced 2024-11-21 01:13:37 +08:00
added "solid with marker color" view mode
This commit is contained in:
parent
dfa0a0ede4
commit
29050ee5ec
@ -1113,7 +1113,10 @@ new NodePreviewController(Cube, {
|
|||||||
mesh.geometry.setIndex(indices)
|
mesh.geometry.setIndex(indices)
|
||||||
|
|
||||||
if (Project.view_mode === 'solid') {
|
if (Project.view_mode === 'solid') {
|
||||||
mesh.material = Canvas.solidMaterial
|
mesh.material = Canvas.monochromaticSolidMaterial
|
||||||
|
|
||||||
|
} else if (Project.view_mode === 'colored_solid') {
|
||||||
|
mesh.material = Canvas.coloredSolidMaterials[element.color % Canvas.emptyMaterials.length]
|
||||||
|
|
||||||
} else if (Project.view_mode === 'wireframe') {
|
} else if (Project.view_mode === 'wireframe') {
|
||||||
mesh.material = Canvas.wireframeMaterial
|
mesh.material = Canvas.wireframeMaterial
|
||||||
|
@ -1061,7 +1061,10 @@ new NodePreviewController(Mesh, {
|
|||||||
let {mesh} = element;
|
let {mesh} = element;
|
||||||
|
|
||||||
if (Project.view_mode === 'solid') {
|
if (Project.view_mode === 'solid') {
|
||||||
mesh.material = Canvas.solidMaterial
|
mesh.material = Canvas.monochromaticSolidMaterial
|
||||||
|
|
||||||
|
} else if (Project.view_mode === 'colored_solid') {
|
||||||
|
mesh.material = Canvas.coloredSolidMaterials[element.color]
|
||||||
|
|
||||||
} else if (Project.view_mode === 'wireframe') {
|
} else if (Project.view_mode === 'wireframe') {
|
||||||
mesh.material = Canvas.wireframeMaterial
|
mesh.material = Canvas.wireframeMaterial
|
||||||
|
@ -294,8 +294,11 @@ new NodePreviewController(TextureMesh, {
|
|||||||
let {mesh} = element;
|
let {mesh} = element;
|
||||||
|
|
||||||
if (Project.view_mode === 'solid') {
|
if (Project.view_mode === 'solid') {
|
||||||
mesh.material = Canvas.solidMaterial
|
mesh.material = Canvas.monochromaticSolidMaterial
|
||||||
|
|
||||||
|
} else if (Project.view_mode === 'colored_solid') {
|
||||||
|
mesh.material = Canvas.coloredSolidMaterials[0]
|
||||||
|
|
||||||
} else if (Project.view_mode === 'wireframe') {
|
} else if (Project.view_mode === 'wireframe') {
|
||||||
mesh.material = Canvas.wireframeMaterial
|
mesh.material = Canvas.wireframeMaterial
|
||||||
|
|
||||||
|
@ -36,6 +36,78 @@ const Reusable = {
|
|||||||
euler2: new THREE.Euler(),
|
euler2: new THREE.Euler(),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Aza note:
|
||||||
|
// ---------------------------------------
|
||||||
|
// Not sure about the pertinence of doing this, but my reasoning is that it saves us
|
||||||
|
// from copying the exact same shaders twice for both solid view mode variants (monochromatic & colored).
|
||||||
|
const SolidMaterialShaders = {
|
||||||
|
vertShader: `
|
||||||
|
attribute float highlight;
|
||||||
|
|
||||||
|
uniform bool SHADE;
|
||||||
|
|
||||||
|
varying float light;
|
||||||
|
varying float lift;
|
||||||
|
|
||||||
|
float AMBIENT = 0.1;
|
||||||
|
float XFAC = -0.05;
|
||||||
|
float ZFAC = 0.05;
|
||||||
|
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
|
||||||
|
if (SHADE) {
|
||||||
|
|
||||||
|
vec3 N = normalize( vec3( modelViewMatrix * vec4(normal, 0.0) ) );
|
||||||
|
|
||||||
|
light = (0.2 + abs(N.z) * 0.8) * (1.0-AMBIENT) + N.x*N.x * XFAC + N.y*N.y * ZFAC + AMBIENT;
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
|
light = 1.0;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if (highlight == 2.0) {
|
||||||
|
lift = 0.3;
|
||||||
|
} else if (highlight == 1.0) {
|
||||||
|
lift = 0.12;
|
||||||
|
} else {
|
||||||
|
lift = 0.0;
|
||||||
|
}
|
||||||
|
|
||||||
|
vec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );
|
||||||
|
gl_Position = projectionMatrix * mvPosition;
|
||||||
|
}`,
|
||||||
|
fragShader: `
|
||||||
|
#ifdef GL_ES
|
||||||
|
precision ${isApp ? 'highp' : 'mediump'} float;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
uniform bool SHADE;
|
||||||
|
uniform float BRIGHTNESS;
|
||||||
|
uniform vec3 base;
|
||||||
|
|
||||||
|
varying float light;
|
||||||
|
varying float lift;
|
||||||
|
|
||||||
|
void main(void)
|
||||||
|
{
|
||||||
|
|
||||||
|
gl_FragColor = vec4(lift + base * light * BRIGHTNESS, 1.0);
|
||||||
|
|
||||||
|
if (lift > 0.1) {
|
||||||
|
gl_FragColor.b = gl_FragColor.b * 1.16;
|
||||||
|
gl_FragColor.g = gl_FragColor.g * 1.04;
|
||||||
|
}
|
||||||
|
if (lift > 0.2) {
|
||||||
|
gl_FragColor.r = gl_FragColor.r * 0.6;
|
||||||
|
gl_FragColor.g = gl_FragColor.g * 0.7;
|
||||||
|
}
|
||||||
|
|
||||||
|
}`
|
||||||
|
}
|
||||||
|
|
||||||
const Canvas = {
|
const Canvas = {
|
||||||
// Stores various colors for the 3D scene
|
// Stores various colors for the 3D scene
|
||||||
gizmo_colors,
|
gizmo_colors,
|
||||||
@ -58,81 +130,31 @@ const Canvas = {
|
|||||||
wireframeMaterial: new THREE.MeshBasicMaterial({
|
wireframeMaterial: new THREE.MeshBasicMaterial({
|
||||||
wireframe: true
|
wireframe: true
|
||||||
}),
|
}),
|
||||||
solidMaterial: (function() {
|
coloredSolidMaterials:[],
|
||||||
var vertShader = `
|
createColoredSolidMaterials() {
|
||||||
attribute float highlight;
|
markerColors.forEach(function(color, i) {
|
||||||
|
if (Canvas.coloredSolidMaterials[i]) return;
|
||||||
uniform bool SHADE;
|
Canvas.coloredSolidMaterials[i] = new THREE.ShaderMaterial({
|
||||||
|
uniforms: {
|
||||||
varying float light;
|
SHADE: {type: 'bool', value: settings.shading.value},
|
||||||
varying float lift;
|
BRIGHTNESS: {type: 'bool', value: settings.brightness.value / 50},
|
||||||
|
base: {value: new THREE.Color().set(color.pastel)}
|
||||||
float AMBIENT = 0.1;
|
},
|
||||||
float XFAC = -0.05;
|
vertexShader: SolidMaterialShaders.vertShader,
|
||||||
float ZFAC = 0.05;
|
fragmentShader: SolidMaterialShaders.fragShader,
|
||||||
|
side: THREE.DoubleSide
|
||||||
void main()
|
});
|
||||||
{
|
})
|
||||||
|
},
|
||||||
if (SHADE) {
|
monochromaticSolidMaterial: (function() {
|
||||||
|
|
||||||
vec3 N = normalize( vec3( modelViewMatrix * vec4(normal, 0.0) ) );
|
|
||||||
|
|
||||||
light = (0.2 + abs(N.z) * 0.8) * (1.0-AMBIENT) + N.x*N.x * XFAC + N.y*N.y * ZFAC + AMBIENT;
|
|
||||||
|
|
||||||
} else {
|
|
||||||
|
|
||||||
light = 1.0;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
if (highlight == 2.0) {
|
|
||||||
lift = 0.3;
|
|
||||||
} else if (highlight == 1.0) {
|
|
||||||
lift = 0.12;
|
|
||||||
} else {
|
|
||||||
lift = 0.0;
|
|
||||||
}
|
|
||||||
|
|
||||||
vec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );
|
|
||||||
gl_Position = projectionMatrix * mvPosition;
|
|
||||||
}`
|
|
||||||
var fragShader = `
|
|
||||||
#ifdef GL_ES
|
|
||||||
precision ${isApp ? 'highp' : 'mediump'} float;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
uniform bool SHADE;
|
|
||||||
uniform float BRIGHTNESS;
|
|
||||||
uniform vec3 base;
|
|
||||||
|
|
||||||
varying float light;
|
|
||||||
varying float lift;
|
|
||||||
|
|
||||||
void main(void)
|
|
||||||
{
|
|
||||||
|
|
||||||
gl_FragColor = vec4(lift + base * light * BRIGHTNESS, 1.0);
|
|
||||||
|
|
||||||
if (lift > 0.1) {
|
|
||||||
gl_FragColor.b = gl_FragColor.b * 1.16;
|
|
||||||
gl_FragColor.g = gl_FragColor.g * 1.04;
|
|
||||||
}
|
|
||||||
if (lift > 0.2) {
|
|
||||||
gl_FragColor.r = gl_FragColor.r * 0.6;
|
|
||||||
gl_FragColor.g = gl_FragColor.g * 0.7;
|
|
||||||
}
|
|
||||||
|
|
||||||
}`
|
|
||||||
|
|
||||||
return new THREE.ShaderMaterial({
|
return new THREE.ShaderMaterial({
|
||||||
uniforms: {
|
uniforms: {
|
||||||
SHADE: {type: 'bool', value: settings.shading.value},
|
SHADE: {type: 'bool', value: settings.shading.value},
|
||||||
BRIGHTNESS: {type: 'bool', value: settings.brightness.value / 50},
|
BRIGHTNESS: {type: 'bool', value: settings.brightness.value / 50},
|
||||||
base: {value: gizmo_colors.solid}
|
base: {value: gizmo_colors.solid}
|
||||||
},
|
},
|
||||||
vertexShader: vertShader,
|
vertexShader: SolidMaterialShaders.vertShader,
|
||||||
fragmentShader: fragShader,
|
fragmentShader: SolidMaterialShaders.fragShader,
|
||||||
side: THREE.DoubleSide
|
side: THREE.DoubleSide
|
||||||
});
|
});
|
||||||
})(),
|
})(),
|
||||||
@ -590,6 +612,7 @@ const Canvas = {
|
|||||||
|
|
||||||
setup() {
|
setup() {
|
||||||
Canvas.updateMarkerColorMaterials();
|
Canvas.updateMarkerColorMaterials();
|
||||||
|
Canvas.createColoredSolidMaterials();
|
||||||
|
|
||||||
//Light
|
//Light
|
||||||
Sun = new THREE.AmbientLight( 0xffffff );
|
Sun = new THREE.AmbientLight( 0xffffff );
|
||||||
@ -935,9 +958,12 @@ const Canvas = {
|
|||||||
if (Canvas.layered_material) {
|
if (Canvas.layered_material) {
|
||||||
Canvas.layered_material.side = side;
|
Canvas.layered_material.side = side;
|
||||||
}
|
}
|
||||||
if (Canvas.solidMaterial) {
|
if (Canvas.monochromaticSolidMaterial) {
|
||||||
Canvas.solidMaterial.side = side;
|
Canvas.monochromaticSolidMaterial.side = side;
|
||||||
}
|
}
|
||||||
|
Canvas.coloredSolidMaterials.forEach(function(mat) {
|
||||||
|
mat.side = side
|
||||||
|
})
|
||||||
Canvas.emptyMaterials.forEach(function(mat) {
|
Canvas.emptyMaterials.forEach(function(mat) {
|
||||||
mat.side = side
|
mat.side = side
|
||||||
})
|
})
|
||||||
@ -1219,8 +1245,11 @@ const Canvas = {
|
|||||||
Canvas.adaptObjectFaceGeo(cube);
|
Canvas.adaptObjectFaceGeo(cube);
|
||||||
|
|
||||||
if (Project.view_mode === 'solid') {
|
if (Project.view_mode === 'solid') {
|
||||||
mesh.material = Canvas.solidMaterial
|
mesh.material = Canvas.monochromaticSolidMaterial
|
||||||
|
|
||||||
|
} else if (Project.view_mode === 'colored_solid') {
|
||||||
|
mesh.material = Canvas.coloredSolidMaterials[cube.color]
|
||||||
|
|
||||||
} else if (Project.view_mode === 'wireframe') {
|
} else if (Project.view_mode === 'wireframe') {
|
||||||
mesh.material = Canvas.wireframeMaterial
|
mesh.material = Canvas.wireframeMaterial
|
||||||
|
|
||||||
|
@ -2070,8 +2070,12 @@ function updateShading() {
|
|||||||
material.uniforms.SHADE.value = settings.shading.value;
|
material.uniforms.SHADE.value = settings.shading.value;
|
||||||
material.uniforms.BRIGHTNESS.value = settings.brightness.value / 50;
|
material.uniforms.BRIGHTNESS.value = settings.brightness.value / 50;
|
||||||
})
|
})
|
||||||
Canvas.solidMaterial.uniforms.SHADE.value = settings.shading.value;
|
Canvas.coloredSolidMaterials.forEach(material => {
|
||||||
Canvas.solidMaterial.uniforms.BRIGHTNESS.value = settings.brightness.value / 50;
|
material.uniforms.SHADE.value = settings.shading.value;
|
||||||
|
material.uniforms.BRIGHTNESS.value = settings.brightness.value / 50;
|
||||||
|
})
|
||||||
|
Canvas.monochromaticSolidMaterial.uniforms.SHADE.value = settings.shading.value;
|
||||||
|
Canvas.monochromaticSolidMaterial.uniforms.BRIGHTNESS.value = settings.brightness.value / 50;
|
||||||
Canvas.uvHelperMaterial.uniforms.SHADE.value = settings.shading.value;
|
Canvas.uvHelperMaterial.uniforms.SHADE.value = settings.shading.value;
|
||||||
Canvas.normalHelperMaterial.uniforms.SHADE.value = settings.shading.value;
|
Canvas.normalHelperMaterial.uniforms.SHADE.value = settings.shading.value;
|
||||||
Blockbench.dispatchEvent('update_scene_shading');
|
Blockbench.dispatchEvent('update_scene_shading');
|
||||||
@ -2094,6 +2098,7 @@ BARS.defineActions(function() {
|
|||||||
options: {
|
options: {
|
||||||
textured: {name: true, icon: 'image', condition: () => (!Toolbox.selected.allowed_view_modes || Toolbox.selected.allowed_view_modes.includes('textured'))},
|
textured: {name: true, icon: 'image', condition: () => (!Toolbox.selected.allowed_view_modes || Toolbox.selected.allowed_view_modes.includes('textured'))},
|
||||||
solid: {name: true, icon: 'fas.fa-square', condition: () => (!Toolbox.selected.allowed_view_modes || Toolbox.selected.allowed_view_modes.includes('solid'))},
|
solid: {name: true, icon: 'fas.fa-square', condition: () => (!Toolbox.selected.allowed_view_modes || Toolbox.selected.allowed_view_modes.includes('solid'))},
|
||||||
|
colored_solid: {name: true, icon: 'fas.fa-square-plus', condition: () => (!Toolbox.selected.allowed_view_modes || Toolbox.selected.allowed_view_modes.includes('colored_solid'))},
|
||||||
wireframe: {name: true, icon: 'far.fa-square', condition: () => (!Toolbox.selected.allowed_view_modes || Toolbox.selected.allowed_view_modes.includes('wireframe'))},
|
wireframe: {name: true, icon: 'far.fa-square', condition: () => (!Toolbox.selected.allowed_view_modes || Toolbox.selected.allowed_view_modes.includes('wireframe'))},
|
||||||
uv: {name: true, icon: 'grid_guides', condition: () => (!Toolbox.selected.allowed_view_modes || Toolbox.selected.allowed_view_modes.includes('uv'))},
|
uv: {name: true, icon: 'grid_guides', condition: () => (!Toolbox.selected.allowed_view_modes || Toolbox.selected.allowed_view_modes.includes('uv'))},
|
||||||
normal: {name: true, icon: 'fa-square-caret-up', condition: () => ((!Toolbox.selected.allowed_view_modes || Toolbox.selected.allowed_view_modes.includes('normal')) && Mesh.all.length)},
|
normal: {name: true, icon: 'fa-square-caret-up', condition: () => ((!Toolbox.selected.allowed_view_modes || Toolbox.selected.allowed_view_modes.includes('normal')) && Mesh.all.length)},
|
||||||
|
@ -1618,6 +1618,7 @@
|
|||||||
"action.view_mode.desc": "Change the model view mode",
|
"action.view_mode.desc": "Change the model view mode",
|
||||||
"action.view_mode.textured": "Textured",
|
"action.view_mode.textured": "Textured",
|
||||||
"action.view_mode.solid": "Solid",
|
"action.view_mode.solid": "Solid",
|
||||||
|
"action.view_mode.colored_solid": "Solid with Marker Colors",
|
||||||
"action.view_mode.wireframe": "Wireframe",
|
"action.view_mode.wireframe": "Wireframe",
|
||||||
"action.view_mode.uv": "UV Preview",
|
"action.view_mode.uv": "UV Preview",
|
||||||
"action.view_mode.normal": "Face Orientation",
|
"action.view_mode.normal": "Face Orientation",
|
||||||
|
@ -1199,6 +1199,7 @@
|
|||||||
"action.view_mode.desc": "Change le mode d'affichage du modèle",
|
"action.view_mode.desc": "Change le mode d'affichage du modèle",
|
||||||
"action.view_mode.textured": "Texturé",
|
"action.view_mode.textured": "Texturé",
|
||||||
"action.view_mode.solid": "Solide",
|
"action.view_mode.solid": "Solide",
|
||||||
|
"action.view_mode.colored_solid": "Solide avec Couleur des marqueurs",
|
||||||
"action.view_mode.wireframe": "Squelette",
|
"action.view_mode.wireframe": "Squelette",
|
||||||
"action.toggle_sidebars": "Activer/désactiver les barres latérales",
|
"action.toggle_sidebars": "Activer/désactiver les barres latérales",
|
||||||
"action.toggle_sidebars.desc": "Active/désactive les bandes sur les côtés",
|
"action.toggle_sidebars.desc": "Active/désactive les bandes sur les côtés",
|
||||||
|
4
package-lock.json
generated
4
package-lock.json
generated
@ -1,12 +1,12 @@
|
|||||||
{
|
{
|
||||||
"name": "Blockbench",
|
"name": "Blockbench",
|
||||||
"version": "4.10.0-beta.1",
|
"version": "4.10.0",
|
||||||
"lockfileVersion": 3,
|
"lockfileVersion": 3,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "Blockbench",
|
"name": "Blockbench",
|
||||||
"version": "4.10.0-beta.1",
|
"version": "4.10.0",
|
||||||
"license": "GPL-3.0-or-later",
|
"license": "GPL-3.0-or-later",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@electron/remote": "^2.1.2",
|
"@electron/remote": "^2.1.2",
|
||||||
|
Loading…
Reference in New Issue
Block a user