Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proposing SV Shape Keys Output Node #1589

Closed
enzyme69 opened this issue Apr 27, 2017 · 13 comments
Closed

Proposing SV Shape Keys Output Node #1589

enzyme69 opened this issue Apr 27, 2017 · 13 comments
Labels

Comments

@enzyme69
Copy link
Collaborator

I am not sure how Blender Shape Keys work internally. Or how its Shape Keys data got linked into the original object. My feeling is that Blender Shape Keys object data is "dead" once linked into original object.

In Maya or Houdini, Shape Keys itself is something that is always hooked.

My curiosity is that: can the "dead" Shape Keys data be modified... using Sverchok? Maybe Sverchok can be the "live data" that continuously updating the data in Shape Keys, this way, we can make Sverchok to act more or less like Modifier, if only the mesh data of original object matches the Sverchok data.

screen shot 2017-04-27 at 11 29 16

What do you all think? Good idea? Yay or Nay?

@enzyme69 enzyme69 changed the title Proposing SV Shape Keys Node Proposing SV Shape Keys Output Node Apr 27, 2017
@enzyme69
Copy link
Collaborator Author

However, suddenly I realize something:
Sverchok can probably do the "Shape Keys" vector interpolation inside it. And more.

However, common Blender workflow maybe nice if Sverchok can modify Shape Keys data, somewhat.
Original Object <- (LIVE) Shape Keys from Sverchok

@enzyme69
Copy link
Collaborator Author

When manually adjusting Shapekeys apparently we can use "Pin" and edit that Shapekey.

@zeffii
Copy link
Collaborator

zeffii commented Apr 27, 2017

It seems to me that shape keys only make sense on a static object, an object that has no changes to topology.

@zeffii
Copy link
Collaborator

zeffii commented Apr 27, 2017

I don't know of any barrier to making a node that operates on a single object and sets its shape keys, but because I have little experience with them I fail to see the usefulness. Show some pics

@enzyme69
Copy link
Collaborator Author

screen shot 2017-04-27 at 20 27 07
screen shot 2017-04-27 at 20 26 43

Above are the example scenario.

  1. We start with a Cube
  2. Sverchok generate some deformation based on Cube, 5 of them
  3. We assign to the Cube, Join As Shapes
  4. Shapekeys now can mix the shapes for that Cube.

In Sverchok node tree, I think Vector Lerp node can probably simulate Shapekeys, maybe... not sure if that is exactly the same.

If we can somewhat have Sverchok node to control the "applied shape key mesh data", then we have some kind of powerful flexibility, creating a "live" shape keys.

A Blender artist friend told me that the usual workflow if we want to edit Shape Key is to just Edit Mode the Shape Keys.

This is like my question before if we can somewhat pass the data back into the original Mesh Data. Which might cause cycle. But in this case, it will not create cyclic dependency because Sverchok juga goes into the Shapekey data.

@enzyme69
Copy link
Collaborator Author

@Kosvor2 this is not working isnt it?
screen shot 2017-04-27 at 20 39 37

@enzyme69
Copy link
Collaborator Author

Wow.. this actually works ...

screen shot 2017-04-27 at 20 41 01

Ok, maybe I will try to further experiment with it.

sv_shape_experiment_003_2017_04_27_10_41.zip

@nortikin
Copy link
Owner

it crashes somehow.
active - activate it
frame = make number of key
SNL script:

"""
in  verts  v   .=[]    n=0
in  edges  s   .=[]    n=0
in  pols   s   .=[]    n=0
in active  s   .=0     n=2
in frame   s   .=1     n=2
"""

import bpy
import bmesh
from mathutils import Vector

#for remove extra brecket
def okok(a):
    if a:
        return a[0]
verts = okok(verts)
edges = okok(edges)
pols = okok(pols)

