mtyka / attractor

Attractor plugin for Blender
36 stars 15 forks source link

Error when running with Blender 2.8 it says upgrade to 2.8x required. #1

Closed stillpointx closed 4 years ago

stillpointx commented 5 years ago

I get an error when trying to run this with Blender 2.8

Error when running with Blender 2.8 it says upgrade to 2.8x required. I'm using Ubuntu 18.04 64bit Linux Blender 2.8 I've also included an attached system info file.

system-info.txt

Screenshot from 2019-09-07 22-35-17

http://i.imgur.com/6lzuxBx.png 6lzuxBx

mtyka commented 5 years ago

Hmm, that seems weird because it actually needs Blender 2.6, see this code line: https://github.com/mtyka/attractor/blob/c7edbadcee826ea5d791529cfa329f2c326215ec/attractor.py#L27

Blender 2.8 didn't come out till July 30 this year so it didn't exist when i wrote this, which was Dec 2013. So I'd try actually with an older version, close to 2.6. It's possible the python API has changed since then and needs updating. Happy to take pull requests if you can make it work for 2.8.

t-hier commented 4 years ago

Anmerkung 2019-09-17

I have a similar problem. Using Blender 2.80.75 with integrated Python 3.7

I tried to build it in the video (https://www.youtube.com/watch?v=zHSf-ifjK_Y) Unfortunately, I get these errors.

Maybe you can look over the code again and update it. You would do me a great favor.

schroef commented 4 years ago

The addon will show, but as the pref panel states. It needs to be updated.

schroef commented 4 years ago

Okay i think i got it working again.... this thing drove me nuts for hours man. Kept showing errors and i didnt understand why. After hours i went on search each class name, then noticed 1 class was being added 2 times and that was bugging me.

Though i noticed the def formula looks different, but they have the same name. Is there a reason for that?

See below

class AizawaAttractor(Attractor):
    bl_idname = "curve.aizawa_attractor_add"
    bl_label = "Aizawa Attractor"
    bl_options = {"REGISTER", "UNDO"}

    npoints : get_npoints()
    params = ["a", "b", "c", "d", "e", "f"]
    a: get_prop("aizawa", "a",  0.95)
    b: get_prop("aizawa", "b",  0.7)
    c: get_prop("aizawa", "c",  0.6)
    d: get_prop("aizawa", "d",  3.5)
    e: get_prop("aizawa", "e",  0.25)
    f: get_prop("aizawa", "f",  0.1)
    x: get_prop("aizawa", "x",  0.1)
    y: get_prop("aizawa", "y",  0.00)
    z: get_prop("aizawa", "z",  0.00)
    dt: get_prop("aizawa", "dt", 0.01)

    def iterate(self, x, y, z):
        dx = (z-self.b)*x-self.d*y
        dy = self.d*x+(z-self.b)*y
        dz = self.c+self.a*z-(pow(z, 3)/3)-(pow(x, 2) +
                                            pow(y, 2))*(1+self.e*z)+self.f*z*pow(x, 3)
        return (dx, dy, dz)

number 2

# class AizawaAttractor(Attractor):
#     bl_idname = "curve.aizawa_attractor_add"
#     bl_label = "Aizawa"
#     bl_options = {"REGISTER", "UNDO"}

#     npoints : get_npoints()
#     params = ["a", "b", "c", "d", "e", "f"]
#     a : get_prop("Aizawa", "a", 0.95)
#     b : get_prop("Aizawa", "b", 0.7)
#     c : get_prop("Aizawa", "c", 0.6)
#     d : get_prop("Aizawa", "d", 3.5)
#     e : get_prop("Aizawa", "e", 0.25)
#     f : get_prop("Aizawa", "f", 0.1)
#     x : get_prop("Aizawa", "x", 0.1)
#     y : get_prop("Aizawa", "y", 0.0)
#     z : get_prop("Aizawa", "z", 0.0)
#     dt : get_prop("Aizawa", "dt", 0.01)

#     def iterate(self, x, y, z):
#         xn = (z-self.b)*x-self.d*y
#         yn = self.d*x+(z-self.b)*y
#         zn = self.c+self.a*z-(pow(z, 3)/3)-(pow(x, 2) +
#                                             pow(y, 2))*(1+self.e*z)+self.f*z*pow(x, 3)
#         return xn, yn, zn

It looked the same to me?

Screen Shot 2019-09-18 at 00 01 32
schroef commented 4 years ago

PS ill make a quick fork and do a pull okay. PS i named this one 0.2

schroef commented 4 years ago

I find more issues, i was double checking all operator and got this error now

File "/Users/romboutversluijs/Library/Application Support/Blender/2.80/scripts/addons/attractor.py", line 99, in execute
    polyline.points.add(self.npoints-1)
TypeError: unsupported operand type(s) for -: 'tuple' and 'int'

Ill check if i can find whats wrong

schroef commented 4 years ago

Weird i wanted to print the points in the main Operator to see what it prints. So i added a print function just before the part which gives the error. Weirdly then it just works fine and it prints zero???

print("Points", polyline.points.add(self.npoints))
        polyline.points.add(self.npoints-1)

Its linenumber 100 in Attractor Operator

stillpointx commented 4 years ago

This is a trimmed version of the python script that I got working. The issue is some of the naming conventions and standards changed and if I fix the errors it breaks the plugin. But if you paste this in the blender 2.80 python screen or save it to a attractor280.py and add it as a add-on file it will work. No guarantees it will work in Blender 2.81.

import bpy
import math

from bpy.props import BoolProperty
from bpy.props import FloatProperty
from bpy.props import FloatVectorProperty
from bpy.props import IntProperty

bl_info = {
  "author": "testing_only@gmail.com",
  "blender": (2, 80, 0),
  "category": "Add Curve",
  "description": "Creates a strange attractor curve",
  "location": "View3D > Add > Curve > Attractors",
  "name": "Strange Attractors",
  "version": (0, 1),
  "warning": "",
  "wiki_url": ""
}

def get_prop(cls, name, default):
  return bpy.props.FloatProperty(attr=cls + "_" + name,
                                 name=name,
                                 description="",
                                 default=default)

def get_int_prop(cls, name, default):
  return bpy.props.IntProperty(attr=cls + "_" + name,
                                 name=name,
                                 description="",
                                 default=default)
def get_npoints(default=10000):
  return IntProperty(attr="npoints",
                     name="Vertices",
                     description="",
                     min=1, soft_min=1, default=default)

class Object_OT_Attractor(bpy.types.Operator):
  bl_idname= "object.attractor"
  bl_label= "Label Attractor"
  view_align= BoolProperty(name="Align to View",default=False)
  location= FloatVectorProperty(name="Location",subtype="TRANSLATION")
  rotation= FloatVectorProperty(name="Rotation",subtype="EULER")

  def draw(self, context):
    layout = self.layout
    row = layout.row()
    row.prop(self, "npoints", text="Vertices")

    col = layout.column(align=True)
    for param in self.params:
          col.prop(self, param, text=param)

    col2 = layout.column(align=True)
    col2.prop(self, "x", text="x")
    col2.prop(self, "y", text="y")
    col2.prop(self, "z", text="z")
    col2.prop(self, "dt", text="dt")

  def execute(self, context):
    curvedata = bpy.data.curves.new(name="Curve", type="CURVE")
    curvedata.dimensions = "3D"

    objectdata = bpy.data.objects.new("ObjCurve", curvedata)
    objectdata.location = (0,0,0) 
    #bpy.context.scene.objects.link(objectdata)
    bpy.context.scene.collection.objects.link(objectdata)

    polyline = curvedata.splines.new("POLY")
    polyline.points.add(self.npoints-1)

    x = self.x
    y = self.y
    z = self.z

    n = 0
    while n < self.npoints:
      dx, dy, dz = self.iterate(x, y, z)
      x = x + self.dt * dx
      y = y + self.dt * dy
      z = z + self.dt * dz
      polyline.points[n].co = (x,y,z,math.sqrt(dx*dx+dy*dy+dz*dz))
      n += 1

    return {"FINISHED"}

class CoulletAttractor(Object_OT_Attractor):
  bl_idname = "curve.coullet_attractor_add"
  bl_label = "Coullet Attractor"
  bl_options = {"REGISTER", "UNDO"}

  npoints = get_npoints()
  params = ["a", "b", "c", "d"]
  a= get_prop("coullet", "a",  0.80)
  b= get_prop("coullet", "b", -1.10)
  c= get_prop("coullet", "c", -0.45)
  d= get_prop("coullet", "d", -1.00)

  x= get_prop("coullet", "x",   0.10)
  y= get_prop("coullet", "y",   0.00)
  z= get_prop("coullet", "z",   0.00)
  dt= get_prop("coullet", "dt", 0.01)

  def iterate(self, x, y, z):
    dx = y 
    dy = z
    dz = self.a*x + self.b*y + self.c*z + self.d*x**3
    return (dx, dy, dz)

class LorenzAttractor(Object_OT_Attractor):
  bl_idname = "curve.lorenz_attractor_add"
  bl_label = "Lorenz Attractor"
  bl_options = {"REGISTER", "UNDO"}

  npoints = get_npoints()
  params = ["a", "b", "c"]
  a = get_prop("lorenz", "a",  10.00)
  b = get_prop("lorenz", "b",  28.00)
  c = get_prop("lorenz", "c",  (8/3))

  x = get_prop("lorenz", "x",   0.10)
  y = get_prop("lorenz", "y",   0.00)
  z = get_prop("lorenz", "z",   0.00)
  dt = get_prop("lorenz", "dt", 0.01)

  def iterate(self, x, y, z):
    dx = self.a * (y - x)
    dy = (x * (self.b - z) - y)
    dz = (x * y - self.c * z)
    return (dx, dy, dz)

class Menu_MT_AttractorMenu(bpy.types.Menu):

  bl_idname= "menu.attractormenu"
  bl_label= "Strange Attractors"

  def draw(self, context):
    layout = self.layout
    layout.operator_context = "INVOKE_REGION_WIN"

    layout.operator("curve.coullet_attractor_add", text="Coullet")
    layout.operator("curve.lorenz_attractor_add",text="Lorenz")

def menu_func(self, context):
  self.layout.menu(Menu_MT_AttractorMenu.bl_idname, icon="PLUGIN")

#needed as workaround
bpy.types.VIEW3D_MT_curve_add.append(menu_func)

#All classes used  
classes = (
            Object_OT_Attractor,
            Menu_MT_AttractorMenu,
            LorenzAttractor,
            CoulletAttractor,
          )

#Register and unregister all classes  
register, unregister = bpy.utils.register_classes_factory(classes)

# This allows you to run the script directly from Blender's Text editor
# to test the add-on without having to install it.
if __name__ == "__main__":
  register()

The errors I get in the terminal are below: (note It still will work):

Warning: class OBJECT_OT_attractor contains a property which should be an annotation! /snap/blender/33/2.80/scripts/modules/bpy/utils/init.py:676 assign as a type annotation: OBJECT_OT_attractor.view_align assign as a type annotation: OBJECT_OT_attractor.location assign as a type annotation: OBJECT_OT_attractor.rotation register_class(...): Warning: 'menu.attractormenu' doesn't contain 'MT' with prefix & suffix Warning: class CURVE_OT_lorenz_attractor_add contains a property which should be an annotation! /snap/blender/33/2.80/scripts/modules/bpy/utils/init.py:676 assign as a type annotation: CURVE_OT_lorenz_attractor_add.npoints assign as a type annotation: CURVE_OT_lorenz_attractor_add.a assign as a type annotation: CURVE_OT_lorenz_attractor_add.b assign as a type annotation: CURVE_OT_lorenz_attractor_add.c assign as a type annotation: CURVE_OT_lorenz_attractor_add.x assign as a type annotation: CURVE_OT_lorenz_attractor_add.y assign as a type annotation: CURVE_OT_lorenz_attractor_add.z assign as a type annotation: CURVE_OT_lorenz_attractor_add.dt Warning: class CURVE_OT_coullet_attractor_add contains a property which should be an annotation! /snap/blender/33/2.80/scripts/modules/bpy/utils/init.py:676 assign as a type annotation: CURVE_OT_coullet_attractor_add.npoints assign as a type annotation: CURVE_OT_coullet_attractor_add.a assign as a type annotation: CURVE_OT_coullet_attractor_add.b assign as a type annotation: CURVE_OT_coullet_attractor_add.c assign as a type annotation: CURVE_OT_coullet_attractor_add.d assign as a type annotation: CURVE_OT_coullet_attractor_add.x assign as a type annotation: CURVE_OT_coullet_attractor_add.y assign as a type annotation: CURVE_OT_coullet_attractor_add.z assign as a type annotation: CURVE_OT_coullet_attractor_add.dt

schroef commented 4 years ago

It will not work properly i believe, it took me a quit some time to adjust all those annotations. Perhaps better is a script which does this automatically, yet i have looked at examples and looks quiet complicated.

My version now also works, all of them work. BUt with that weird print error now :)

