3DSinghVFX / animation_nodes

Node-based visual scripting system designed for motion graphics in Blender.
Other
155 stars 16 forks source link

how to define the data structrues of the "object" in the cython #143

Closed kdsin23 closed 4 years ago

kdsin23 commented 4 years ago

hi, i learn to write a cython code file in animation nodes,but i am trouble with cython,yesterday,i tried the way OmarEmaraDev provided,still doesn't work. for example, i want to import "object" to cython, so I add : from ...data_structrues cimport Object def getfunction(Object object): ....

when Cythonizing the .pyx file, it appering an error: 'Object' is not a type identifier,i don't know why, i need some help,Thank you very much!

3DSinghVFX commented 4 years ago

I think, there is no type for Object in data_structures for cimport. Can you elaborate on why do you need Object type in .pyx?

kdsin23 commented 4 years ago

I think, there is no type for Object in data_structures for cimport. Can you elaborate on why do you need Object type in .pyx?

Thank you for your reply! for example, i want to get patilces from ParticleSystem,I maybe write a python file like this:

import bpy
from ... base_types import AnimationNode
from ... utils.depsgraph import getEvaluatedID

class ExtractParticlesNode(bpy.types.Node, AnimationNode):
    bl_idname = "an_ExtractParticlesNode"
    bl_label = "Extract Particles"

    def create(self):
        self.newInput("Object", "Object", "object")
        self.newOutput("Generic", "Particles", "particles")

    def execute(self, object):
        if object is None:
            return

        ParticleList = []
        for p in getEvaluatedID(object).active.particles:
            ParticleList.append(p)

        return ParticleList

but the speed is very slow when performace,so i tried to wirite the function "ExtractParticles()" to the cython file like this:

def ExtractParticles(Object object):
    cdef Py_ssize_t i
    cdef Py_ssize_t count = len(getEvaluatedID(object).particle_systems.active.particles)
    cdef ParticleList = list(length = count)
    for i in range(count):
        ParticleList.append(getEvaluatedID(object).particle_systems.active.particles[i])
    return ParticleList

it gave me an error: c_utils.pyx:58:21: 'Object' is not a type identifier, my question is how to import "object" data_structures,or to create a "Object" data in .pyx,thank you very much!

3DSinghVFX commented 4 years ago

There is no object data type in data_structures. However, your code will run even if you do not define the object type. Here is code of the Particle System from Object node: https://github.com/3DSinghVFX/animation_nodes/blob/0ed95e2c842681c81395f7477bb95f20900388fe/animation_nodes/nodes/particles/particle_systems_from_object.py#L15-L19

kdsin23 commented 4 years ago

There is no object data type in data_structures. However, your code will run even if you do not define the object type. Here is code of the Particle System from Object node:

https://github.com/3DSinghVFX/animation_nodes/blob/0ed95e2c842681c81395f7477bb95f20900388fe/animation_nodes/nodes/particles/particle_systems_from_object.py#L15-L19

Thank you for your explanation ! but this code can not be put into the .pyxfile ,right?

3DSinghVFX commented 4 years ago

You can put the code in .pyx if you want. However, to get the benefits of the Cython we have to specify the types.

kdsin23 commented 4 years ago

You can put the code in .pyx if you want. However, to get the benefits of the Cython we have to specify the types.

Thank you very much!

3DSinghVFX commented 4 years ago

Is it resolved?

kdsin23 commented 4 years ago

Is it resolved?

yes,it is. thank you

3DSinghVFX commented 4 years ago

You're welcome.