I have a python program that is running on ursina. When I run it on Windows, I get no errors at all, but now that I am running it on Linux, it is saying:
Traceback (most recent call last):
File "main.py", line 233, in <module>
car.collider = MeshCollider(car, mesh=car.model, center=Vec3(0,0,0))
File "/home/prashun/.local/lib/python3.8/site-packages/ursina/collider.py", line 73, in
__init__
if mesh.triangles:
AttributeError: 'NoneType' object has no attribute 'triangles'
I think this has something to do with the mesh collider not working. Is there any way I can fix this?
I could show the related code but it is long, and the code is the exact same on both.
Nonetheless, here is the code if itll help:
# Main Import
from ursina import *
# First Person Camera Import (Not used for real gameplay, only dev
test)
# from ursina.prefabs.first_person_controller import
FirstPersonController
# Import mesh
from ursina.mesh_importer import *
# Import Textures hopefully
from ursina.texture import *
# Import camera
from ursina import camera
# Import Entity (used for any entity sytems in use)
from ursina.entity import Entity
# Import math (used for trig, alg, calc functions inside of the
physics system)
# import math
# Import Time (used for controlling time and vsync of framerate)
# Import lighting shader (not used at moment)
# from ursina.shaders import basic_lighting_shader
# Import Procedural Terrain Generation System
# import ursina.models.procedural.terrain
# Import Text
# import ursina.text
# Import the raycasting system
from ursina.raycaster import *
app = Ursina()
# Classes
class PoliceCar(Entity):
def __init__(self, position=(100, 0, 100)):
super().__init__(
parent=scene,
position=position,
model=PoliceCarModel,
origin_y=0.5,
texture='white_cube',
rotation=Vec3(180, 0, 0),
a=0,
s=0,
accdg=0,
velocity=0,
det_range=1,
)
def gravity(self, grav):
self.accdg += grav
self.y += self.accdg
if self.y <= 0:
self.accdg = 0.01
def chase(self):
print(self.rotation_x, self.rotation_y, self.rotation_z)
ray = raycast(self.position, direction=(0, 0, 0),
distance=self.det_range, traverse_target=scene, ignore=list(),
debug=False)
if ray.hit:
print("hit!")
class Car(Entity):
def __init__(self, position=(0, 10, 0)):
super().__init__(
parent=scene,
position=position,
model=car,
origin_y=0.5,
texture='white_cube',
rotation=Vec3(180, 0, 0),
a=0,
s=0,
accdg=0,
velocity=0,
state=1,
)
def gravity(self, grav):
self.accdg += grav
self.y += self.accdg
if self.y <= 0:
self.accdg = 0.01
class Voxel(Button):
def __init__(self, position=(0, 0, 0)):
super().__init__(
parent=scene,
position=position,
model='cube',
origin_y=0.5,
texture='white_cube',
scale=(10, 1, 10)
)
class GameClass:
def __init__(self):
self.game = 0
class StartGame(Button):
def __init__(self):
super().__init__(
parent=scene,
model='cube',
texture='white_cube',
)
gameclass = GameClass()
gameclass.game = 1
if gameclass.game == 0:
startbutton = StartGame()
if startbutton.hovered and key == 'left mouse down':
print("button pressed")
gameclass.game = 1
quit()
if gameclass.game == 1:
car = load_model('Graphics/Car_graphics/CarVersion2', path=application.asset_folder)
PoliceCarModel = load_model('Graphics/Police_graphics/PoliceCarVersion1', path=application.asset_folder)
# sky_texture = load_texture('Graphics/skybox', path=None)
# Terrain = Entity(model=Terrain('heightmap_1', skip=2), scale=(20,5,20), texture='heightmap_1')
window.title = 'Millwoods Version 1.0 - 3D'
window.borderless = False
window.fullscreen = False
window.exit_button.visible = True
window.fps_counter.enabled = True
window.vsync = False
def update():
# Car Physics
def car_physics():
car.gravity(-0.01)
if car.rotation_y > 360:
car.rotation_y -= 360
z = car.velocity * math.cos(car.rotation_y * 3.14159 / 180)
x = car.velocity * math.sin(car.rotation_y * 3.14159 / 180)
car.x += x
car.z += z
cameraz = -30 * math.cos(car.rotation_y * 3.14159 / 180)
camerax = -30 * math.sin(car.rotation_y * 3.14159 / 180)
camera.position = (car.x + camerax, car.y +5, car.z + cameraz)
camera.rotation_y = car.rotation_y
if car.state == 4:
if held_keys['w']:
r = car.rotation_y
car.velocity += 0.05
if held_keys['a']:
if car.velocity > 0 or car.velocity < 0:
car.rotation_y -= 5
if held_keys['d']:
if car.velocity > 0 or car.velocity < 0:
car.rotation_y += 5
if held_keys['s']:
if car.velocity > 0:
car.velocity -= 0.05
elif car.velocity < 0:
car.velocity += 0.05
else:
pass
if car.state == 3:
if held_keys['w']:
pass
if held_keys['a']:
if car.velocity > 0 or car.velocity < 0:
car.rotation_y -= 5
if held_keys['d']:
if car.velocity > 0 or car.velocity < 0:
car.rotation_y += 5
if held_keys['s']:
if car.velocity > 0:
car.velocity -= 0.05
elif car.velocity < 0:
car.velocity += 0.05
else:
pass
if car.state == 2:
if held_keys['w']:
car.velocity -= 0.05
if held_keys['a']:
if car.velocity > 0 or car.velocity < 0:
car.rotation_y -= 5
if held_keys['d']:
if car.velocity > 0 or car.velocity < 0:
car.rotation_y += 5
if held_keys['s']:
if car.velocity > 0:
car.velocity -= 0.05
elif car.velocity < 0:
car.velocity += 0.05
else:
pass
if car.state == 1:
pass
if held_keys['1']:
car.state = 1
if held_keys['2']:
car.state = 2
if held_keys['3']:
car.state = 3
if held_keys['4']:
car.state = 4
def inertia():
if car.velocity > 0:
car.velocity -= 0.005
if car.velocity < 0:
car.velocity += 0.005
inertia()
def police_car_physics():
policeCar1.gravity(-0.01)
policeCar1.chase()
police_car_physics()
car_physics()
t = Text(text='Car Speed: ' + str(float(car.velocity*10)), scale=1, origin=(4, 10))
t.update_text()
print(car.velocity*10, car.state)
for z in range(20):
for x in range(20):
voxel = Voxel(position = (x*10, 0, z*10))
car = Car()
policeCar1 = PoliceCar()
car.collider = MeshCollider(car, mesh=car.model, center=Vec3(0,0,0))
# sky = Sky()
# person = FirstPersonController()
app.run()
question from:
https://stackoverflow.com/questions/65864791/ursina-doesnt-work-on-linux-but-it-does-on-windows