• @JonB : Simple...Thank you!

  • @Brun0oO, I have been using this bottle server to be my cleanly exiting threaded web server, for quite a while now, without issues.

  • @dgelessus : you're right ! I've extracted objc_util.py from my current Pythonista and have copied it to the XCode Template project (PythonistaAppTemplate/PythonistaKit.framework/pylib/site-packages directory ). Now, I can test my app :o)

    @JonB : I don't need to add the framework I want to load in my xcode project. I've removed the framework in the xcode project and my app can be launched without any problem...Perhaps as it's an Apple framework, I don't need to add it....My xcode knowledge is a little low ;o)

    Thank you for your help...

  • Hi,
    Finally, I managed to initialize an ar session
    but I remain open to any improvement (
    especially the famous ARKit constants and the call to the sleep function ;o)

    Here the code :

    # coding: utf-8 import objc_util from objc_util import * import ui import os import sys #from myDebugToolKit import * import time from enum import IntFlag load_framework('SceneKit') load_framework('ARKit') # Some 'constants' used by ARkit # But i can't transfer them to the ARKit framework, why ????? class ARWorldAlignment(IntFlag): ARWorldAlignmentGravity = 0 ARWorldAlignmentGravityAndHeading = 1 ARWorldAlignmentCamera = 2 class ARPlaneDetection(IntFlag): ARPlaneDetectionNone = 0 ARPlaneDetectionHorizontal = 1 << 0 ARPlaneDetectionVertical = 1 << 1 # Work In Progress here, I'm deciphering the ARKit constants... #class ARSCNDebugOption(IntFlag): # ARSCNDebugOptionNone = 0 # ARSCNDebugOptionShowWorldOrigin = int("ffffffff80000000", 16) # ARSCNDebugOptionShowFeaturePoints = int("ffffffff40000000", 16) class ARSessionRunOptions(IntFlag): ARSessionRunOptionsNone = 0 ARSessionRunOptionResetTracking = 1 << 0 ARSessionRunOptionRemoveExistingAnchors = 1 << 1 NSError = ObjCClass('NSError') SCNScene = ObjCClass('SCNScene') ARSCNView = ObjCClass('ARSCNView') ARWorldTrackingConfiguration = ObjCClass('ARWorldTrackingConfiguration') ARSession = ObjCClass('ARSession') UIViewController = ObjCClass('UIViewController') ARPlaneAnchor = ObjCClass('ARPlaneAnchor') # I should refactor te following line in a class but I need to learn more the create_objcc_class function sceneview = None # Here some set up functions used by the main class def createSampleScene(): # an empty scene scene = SCNScene.scene() return scene def setDebugOptions(arscn): # Work In Progress Here, I'm trying to decipher the arkit constants... #val = ARSCNDebugOption.ARSCNDebugOptionShowWorldOrigin | ARSCNDebugOption.ARSCNDebugOptionShowFeaturePoints val = int("fffffffffc000000", 16) # this value is a combination of ShowWorldOrigin and ShowFeaturePoints flags, but I can't isolate each flags.... print('Before calling setDebugOptions_(%s) : debugOptions=%s' %(hex(val), hex(arscn.debugOptions()))) arscn.setDebugOptions_(val) print('After calling setDebugOptions_(%s) : debugOptions=%s' % (hex(val),hex(arscn.debugOptions()))) def createARSceneView(x, y, w, h, debug=True): v = ARSCNView.alloc().initWithFrame_((CGRect(CGPoint(x, y), CGSize(w, h)))) v.setShowsStatistics_(debug) # I love statistics... return v # Some callback definitions used by create_objc_class def CustomViewController_touchesBegan_withEvent_(_self, _cmd, _touches, event): touches = ObjCInstance(_touches) for t in touches: loc = t.locationInView_(sceneview) sz = ui.get_screen_size() print(loc) @on_main_thread def runARSession(arsession): arconfiguration = ARWorldTrackingConfiguration.alloc().init() arconfiguration.setPlaneDetection_ (ARPlaneDetection.ARPlaneDetectionHorizontal) arconfiguration.setWorldAlignment_(ARWorldAlignment.ARWorldAlignmentGravity) # I do not use ARWorldAlignmentGravityAndHeading anymore because on my device, sometimes it fails to initialize the ar session because of an unitialized sensor (error 102). I think my magnetic phone casing plays tricks on me... arsession.runWithConfiguration_options_(arconfiguration, ARSessionRunOptions.ARSessionRunOptionResetTracking | ARSessionRunOptions.ARSessionRunOptionRemoveExistingAnchors ) time.sleep(0.5) # Let the system breathe ;o) Ok, that's the workarround I found to retrieve the ar session configuration (otherwise I got None).... print('configuration',arsession.configuration()) # Very usefull for the debuging (at least for me !) def CustomViewController_viewWillAppear_(_self, _cmd, animated): return def CustomViewController_viewWillDisappear_(_self, _cmd, animated): session = sceneview.session() session.pause() def MyARSCNViewDelegate_renderer_didAdd_for_(_self, _cmd, scenerenderer, node, anchor): if not isinstance(anchor, (ARPlaneAnchor)): return # to be implemented... def MyARSCNViewDelegate_session_didFailWithError_(_self,_cmd,_session,_error): print('error',_error,_cmd,_session) err_obj=ObjCInstance(_error) print(err_obj) # Again, very usefull for the debuging... # The main class... class MyARView(ui.View): def __init__(self): super().__init__(self) @on_main_thread def initialize(self): global sceneview self.flex = 'WH' screen = ui.get_screen_size() # set up the scene scene = createSampleScene() # set up the ar scene view delegate methods = [MyARSCNViewDelegate_renderer_didAdd_for_,MyARSCNViewDelegate_session_didFailWithError_] protocols = ['ARSCNViewDelegate'] MyARSCNViewDelegate = create_objc_class('MyARSCNViewDelegate', NSObject, methods=methods, protocols=protocols) delegate = MyARSCNViewDelegate.alloc().init() # set up the ar scene view sceneview = createARSceneView(0, 0, screen.width, screen.height) sceneview.scene = scene sceneview.setDelegate_(delegate) # set up the custom view controller methods = [CustomViewController_touchesBegan_withEvent_, CustomViewController_viewWillAppear_, CustomViewController_viewWillDisappear_] protocols = [] CustomViewController = create_objc_class('CustomViewController', UIViewController, methods=methods, protocols=protocols) cvc = CustomViewController.alloc().init() cvc.view = sceneview # internal scheming... self_objc = ObjCInstance(self) self_objc.nextResponder().addChildViewController_(cvc) self_objc.addSubview_(sceneview) cvc.didMoveToParentViewController_(self_objc) # here, we try... runARSession(sceneview.session()) # I call here this function because I'm trying to find the best place to run the ar session... setDebugOptions(sceneview) # I call here this function because I'm trying to find the best place to set the debuging options.... def will_close(self): session = sceneview.session() session.pause() if __name__ == '__main__': v = MyARView() v.present('full_screen', hide_title_bar=True, orientations=['portrait']) v.initialize()

    Note: if someone can correct the autorotate, I'm also interested !o)
    Edit: I found a solution for my autorotate problem -> I turn it off ;o)

    Live session

  • Ok... I found my error and as always, the solution was in front of my eyes...
    I was certain to deal with a variable not a method.
    If I got an ObjCIntanceMethodProxy class instance, i got the address of a method not a variable so I need to put () characters...

    Brun0oO
    .. in search of arkit integration...

  • As I took the wrong direction, I close this topic.

    Brun0oO

  • @bennr01 said:

    @Brun0oO If you only need websockets, you could also use Autobahn|Python, which runs on asyncio and/or Twisted.

    That's the solution, thank you !!

    In order to install autobahn, i did under Stash "pip install zope.interface".
    As "pip install twisted" failed, i downloaded the twisted code source and moved manually the twisted package to the site-packages folder. Then, i performed a "pip install autobahn".

    Here the code for the websocket server websocket-server.py:

    from autobahn.asyncio.websocket import WebSocketServerProtocol, \ WebSocketServerFactory import socket def get_local_ip_addr(): # Get the local ip address of the device s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) # Make a socket object s.connect(('8.8.8.8', 80)) # Connect to google ip = s.getsockname()[0] # Get our IP address from the socket s.close() # Close the socket return ip # And return the IP address class MyServerProtocol(WebSocketServerProtocol): def onConnect(self, request): print("Client connecting: {0}".format(request.peer)) def onOpen(self): print("WebSocket connection open.") def onMessage(self, payload, isBinary): if isBinary: print("Binary message received: {0} bytes".format(len(payload))) else: print("Text message received: {0}".format(payload.decode('utf8'))) # echo back message verbatim self.sendMessage(payload, isBinary) def onClose(self, wasClean, code, reason): print("WebSocket connection closed: {0}".format(reason)) if __name__ == '__main__': try: import asyncio except ImportError: # Trollius >= 0.3 was renamed import trollius as asyncio factory = WebSocketServerFactory(u"ws://127.0.0.1:9000") factory.protocol = MyServerProtocol loop = asyncio.get_event_loop() coro = loop.create_server(factory, '0.0.0.0', 9000) server = loop.run_until_complete(coro) print("Server started at {0}:{sock[1]}".format(get_local_ip_addr(),sock=server.sockets[0].getsockname())) try: loop.run_forever() except KeyboardInterrupt: pass finally: server.close() loop.close()

    The code for the websocket client is the same as the previous one.

    Brun0oO

  • Actually, I'm doing this :

    ... w, h = ui.get_screen_size() main_view = ui.View() main_view_objc = ObjCInstance(main_view) left_scene_view = SCNView.alloc().initWithFrame_options_(((0,0), (w,h/2)), None).autorelease() ... main_view_objc.addSubView_(left_scene_view) main_view.present("fullscreen", hide_title_bar=True) ...

    but i still have the status bar (but the title bar with the close button is hidden), what code can i add to hide this bar?

    Bruno

Internal error.

Oops! Looks like something went wrong!