Incorrect display of my 3D model with Panda3D - python

I'm trying to use Panda3D to make a 3D game with Python. I used Blender to make a 3D model for the player, and gave it some animations and a green texture. It looks like this:
Then I exported it in .gltf Embedded, using default presets.
Finally, I tried using this code to display the model:
import panda3d.core as p3d
from direct.showbase.ShowBase import ShowBase
from direct.actor.Actor import Actor
class Game(ShowBase):
def __init__(self, model_path):
ShowBase.__init__(self)
# Load my model
self.player = Actor(model_path)
# Add player to scene
self.player.reparentTo(self.render)
if __name__ == "__main__":
model_path = "player_model.gltf"
# Create the game instance
game = Game(model_path)
game.run()
However, the model looks completely wrong:
I also get these warnings:
Known pipe types:
wglGraphicsPipe
(all display modules loaded.)
:Actor(warning): player_model.gltf is not a character!
:linmath(warning): Tried to invert singular LMatrix4.
:linmath(warning): Tried to invert singular LMatrix4.
...
:linmath(warning): Tried to invert singular LMatrix4.
How can I fix the problem? Is there something wrong with how I am exporting the model?
I was able to import a basic cube model with the same process and got the expected result. Is the problem perhaps caused by armature or animations?

Related

When using Augmentations in Detectron2 are Bounding Boxes transformed automatically?

I'm currently trying to implement Augmentations in Detectron2 and my code is looking like this:
class AugmentationTrainer(DefaultTrainer):
#classmethod
def build_train_loader(cls, cfg):
mapper = DatasetMapper(cfg, is_train=True,augmentations=[
T.RandomBrightness(0.5,1.5),
T.RandomContrast(2, 2),
T.RandomSaturation(2 ,2),
T.RandomFlip(prob=1, horizontal=True, vertical=False),
T.RandomFlip(prob=0.5, horizontal=False, vertical=True),
])
return build_detection_train_loader(cfg, mapper = mapper)
I'm simply using this class as a Trainer instead of the Default one. I was wondering if the bounding box data gets changed properly using this, when using Augmentations like Flip or Rotate for example.
Thanks in Advance!
I trained with the above augmentations, but my end result was worse than the training without augmentations, which confused me a lot.

How can I play an animation from a non-Scene class using manim?

I was trying to do a Neural Network animation, and I found a class online, which I modified to suit my needs. Basically, the class looks like:
class NeuralNetworkMobject(VGroup):
...
...
def change_edge_color(...):
edge = random.choice(n1.edges_out) # n1.edges_out is a VGroup, and edge is Line
# I want to play the edge fade in animation from this method.
# I've tried to do:
NeuralNetworkScene.play(FadeIn(edge)) # NeuralNetworkScene is the actual scene
But, the program gives an error, saying that:
File "neural.py", line 171, in set_neuron_edge_color
NeuralScene.play(FadeIn(n_edge))
File "/usr/local/lib/python3.9/site-packages/manimlib/scene/scene.py", line 845, in wrapper
self.update_skipping_status()
AttributeError: 'FadeIn' object has no attribute 'update_skipping_status'
How can I play an animation form a non-Scene class?
Thanks,
So I tried everything I can, including instantiating the main scene and then trying to play the animation (which you obviously shouldn't) to directly accessing the Scene.play() method (which didn't work either). So, as a solution I came up with:
class MainScene(Scene):
def construct(self):
...
neurons = NeuralNetworkMobject()
your_animation_function(neurons)
def your_animation_function(self, neurons):
self.play(FadeIn(neurons))
...
While this approach does solve the problem, just for curiosity I am asking that is it possible to play an animation from a non-Scene class?
Thanks,

how to make python ursina engine's cube texture

