Skip to content

Instantly share code, notes, and snippets.

# pySDL3 is required, install with:
# pip install PySDL3
# Free Flight FreeCAD demo. Navigate scene with mouse and keyboard
# Bindings:
# mouse: yaw and pitch
# Q/E - roll, W/S - forward/backward, A/D - sidestep left/right, Ctrl/Space - down/up
# note: proper threading/concurrency not completed, adjust sleep in self._running loop if segfaults
# note: background color and lights copying from main view not implemented yet
# moves selected shape along predefined path, and creates a 3D picking ray along object's Z axis
# solid should be outside 0-Z+ to avoid self-picking
# the ray picks another object in predefined location (waypoint changing from (plecement, False) to (placement, True)) and drags it
from pivy.coin import SbVec3f, SbRotation
from pivy.coin import SoTranslation
from pivy.coin import SoSeparator, SoSwitch, SO_SWITCH_ALL, SO_SWITCH_NONE
from pivy.coin import SoVertexProperty, SoLineSet, SoSphere
from pivy.coin import SoBaseColor, SbColor
#!/bin/sh
set -e
# Steam Deck UNOFFCIAL Tilt Five install script
# Save to a directory with the tiltfive_driver_1.4.1_amd64.unpacked_debs.tar.xz archive
# chmod +x steamdeck-install.sh
# sudo sh ./steamdeck-install.sh
# Adjust paths if necessary
TILTFIVE_HOME_DIR="/var/opt/tiltfive"
import FreeCADGui as Gui
import FreeCAD as App
import Part
def pick_ray(start_vec, dir_vec):
Gui.Selection.clearSelection()
if App.ActiveDocument.getObject('Line_dir'):
App.ActiveDocument.removeObject('Line_dir')
if App.ActiveDocument.getObject('Line_ray'):
App.ActiveDocument.removeObject('Line_ray')
@kwahoo2
kwahoo2 / framebuffer_test.py
Last active November 27, 2024 18:48 — forked from vug/framebuffer_test.py
Trying Frame buffer objects in PyOpenGL
import numpy as np
from OpenGL.GL import *
WINDOW_LIBRARY = 'GLFW' # GLFW or GLUT
TRY_FRAMEBUFFER = True
GENERATE_TEXTURE_ID_PROBLEM = False # Follow this global variable to see the error in texture ID generation
SIDE = 800 # window size
@kwahoo2
kwahoo2 / soenvfc.py
Last active October 28, 2024 17:15
SoEnvironment usage in FreeCAD scene
# SoEnvironment usage in FreeCAD scene
# https://www.coin3d.org/coin/classSoEnvironment.html
# https://forum.freecad.org/viewtopic.php?p=785643#p785643
from pivy.coin import SoEnvironment
se = SoEnvironment() # create a new node
sg = Gui.ActiveDocument.ActiveView.getSceneGraph()
sg.insertChild(se, 1) # add the node at the beginning of our scene
se.ambientIntensity.getValue() # read value for current ambient light eg.: 0.2
se.ambientIntensity.setValue(0.8) # set a new value for ambient light, can be higher than 1 too, since it is multiplied by AmbientColor property of a material
@kwahoo2
kwahoo2 / gamepad-navigation.py
Created October 20, 2024 21:42
Python script for navigating FreeCAD view with a gamepad
# move FreeCAD camera with a gamepad
import ctypes
import time
from sdl2 import *
from pivy.coin import SbVec3f, SbRotation
from PySide import QtCore
from math import pi
import FreeCAD as App, FreeCADGui as Gui, time
from PySide2 import QtGui,QtCore
class Animation(object):
def __init__(self):
App.Console.PrintMessage("init \n")
App.ActiveDocument.recompute()
self.timer = QtCore.QTimer()
QtCore.QObject.connect(self.timer, QtCore.SIGNAL("timeout()"), self.my_update)
self.timer.start(100) #100ms for step, adjust to performance of the PC
import FreeCAD as App, FreeCADGui as Gui, Part, time
from PySide2 import QtGui,QtCore
from pivy import coin
import math
class CustomArrow(object):
def __init__(self):
self.cyl_height = 6
cyl_radius = 3
@kwahoo2
kwahoo2 / sdl-example-coin-test.py
Created August 23, 2023 21:18
Paste in FreeCAD console to get OpenXR viewer
# based on gl_example.py https://github.com/cmbruns/pyopenxr_examples
import ctypes
import logging
from threading import Thread
import sdl2
import platform
from OpenGL import GL