donmccurdy / three-gltf-viewer

Drag-and-drop preview for glTF 2.0 models in WebGL using three.js.
https://gltf-viewer.donmccurdy.com/
MIT License
2.09k stars 534 forks source link

Blendshape changes object color on its own #283

Closed thisismygatekeeper closed 2 years ago

thisismygatekeeper commented 2 years ago

To reproduce, I use blender to generate a very simple cube, assign it a base color and a blend shape that shrinks the cube in one dimension. After these, I save the cube as a gltf file. Then, in gltf viewer, dragging on the blend shape will change the “color” of the cube.

This seems odd. I’m pretty new to this space. Is this a bug or a feature?

I’m attaching the blender python script, the generated gltf file as well as a video clip for the color changing effect.

import bpy

cube = bpy.data.objects['Cube']

mat = cube.data.materials[0]
mat.use_nodes = True
mat.node_tree.nodes['Principled BSDF'].inputs[0].default_value = (0.1, 0.2, 0.3, 1)

sk_basis = cube.shape_key_add(name='Basis')
sk_basis.interpolation = 'KEY_LINEAR'

sk = cube.shape_key_add(name='Key')
sk.interpolation = 'KEY_LINEAR'
for i in range(4):
  sk.data[i * 2 + 1].co.z = -1
for i in range(4):
  sk.data[i * 2].co.z = -1

gltf file: https://www.dropbox.com/s/b1qjvy3btu38hut/1.glb?dl=0

video clip:

https://user-images.githubusercontent.com/96497730/151229950-651f6020-5349-4524-8c0d-d18ad35f20f3.mp4

donmccurdy commented 2 years ago

Often morph targets (also: "shape keys" or "blend shapes") change not just the positions of vertices, but the normal vectors associated with them. That's probably what you're seeing here – as the morph target weight increases, the lighting begins to look as if the sides are facing up. For complex morph targets that can be a good thing, but as you mention it's confusing when the shape is just a cube.

If you don't want that to happen, when exporting from Blender you can change export settings to (a) skip shape key normals, or (b) skip vertex normals entirely. I'd probably choose (b) for models with a low-poly look.

thisismygatekeeper commented 2 years ago

Thanks for your reply @donmccurdy. Turning off normals works!