# main function
def make():
    # find mesh or create
    if not 'sv_shape_key' in bpy.data.meshes:
        mesh = bpy.data.meshes.new('sv_shape_key')
        mesh.from_pydata(verts,edges,pols)
    else:
        mesh = bpy.data.meshes['sv_shape_key']
    # find object or create
    if not 'sv_shape_key' in bpy.data.objects:
        obj = bpy.data.objects.new("sv_shape_key", mesh)
        bpy.context.scene.objects.link(obj)
    else:
        obj = bpy.data.objects['sv_shape_key']

    #bmesh from scene's object
    bm = bmesh.new()
    bm.from_mesh(obj.data)
    bm.verts.ensure_lookup_table()
    bm.edges.ensure_lookup_table()
    bm.faces.ensure_lookup_table()
    
    # name of new shape from frame number
    #i = bpy.context.scene.frame_current
    kn = "sverchok %d"%frame

    # make shape key basis at first
    if 'Basis' not in bm.verts.layers.shape:
        sk0 = obj.shape_key_add("Basis")
        for i,v in enumerate(verts):
            bm.verts[i][sk0] = Vector(v)*(-1)
        #print(sk0)
        #sk0 = obj.data.shape_keys
        #print(sk0)
        sk0.use_relative = False # maybe yes

    #if len(bm.verts) != len(verts):
    #    return
    if kn not in bm.verts.layers.shape:
        #addShapeKey(obj, verts,edges,pols, bpy.context.scene.frame_current)
        sl = bm.verts.layers.shape.new(kn)
        sk = obj.shape_key_add(kn)
        #sl.use_relative = False
        #sl = bm.verts.layers.shape.get(kn)
        #print(sl, 'also what is it?')
        for i,v in enumerate(verts):
            bm.verts[i][sl] = Vector(v)
        bm.verts.ensure_lookup_table()
        bm.to_mesh(obj.data)
if active and verts:
    make()

@nortikin
Copy link
Owner

next will try @enzyme69 approach with this SNL

@nortikin
Copy link
Owner

nortikin commented Apr 22, 2018

ok, will put it now in SNL templates for a while.
@enzyme69 , please, use it
shape_keys
shape_keys

"""
in  verts  v   .=[]    n=0
in  edges  s   .=[]    n=0
in  pols   s   .=[]    n=0
in active  s   .=0     n=2
in frame   s   .=1     n=2
"""

import bpy
import bmesh
from mathutils import Vector


#for remove extra brecket
def okok(a):
    if a:
        return a[0]
verts = okok(verts)
edges = okok(edges)
pols = okok(pols)

# main function
def make():
    # find mesh or create
    if not 'sv_shape_key' in bpy.data.meshes:
        mesh = bpy.data.meshes.new('sv_shape_key')
        mesh.from_pydata(verts,edges,pols)
    else:
        mesh = bpy.data.meshes['sv_shape_key']
    # find object or create
    if not 'sv_shape_key' in bpy.data.objects:
        obj = bpy.data.objects.new("sv_shape_key", mesh)
        bpy.context.scene.objects.link(obj)
    else:
        obj = bpy.data.objects['sv_shape_key']

    # shapekeys adding
    # make shape key basis at first
    if not obj.data.shape_keys:
        sk0 = obj.shape_key_add(name='Basis')
    key = bpy.data.shape_keys[obj.data.shape_keys.name]
    key.use_relative = False

    # name of new shape from frame number
    kn = "sverchok %d"%frame

    # check for equal length of vertices
    if len(obj.data.vertices) != len(verts):
        return
    # current frame to add
    if kn not in key.key_blocks:
        sk = obj.shape_key_add(kn)
        for i,v in enumerate(verts):
            key.key_blocks[kn].data[i].co = Vector(v)

if active and verts:
    make()
#bpy.data.shape_keys[obj.data.shape_keys.name].key_blocks[kn].data[:].co

@nortikin
Copy link
Owner

now it only create, not rewrite shapes. But in full-node it will be, i guess.

@enzyme69
Copy link
Collaborator Author

enzyme69 commented Apr 22, 2018 via email

@nortikin
Copy link
Owner

in master as snl

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants