Comments (2)
there is no main function in godot-python (this is because it's godot that decides which class should be loaded, then ask godot-python load the corresponding python file). So everything in you class's file will be executed and if you have a if name == "main": .... it will be skipped
but the question remains : how to stop godot python from autoexecuting every python script on start of the editor because its locking some of the features and hardware before the actual game can start.
I can put the aforementioned code behind if name == main but that stops it from being executed when the game starts.
Is there a way to do like if is_godot_engine == false : to lock some parts of code behind ?
My problem stems from need to block the execution of functions that im holding in a helper classes, so i dont know if i should to stuff all the class into the "if name" block.
also there is a weird bug that does not allow exporting the variables in the script to the editor, i cant put my finger on why.
let me post my script here to examine what is wrong with it :
from godot import exposed, export, ResourceLoader
from godot import *
import ctypes
import subprocess
import sys
import cv2
import depthai as dai
from depthaiHelpers import dai_pipeline as pipeline
from depthaiHelpers import dai_getCalibration as calib
from depthaiHelpers import cv2_tracking as tracking
import numpy as np
@exposed
class Main(Spatial):
# member variables here, example:
texture = ImageTexture()
material = export(SpatialMaterial)
pool_array = PoolByteArray()
sensor = pipeline.Oakd_pipeline(True,True,True,True)
sensor.setupPipeline()
print("main is being run")
frame, height, width, channels, size = None,None,None,None,None
def frame_to_godot_image(self, frame, height, width, channels, size):
print(width, height, channels)
image = Image()
with self.pool_array.raw_access() as ptr:
numpy_array = np.ctypeslib.as_array(ctypes.cast(ptr.get_address(), ctypes.POINTER(ctypes.c_uint8)), (size,))
numpy_array[:] = np.frombuffer(frame, dtype=np.uint8).reshape((height,width)[::-1]+(channels,)).flatten()
image.create_from_data( width, height, False, Image.FORMAT_RGB8, self.pool_array)
return image
def _ready(self):
print("YEllo")
frame = self.sensor.getColorFrames()
self.height, self.width, self.channels = frame.shape
self.size = self.width * self.height * self.channels
self.pool_array.resize(self.size)
#if self.material is not None:
# self.material.albedo_texture = self.texture
def _process(self,delta):
frame = self.sensor.getColorFrames()
image = self.frame_to_godot_image(frame,self.height, self.width, self.channels, self.size)
self.texture.create_from_image(image)
self.material.emission_texture = self.texture
EDIT:
After some tinkering ive managed to understand what You've meant and moved all the functional code to the def _ready: and def _process: to avoid premature actions.
from godot-python.
Hi @TheBricktop
You are talking about Godot editor, so you know there is multiple way Godot run a project:
- Godot running the game (i.e. calling something like
godot --path path/to/my/project/
) this is typically the way you run in production. In this mode there is no Godot editor running. - Godot editor running (i.e. calling
godot --python path/to/my/project --editor
) this time you are not running your game but the project of your game (remember the Godot editor is actually a Godot game !). So in this mode your python code is not running given you're not running your game (unless you mark a class astool
then the class will run only in the editor and not when running the game) - Godot editor running the game. This is typically the debug mode when hitting F5 in the editor. Each time you do that you create a new process that will run the game.
So I advice you to make sure you are not by mistake running multiple instance of the python code that would then fight over connecting to your camera...
The possible culprit might be that godot language server runs through all of the init and main functions in provided
there is no main function in godot-python (this is because it's godot that decides which class should be loaded, then ask godot-python load the corresponding python file). So everything in you class's file will be executed and if you have a if __name__ == "__main__": ....
it will be skipped
from godot-python.
Related Issues (20)
- Installing packages only shows "requirement already satisfied " but points to global python installation HOT 2
- [Godot 4] Better numpy support for image / np.arrays HOT 2
- Best way to display the texture produced in python on a spatial material HOT 4
- Adding Custom Icons to Classes for Nodes HOT 2
- Test project crashes while loading methods (invalid pointer) HOT 2
- impossible to use wandb. HOT 1
- Build failure
- Cant set shader parameter on custom visual shader
- get_children() not working when Label3D is a child. HOT 1
- Question - Embedded Application HOT 2
- Path incorrect for godot-headers HOT 6
- Pass or return Python instance to/from Godot
- How to access nodes from the tree.
- Segmentation fault while using matplotlib under Linux
- make.py initialization fails
- godot3 export python problem HOT 2
- trying on fedora linux HOT 4
- PythonJIT like LuaJIT.
- GDExtension HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from godot-python.