Mesh duplication

This commit is contained in:
Dane Johnson 2021-01-23 13:00:08 -06:00
parent 5e8e7b3ce0
commit 59da3c088f
7 changed files with 51 additions and 1 deletions

View File

@ -51,6 +51,11 @@ Mesh::~Mesh() {
} }
} }
Mesh *Mesh::Duplicate() {
Mesh *dup = new Mesh(*this);
return dup;
}
void Mesh::SetupMesh() { void Mesh::SetupMesh() {
for (SubMesh *sub : submeshes) { for (SubMesh *sub : submeshes) {
sub->SetupSubMesh(); sub->SetupSubMesh();

View File

@ -44,6 +44,7 @@ public:
virtual bool IsDrawable() const {return true;} virtual bool IsDrawable() const {return true;}
virtual void Draw(Shader *shader); virtual void Draw(Shader *shader);
virtual Name GetType() const; virtual Name GetType() const;
Mesh *Duplicate();
protected: protected:
SubMeshList submeshes; SubMeshList submeshes;
virtual void SetupMesh(); virtual void SetupMesh();

BIN
demo/grass_lowres.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 62 KiB

13
demo/ground.mtl Normal file
View File

@ -0,0 +1,13 @@
# Blender MTL File: 'None'
# Material Count: 1
newmtl Material.001
Ns 20.935559
Ka 1.000000 1.000000 1.000000
Kd 0.800000 0.800000 0.800000
Ks 0.000000 0.000000 0.000000
Ke 0.000000 0.000000 0.000000
Ni 1.450000
d 1.000000
illum 1
map_Kd /home/dane/dev/games/trough/godot/environment/raw/grass_lowres.png

16
demo/ground.obj Normal file
View File

@ -0,0 +1,16 @@
# Blender v2.91.0 OBJ File: ''
# www.blender.org
mtllib ground.mtl
o Plane
v -1.000000 0.000000 1.000000
v 1.000000 0.000000 1.000000
v -1.000000 0.000000 -1.000000
v 1.000000 0.000000 -1.000000
vt 0.000000 0.000000
vt 1.000000 0.000000
vt 1.000000 1.000000
vt 0.000000 1.000000
vn 0.0000 1.0000 0.0000
usemtl Material.001
s off
f 1/1/1 2/2/1 4/3/1 3/4/1

View File

@ -46,6 +46,8 @@ function init()
) )
couch.Node.GetRoot().children:Append(skybox) couch.Node.GetRoot().children:Append(skybox)
make_ground()
ball = couch.Mesh.FromFile("cube.obj") ball = couch.Mesh.FromFile("cube.obj")
material = ball:GetMaterial(0) material = ball:GetMaterial(0)
material.ambient = RED material.ambient = RED
@ -147,3 +149,17 @@ function onmousemotion(_, _, relx, rely)
cam_rot_x = relx cam_rot_x = relx
cam_rot_y = rely cam_rot_y = rely
end end
function make_ground()
local ground = couch.TexturedMesh("ground.obj", "grass_lowres.png")
ground.transform.position = couch.Vector3(0.0, -2.0, 0.0)
ground.transform.scale = couch.Vector3(3.0, 1.0, 3.0)
for x = -20, 20, 1 do
for z = -20, 20, 1 do
local piece = ground:Duplicate()
piece.transform.position = couch.Vector3(3.0 * x, -2.0, 3.0 * z)
couch.Node.GetRoot().children:Append(piece)
end
end
end

View File

@ -54,7 +54,6 @@ calling it from the lua file, so stubs aren't necessary to prevent a crash
- [X] No crash on calling non-existant scripting hooks - [X] No crash on calling non-existant scripting hooks
## Lighting ## Lighting
I'm a bit happier with the system now, I think it's time I started the lighting. I'm a bit happier with the system now, I think it's time I started the lighting.
We're going to use a pretty basic Phong lighting system, with We're going to use a pretty basic Phong lighting system, with
Flat and Garourd shaders available (This was all that was available on the PSX!) Flat and Garourd shaders available (This was all that was available on the PSX!)