omz:forum

    • Register
    • Login
    • Search
    • Recent
    • Popular

    Welcome!

    This is the community forum for my apps Pythonista and Editorial.

    For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.


    For the fun, a Photos cube

    Pythonista
    5
    35
    18758
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • scj643
      scj643 last edited by

      I actually need people to help make an API for scenekit so we can do this type of stuff with a python AI

      1 Reply Last reply Reply Quote 0
      • cvp
        cvp last edited by

        I would like to help but I think I know not enough objective c for that...
        When I program in objc, I spend hours before it works.

        1 Reply Last reply Reply Quote 0
        • scj643
          scj643 last edited by

          https://github.com/scj643/objc_tools is my repo

          1 Reply Last reply Reply Quote 0
          • cvp
            cvp last edited by

            I know your repo, often checked...

            1 Reply Last reply Reply Quote 0
            • momorprods
              momorprods last edited by momorprods

              hey, digging out this old topic - did you have chance into the triangle mesh generation?

              I have started converting the Obj-c snippet above, but it crashes Pythonista at the geometrySourceWithVertices call. Probably my bad, but I’m clueless about how to fiw this:

              verts=[SCNVector3(0, 0, 0), SCNVector3(1, 0, 0), SCNVector3(0, 1, 0)]
              
              src = SCNGeometrySource.geometrySourceWithVertices_count_(POINTER(verts),3)
              cvp 2 Replies Last reply Reply Quote 0
              • cvp
                cvp @momorprods last edited by

                @momorprods No, sorry, I didn't success...

                1 Reply Last reply Reply Quote 0
                • JonB
                  JonB last edited by

                  It wouldn't be POINTER here. Try byref.

                  1 Reply Last reply Reply Quote 0
                  • JonB
                    JonB last edited by

                    Actually, verts must be a ctypes array, not a python list.

                    1 Reply Last reply Reply Quote 0
                    • momorprods
                      momorprods last edited by

                      oh ok thanks, going to try that and keep you posted!

                      1 Reply Last reply Reply Quote 0
                      • momorprods
                        momorprods last edited by momorprods

                        Made this, but still crashing. Am I making another noob mistake?

                        verts=[0.0,0.0,0.0 , 1.0,0.0,0.0 , 0.0,1.0,0.0]
                        arr = (ctypes.c_float * len(verts))(*verts)
                        src = SCNGeometrySource.geometrySourceWithVertices_count_(byref(arr),3)
                        cvp 1 Reply Last reply Reply Quote 0
                        • cvp
                          cvp @momorprods last edited by cvp

                          @momorprods Perhaps this (at least, no crash šŸ˜€)

                          class SCNVector3(Structure):
                          	_fields_ = [('x', c_double), ('y', c_double), ('z', c_double)]
                          

                          And

                              verts=[SCNVector3(0, 0, 0), SCNVector3(1, 0, 0), SCNVector3(0, 1, 0)]
                              verts_array = (SCNVector3 * len(verts))(*verts)
                              SCNGeometrySource = ObjCClass('SCNGeometrySource').geometrySourceWithVertices_count_(
                              verts_array,len(verts),
                              restype=c_void_p,
                              argtypes=[POINTER(SCNVector3), c_ulong],)
                          
                          1 Reply Last reply Reply Quote 0
                          • momorprods
                            momorprods last edited by

                            wooohoooo thanks!!

                            cvp 1 Reply Last reply Reply Quote 0
                            • momorprods
                              momorprods last edited by momorprods

                              Making some good progress thanks to your help. But I’m getting a last crash on the very last instruction - any idea?

                              #triangle generation
                              verts=[SCNVector3(0, 0, 0), SCNVector3(1, 0, 0), SCNVector3(0, 1, 0)]
                              verts_array = (SCNVector3 * len(verts))(*verts)
                              
                              src = ObjCClass('SCNGeometrySource').geometrySourceWithVertices_count_(
                                  verts_array,len(verts),
                                  restype=c_void_p,
                                  argtypes=[POINTER(SCNVector3), c_ulong],)
                                  
                              indexes=[0,1,2]
                              indexes_array = (c_ulong*len(indexes))(*indexes)
                              datIndexes = ObjCClass('NSData').dataWithBytes_length_(indexes_array,len(indexes_array))
                               
                              ele=ObjCClass('SCNGeometryElement').geometryElementWithData_primitiveType_primitiveCount_bytesPerIndex_(datIndexes,SCNGeometryPrimitiveTypeTriangles,1,4)
                                 
                              # CRASH Here: 
                              geo = ObjCClass('SCNGeometry').geometryWithSources_elements_(src,ele)
                              cvp 2 Replies Last reply Reply Quote 0
                              • cvp
                                cvp @momorprods last edited by cvp

                                @momorprods I've read that indices must contain a first element with the number of points but I don't know if it is true.
                                sources and elements must be arrays
                                But I have also a crash with my code
                                See faultlog below but I can't solve the problem, sorry

                                    verts = [SCNVector3(0, 0, 0), SCNVector3(1, 0, 0), SCNVector3(0, 1, 0)]
                                    verts_array = (SCNVector3 * len(verts))(*verts)
                                    SCNGeometrySource = ObjCClass('SCNGeometrySource').geometrySourceWithVertices_count_(
                                    verts_array,len(verts),
                                    restype=c_void_p,
                                    argtypes=[POINTER(SCNVector3), c_ulong],)
                                    sources = NSArray([SCNGeometrySource])
                                    
                                    indices = [3,0,1,2]	# number points and their indices
                                    indices_data = ns(indices)
                                    # primitiveType = 0 for triangle
                                    # primitiveCount = 1
                                    SCNGeometryElement = ObjCClass('SCNGeometryElement').geometryElementWithData_primitiveType_primitiveCount_bytesPerIndex_(indices_data,0,1,4)
                                    elements = NSArray([SCNGeometryElement])
                                    
                                    geometry = ObjCClass('SCNGeometry').geometryWithSources_elements_(sources, elements)    	
                                

                                Fatal Python error: Aborted

                                Current thread 0x0000000100d62b80 (most recent call first):
                                File "/var/containers/Bundle/Application/E4751F4F-64A4-4BE6-AB9D-9C9564715002/Pythonista3.app/Frameworks/Py3Kit.framework/pylib/site-packages/objc_util.py", line 773 in call
                                File "/private/var/mobile/Containers/Shared/AppGroup/668A7D98-7216-47ED-917D-AA0B6173167E/Pythonista3/Documents/test6.py", line 51 in demo
                                File "/var/containers/Bundle/Application/E4751F4F-64A4-4BE6-AB9D-9C9564715002/Pythonista3.app/Frameworks/Py3Kit.framework/pylib/site-packages/objc_util.py", line 1066 in OMMainThreadDispatcher_invoke_imp

                                Thread 0x000000016fa5f000 (most recent call first):
                                File "/var/containers/Bundle/Application/E4751F4F-64A4-4BE6-AB9D-9C9564715002/Pythonista3.app/Frameworks/Py3Kit.framework/pylib/site-packages/objc_util.py", line 898 in call
                                File "/var/containers/Bundle/Application/E4751F4F-64A4-4BE6-AB9D-9C9564715002/Pythonista3.app/Frameworks/Py3Kit.framework/pylib/site-packages/objc_util.py", line 1095 in new_func
                                File "/private/var/mobile/Containers/Shared/AppGroup/668A7D98-7216-47ED-917D-AA0B6173167E/Pythonista3/Documents/test6.py", line 76 in <module>


                                Objective-C exception details:

                                NSInvalidArgumentException: -[SCNGeometrySource count]: unrecognized selector sent to instance 0x283276100

                                1 Reply Last reply Reply Quote 0
                                • JonB
                                  JonB last edited by JonB

                                  this works

                                  from ctypes import *
                                  from objc_util import *
                                  
                                  class SCNVector3(Structure):
                                      _fields_ = [('x', c_double), ('y', c_double), ('z', c_double)]
                                  
                                  verts=[SCNVector3(0, 0, 0), SCNVector3(1, 0, 0), SCNVector3(0, 1, 0)]
                                  
                                  SCNVector3Array3=SCNVector3 * len(verts)
                                  verts_array=SCNVector3Array3(*verts)
                                  SCNGeometrySource = ObjCClass('SCNGeometrySource')
                                  
                                  s=SCNGeometrySource.geometrySourceWithVertices_count_(byref(verts_array),len(verts),restype=c_void_p,argtypes=[POINTER(SCNVector3Array3), c_ulong],)
                                  
                                  cvp 1 Reply Last reply Reply Quote 0
                                  • cvp
                                    cvp @JonB last edited by

                                    @JonB Yes, but in my code,,the crash was in

                                        geometry = ObjCClass('SCNGeometry').geometryWithSources_elements_(sources, elements)    	
                                    
                                    1 Reply Last reply Reply Quote 0
                                    • cvp
                                      cvp @momorprods last edited by cvp

                                      @momorprods @JonB No crash with

                                          verts = [SCNVector3(0, 0, 0), SCNVector3(1, 0, 0), SCNVector3(0, 1, 0)]     
                                          SCNVector3Array3=SCNVector3 * len(verts)
                                          verts_array=SCNVector3Array3(*verts)
                                          SCNGeometrySource = ObjCClass('SCNGeometrySource')
                                          s = SCNGeometrySource.geometrySourceWithVertices_count_(byref(verts_array),len(verts),restype=c_void_p,argtypes=[POINTER(SCNVector3Array3), c_ulong],)
                                         
                                          indexes=[0,1,2]
                                          indexes_array = (c_ulong*len(indexes))(*indexes)
                                          datIndexes = ObjCClass('NSData').dataWithBytes_length_(indexes_array,len(indexes_array))
                                          # primitiveType = 0 for triangle
                                          # primitiveCount = 1  
                                          e = ObjCClass('SCNGeometryElement').geometryElementWithData_primitiveType_primitiveCount_bytesPerIndex_(datIndexes,0,1,4)
                                          
                                          geometry = ObjCClass('SCNGeometry').geometryWithSources_elements_([s],[e])
                                      	```
                                      
                                      Edit: but nothing visible
                                      1 Reply Last reply Reply Quote 0
                                      • cvp
                                        cvp @momorprods last edited by

                                        @momorprods I'm not sure if you should take in account the length of c_ulong
                                        Just an idea, rally not sure.
                                        Anyway, Scene stays blank 😢

                                            #indexes=[0,1,2]
                                            indexes = [c_ulong(0),c_ulong(1),c_ulong(2)]
                                            indexes_array = (c_ulong*len(indexes))(*indexes)
                                            #datIndexes = ObjCClass('NSData').dataWithBytes_length_(indexes_array, len(indexes_array))
                                            datIndexes = ObjCClass('NSData').dataWithBytes_length_(indexes_array, len(indexes_array)*sizeof(c_ulong))
                                            # primitiveType = 0 for triangle
                                            # primitiveCount = 1  
                                            #e = ObjCClass('SCNGeometryElement').geometryElementWithData_primitiveType_primitiveCount_bytesPerIndex_(datIndexes,0,1,4)
                                            e = ObjCClass('SCNGeometryElement').geometryElementWithData_primitiveType_primitiveCount_bytesPerIndex_(datIndexes,0,1,sizeof(c_ulong))
                                        
                                        1 Reply Last reply Reply Quote 0
                                        • momorprods
                                          momorprods last edited by

                                          @cvp @JonB thanks for your help, I am going to investigate that empty scene stuff.

                                          1 Reply Last reply Reply Quote 0
                                          • JonB
                                            JonB last edited by JonB

                                            dataWithBytes_length_ expects sizeof(verts_array)

                                            datIndexes = ObjCClass('NSData').dataWithBytes_length_(indexes_array,sizeof(indexes_array))
                                            

                                            as a check:

                                            geometry.geometryElements()[0].data()
                                            
                                            cvp 1 Reply Last reply Reply Quote 0
                                            • First post
                                              Last post
                                            Powered by NodeBB Forums | Contributors