Giter Club home page Giter Club logo

I tried to compile a single file my_wiggle_falloff.pyx based on wiggle_falloff.pyx, and it pops up an error relative cimport beyong main package is not allowed. Below is the setup.py. Is it possible to compile a single file rather than the whole package? about animation_nodes HOT 10 CLOSED

derekcbr avatar derekcbr commented on June 23, 2024
I tried to compile a single file my_wiggle_falloff.pyx based on wiggle_falloff.pyx, and it pops up an error relative cimport beyong main package is not allowed. Below is the setup.py. Is it possible to compile a single file rather than the whole package?

from animation_nodes.

Comments (10)

OmarEmaraDev avatar OmarEmaraDev commented on June 23, 2024

You probably need to set the include dir to the Animation Nodes header and import using a path relative to the Animation Nodes module.

See the Cython section of the developer guide for extensions:
https://docs.animation-nodes.com/developer_guide/extensions/introduction/#cython

from animation_nodes.

derekcbr avatar derekcbr commented on June 23, 2024

You probably need to set the include dir to the Animation Nodes header and import using a path relative to the Animation Nodes module.

See the Cython section of the developer guide for extensions: https://docs.animation-nodes.com/developer_guide/extensions/introduction/#cython

Thanks Omar!Will try!

from animation_nodes.

derekcbr avatar derekcbr commented on June 23, 2024

Hi Omar,
I was not able to complie correctly, please take a look and many thanks.
from setuptools import setup, Extension
from Cython.Build import cythonize
from Cython.Distutils import build_ext
import sys
user_name = 'UPC'
mypath01=r'C:\Users\UPC\AppData\Roaming\Blender Foundation\Blender\2.93\scripts\addons'
if not(mypath01 in sys.path):
sys.path.append(mypath01)
import animation_nodes

extensions = [
Extension(
"my_wiggle_falloff",["my_wiggle_falloff.pyx"],
"include_dirs", ["C:/Users/UPC/Documents/Downloads/animation_nodes_headers"],
),

]

setup(name='my_wiggle_falloff',
ext_modules=cythonize(extensions),
)

You probably need to set the include dir to the Animation Nodes header and import using a path relative to the Animation Nodes module.
See the Cython section of the developer guide for extensions: https://docs.animation-nodes.com/developer_guide/extensions/introduction/#cython

Thanks Omar!Will try!

Hi Omar,
I was not able to complie correctly, please take a look and many thanks.
from setuptools import setup, Extension
from Cython.Build import cythonize
from Cython.Distutils import build_ext
import sys
user_name = 'UPC'
mypath01=r'C:\Users\UPC\AppData\Roaming\Blender Foundation\Blender\2.93\scripts\addons'
if not(mypath01 in sys.path):
sys.path.append(mypath01)
import animation_nodes

extensions = [
Extension(
"my_wiggle_falloff",["my_wiggle_falloff.pyx"],
"include_dirs", ["C:/Users/UPC/Documents/Downloads/animation_nodes_headers"],
),

]

setup(name='my_wiggle_falloff',
ext_modules=cythonize(extensions),
)

from animation_nodes.

OmarEmaraDev avatar OmarEmaraDev commented on June 23, 2024

Can you provide a more complete version of what you are trying to do so that I can test it locally?
It is unclear to me why you import animation_nodes in the setup file here.

from animation_nodes.

derekcbr avatar derekcbr commented on June 23, 2024

Can you provide a more complete version of what you are trying to do so that I can test it locally? It is unclear to me why you import animation_nodes in the setup file here.

image

setup.py is as below:

from setuptools import setup, Extension 
from Cython.Build import cythonize
from Cython.Distutils import build_ext

extensions = [
    Extension(
        "my_wiggle_falloff",["my_wiggle_falloff.pyx"],
        "include_dirs", ["C:/Users/UPC/Documents/Downloads/animation_nodes_headers"],
    ),
    
]

setup(name='my_wiggle_falloff',
      ext_modules=cythonize(extensions),
      )

my_wiggle_off.pyx is below:

import bpy
from bpy.props import *
from ... base_types import AnimationNode
from ... data_structures cimport BaseFalloff
from ... algorithms.perlin_noise cimport perlinNoise1D

class WiggleFalloffNode():

    def execute(self, seed, evolution, speed, offset, amplitude, octaves, persistance):
        evolution *= max(speed, 0) / 10
        return WiggleFalloff(seed, evolution, offset, amplitude, octaves, persistance)

cdef class WiggleFalloff(BaseFalloff):
    cdef:
        double evolution
        double offset, amplitude
        double persistance
        int octaves

    def __cinit__(self, float seed, float evolution,
                        float offset, float amplitude,
                        int octaves, float persistance):
        self.evolution = seed * 341312 + evolution
        self.amplitude = amplitude
        self.persistance = persistance
        self.offset = offset
        self.octaves = min(max(octaves, 0), 100)
        self.clamped = False
        self.dataType = "NONE"

    cdef float evaluate(self, void *object, Py_ssize_t index):
        cdef double x = self.evolution + index * 1127
        cdef double noise = perlinNoise1D(x, self.persistance, self.octaves)
        return <float>(self.amplitude * noise + self.offset)

from animation_nodes.

OmarEmaraDev avatar OmarEmaraDev commented on June 23, 2024

You should probably set the include path in the cythonize function as follows:

from Cython.Build import cythonize
from Cython.Distutils import build_ext
from setuptools import setup, Extension 

extensions = [
    Extension(
        "my_wiggle_falloff", ["my_wiggle_falloff.pyx"]
    ),
]

setup(
    name = "my_wiggle_falloff",
    ext_modules = cythonize(extensions,
                            include_path = ["/path/to/animation_nodes_headers", "."],
                            compiler_directives = {"language_level" : "3"}),
)

And use absolute imports relative to the animation_nodes module as follows:

from animation_nodes.data_structures cimport BaseFalloff
from animation_nodes.algorithms.perlin_noise cimport perlinNoise1D

from animation_nodes.

derekcbr avatar derekcbr commented on June 23, 2024
animation_nodes.

It worked well now. Thanks a lot Omar! Your supports are always great!

from animation_nodes.

derekcbr avatar derekcbr commented on June 23, 2024

Hi Omar, although the compilation is ok, when call my_wiggle_falloff, it will generate below errors:animation_nodes.data_structures.meshes,mesh_data.Mesh size changed ,may indicate binary incompatibility, expect 88 from c header, got 80 from pyobject. not sure why?

from animation_nodes.

OmarEmaraDev avatar OmarEmaraDev commented on June 23, 2024

This likely means that your headers are older/newer than your compiled files. Make sure both the headers and the compiled objects are of the same version.

from animation_nodes.

derekcbr avatar derekcbr commented on June 23, 2024

This likely means that your headers are older/newer than your compiled files. Make sure both the headers and the compiled objects are of the same version.

Thanks Omar again.

from animation_nodes.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.