I also added some transform options, perhaps handy??? PS it does work in 2.81... for now atleast

Screen Shot 2019-09-18 at 01 49 27
7bitretro commented 4 years ago

I'm a total Blender and Python NooB so excuse this but found classes cant be blanket registered in 2.8x?

https://theduckcow.com/2019/update-addons-both-blender-28-and-27-support/

schroef commented 4 years ago

Yeah ive viewd that link a couple times in the past. Did help update my addons. Im not sure why its not working for you, for me it works fine in 2.80 release.

Did you check Console for any output?

PS what do you exactly mean by "blanket registered", im none English so im not sure i understand it properly

schroef commented 4 years ago

PS i check the link again. Im using that new method by the way of registring functions. You need to otherwise it wont even register. My version now works

cupofnestor commented 4 years ago

@schroef , is your fork available? I'd like to check it out.

adicirstei commented 4 years ago

a PR would be good. Thanks!

mtyka commented 4 years ago

I would totally accept pull requests if anybody wants to upgrade the current code to work with latest Blender. Seems like there's only some minor changes that would need to happen ?

mtyka commented 4 years ago

Ok all, thanks for all the work on the upgrades. I used @stillpointx 's version and added the rest of the attractors and some cleanups. Please let mw know if this works - i just tested it in Blender 2.81 on MacOS and it seemed to work nicely.

adicirstei commented 4 years ago

Thank you very much. I tested it on Windows 10 Blender 2.8.0 and it is working great.