I am wondering about how to make a simple cube texture in the Python Panda3D wrapper, ursina engine library.
Here's the code that I have tried.
from ursina import *
app = Ursina()
window.fps_counter.enabled = False
class Voxel(Button):
def __init__(self, position=(0,0,0), texture='red.png'):
super().__init__(
parent = scene,
position=position,
model='cube',
origin_y=0.5,
texture=texture,
color=color.color(0,0, random.uniform(0.9, 1.0)),
scale = 1.0
)
for x in range(3):
for y in range(3):
for z in range(3):
voxel = Voxel(position=(x,y,z))
EditorCamera()
app.run()
I want to know how to make uv map ( one that I made is really bad ).
I want to know convert uv map to ursina engine cube texture.
Built in textures are great for Ursina Voxel engines. They include:
'arrow_down'
'arrow_right'
'brick'
'circle'
'circle_outlined'
'cobblestone'
'cursor'
'file_icon'
'folder'
'grass'
'heightmap_1'
'horizontal_gradient'
'noise'
'radial_gradient'
'reflection_map_3'
'shore'
'sky_default'
'sky_sunset'
'ursina_logo'
'ursina_wink_0000'
'ursina_wink_0001'
'vertical_gradient'
'white_cube'
They are all great textures. But if you don't want to use built in textures, use a .jpg .psd or .png file, but without the file extension.
e.g.
My_Image.png would be imported as...
Entity(model=cube,
texture='My_Image')
If you have multiple files that have the same name but different file extensions,
e.g.
My_Image.png
and
My_Image.jpg
and both of them are compatible, it will use the first file in the directory.
I hope this helps. If so, please approve this so others can see that it works. It worked for me and I hope this improves your programs!
There is no such thing as ursina specific textures. When importing a texture, just use texture='cool_file' without the extension (.jpg, .png and .psd). Ursina currently supports png, jpeg and psd images (the psd-tools library must be installed since it isn't by default).
If you want to do uv mapping, you need to directly do it in a 3D software (e.g. Blender), and just import the model.

custom animation in ursina engine

I am trying to play my own animation in the ursina engine but I have no idea how to. According to the documentation, I would need this code:
from ursina import *
app = Ursina()
window.color = color._20
animation = Animation('ursina_wink', fps=2, scale=1, filtering=None, autoplay=True)
EditorCamera()
app.run()
And that one does indeed work. However, I do not understand how I can replace the default animation with my own frames ('ursina_wink' is inbuilt).
The documentation says there is a frame parameter, so here is what I tried so far:
from ursina import *
app = Ursina()
window.color = color._20
coin1 = load_texture('animation/coin1')
coin2 = load_texture('animation/coin2')
coin3 = load_texture('animation/coin3')
coin4 = load_texture('animation/coin4')
coin5 = load_texture('animation/coin5')
coin6 = load_texture('animation/coin6')
animation = Animation('test',fps=2, scale=1, filtering=None, autoplay=True, frames = (coin1, coin2,coin3,coin4,coin5,coin6))
EditorCamera()
app.run()
But I cannot see anything on the screen and I cannot find an example online for it. Would really appreciate some help.
It loads an image sequence as a frame animation. You can load it like this:
Animation('coin') and it will take all the frames starting with 'coin' and load them alphabetically.
I will clarify this in the documentation.
I have come across your error and I have a simple solution, try to convert the images into a gif because in the ursina documentation it says that you can also use a gif wich is way more simple but less customizable, here's the text:
Loads an image sequence as a frame animation.
Consider using SpriteSheetAnimation instead if possible.
So if you have some frames named image_000.png, image_001.png, image_002.png and so on,
you can load it like this: Animation('image')
You can also load a .gif by including the file type: Animation('image.gif')
So, I hope this helped you.

Changing Screen Resolution of Computer using python

I'm creating a python program that is supposed to streamline the process of setting up a computer. I want this python program to change the screen resolution of the computer and scaling of it. I'm not sure what the best approach is however, or how to approach it.
I've tried using an example pywin32 program, but it only outputted an array of resolution sizes
I had a look how to change screen resolution using C++ and then translated it to Python:
import win32api
import win32con
import pywintypes
devmode = pywintypes.DEVMODEType()
devmode.PelsWidth = 1366
devmode.PelsHeight = 768
devmode.Fields = win32con.DM_PELSWIDTH | win32con.DM_PELSHEIGHT
win32api.ChangeDisplaySettings(devmode, 0)
We needed a DEVMODE object to pass to the ChangeDisplaySettings function. The pywintypes module which is also part of pywin32 has a function to create objects of type DEVMODE.
We then set the PelsWidth and PelsHeight fields and also the Fields field to tell the API which field's values we want to use.
To change back to the previous resolution, simply call:
win32api.ChangeDisplaySettings(None, 0)
Thanks for asking the question. I've learned something.

Categories

Resources