Загрузка файла PywavefrontPython

Программы на Python
Anonymous
Загрузка файла Pywavefront

Сообщение Anonymous »

В своем коде я пытался всеми возможными способами заставить мой файловый каталог работать, но этого не произошло, я искал в Интернете, менял местоположение и даже пробовал это на другом компьютере, но это никогда не получалось. сработало.
Вот мой основной импорт объектов:
spawn_planet_model = pywavefront.Wavefront(r"C:\Users\piyus\Music\Aayan\Blender & Coding\Blender\spawn_planet.obj")
male_player_1_model = pywavefront.Wavefront(r"C:\Users\piyus\Music\Aayan\Blender & Coding\Blender\male_player_1.obj")
workbench_model = pywavefront.Wavefront(r"C:\Users\piyus\Music\Aayan\Blender & Coding\Blender\workbench.obj")

А позже я дам вам код. Другая проблема заключается в том, что функция под названием «GLUT_BITMAP_HELVETICA_18» была подчеркнута красным, что означало, что в ней возникла ошибка.
Вот часть кода, в которой она была:def render_text(text, x, y):
gl.glRasterPos2f(x, y)
for c in text:
glut.glutBitmapCharacter(glut.GLUT_BITMAP_HELVETICA_18, ord(c))

Я пробовал много чего, но теперь просто сдаюсь, поэтому вот мой код:
import OpenGL.GL as gl
import OpenGL.GLU as glu
import OpenGL.GLUT as glut
from OpenGL.GL.shaders import compileProgram, compileShader
import pywavefront
import math
import time
from PIL import Image
import numpy as np
import random
import datetime
import cv2

# Load models
spawn_planet_model = pywavefront.Wavefront(r"C:\Users\piyus\Music\Aayan\Blender & Coding\Blender\spawn_planet.obj")
male_player_1_model = pywavefront.Wavefront(r"C:\Users\piyus\Music\Aayan\Blender & Coding\Blender\male_player_1.obj")
workbench_model = pywavefront.Wavefront(r"C:\Users\piyus\Music\Aayan\Blender & Coding\Blender\workbench.obj")

# Player position and movement variables
player_head_x = -100.0
player_head_y = 1.0
player_head_z = 0.0
ground_level = 0.0

# Player orientation (yaw, pitch for looking around)
yaw_angle = 0.0
pitch_angle = 0.0
look_distance = 10.0

# Movement keys
keys = {b'w': False, b'a': False, b's': False, b'd': False, b' ': False, b'\x1b': False}

# Movement dynamics
move_speed = 0.0
strafe_speed = 0.0
max_speed = 2.0
acceleration = 0.02
deceleration = 0.04
sprint_speed = 4.0
is_sprinting = False

# Mouse control (viewing angle)
last_mouse_x = 0
last_mouse_y = 0
mouse_sensitivity = 0.004

# Sprint window for double press
last_w_press_time = 0
sprint_window = 0.3 # 300ms for double press

# Crouching mechanics
is_crouching = False
crouch_height = 0.6
normal_height = 1.0
crouch_speed = 0.04

# Gravity and jump mechanics
gravity_force = 12.0
vertical_velocity = 0.0
is_jumping = False
jump_velocity = 0.30

# Overlay and UI variables
overlay_active = False # Controls whether the chat overlay is active
chat_open = False # If chat is open for typing
typed_message = "" # Stores the current typed message
window_width = 1920
window_height = 1080

# Limits for camera view
MAX_PITCH = math.pi / 2
MIN_PITCH = -math.pi / 2

frame_interval = int(1000 / 45)

# Chat system and storage
max_storage_size = 5 * 1024 * 1024 # 5MB in bytes
chat_cache_1 = []
chat_cache_2 = []
chat_cache_3 = []
chat_messages = [] # Main chat storage
active_cache = chat_messages

# Cache switching mechanism when storage reaches 5MB
def switch_cache_if_full():
global chat_cache_1, chat_cache_2, chat_cache_3, active_cache
current_size = sum(len(msg) for msg in active_cache)

if current_size >= max_storage_size:
if active_cache is chat_messages:
active_cache = chat_cache_1
elif active_cache is chat_cache_1:
active_cache = chat_cache_2
elif active_cache is chat_cache_2:
active_cache = chat_cache_3
else:
active_cache = chat_messages # Circle back to the first cache

# Remove oldest cache if all caches are full
if sum(len(msg) for msg in chat_cache_3) >= max_storage_size:
chat_cache_1.clear()
chat_cache_2.clear()
chat_cache_3.clear()

def handle_chat_input():
global chat_open, typed_message
if chat_open:
# Add typed message to chat messages and clear input
if typed_message:
chat_messages.append(typed_message)
typed_message = ""
chat_open = False

def render_chat():
gl.glColor3f(1.0, 1.0, 1.0) # White color for text
chat_display_messages = chat_messages[-3:] # Get the last 3 messages

# Display each message
y_offset = -0.8
for message in chat_display_messages:
# Render each message at the specified position
render_text(message, window_width / 2, window_height * (y_offset + 0.2))
y_offset += 0.1

def render_text(text, x, y):
gl.glRasterPos2f(x, y)
for c in text:
glut.glutBitmapCharacter(glut.GLUT_BITMAP_HELVETICA_18, ord(c))

# Keyboard input handling
def key_down(key, x, y):
global keys, chat_open, typed_message

keys[key] = True

if key == b'\r': # Enter key
if chat_open:
handle_chat_input()
else:
chat_open = True

if chat_open and key >= b' ' and key

Подробнее здесь: https://stackoverflow.com/questions/790 ... le-loading

Вернуться в «Python»