Add skinning

This commit is contained in:
2026-03-05 14:19:46 +03:00
parent d57ac17b69
commit 65cf326f25
21 changed files with 1305 additions and 117 deletions

View File

@@ -12,10 +12,18 @@
<Entity classname="Entity">
<Position x="3.0" y="1.0" z="3.0" />
<Model filename="data/models/figure_cone.obj" />
<Model filename="data/models/figure_box.obj" />
<IsDisableled value="false" />
<Physics value="true" />
</Entity>
<!--
<Entity classname="test_object">
<Position x="3.0" y="1.0" z="4.0" />
<Model filename="data/models/weapons/v_ump.iqm" />
<IsDisableled value="false" />
</Entity>
-->
</Entities>
</Level>

Binary file not shown.

Binary file not shown.

View File

@@ -7,6 +7,16 @@ function actor_player:on_init()
self:create_body()
self:activate_camera()
local ent = engine.create_entity("test_object")
engine.add_entity_to_world(ent)
self.m_weapon_entity_id = ent:get_id()
self.m_in_reload = false
--local ent2 = engine.get_entity_from_id(self.m_weapon_entity_id)
--console.print(ent2:get_classname())
end
function actor_player:on_shutdown()
@@ -19,8 +29,39 @@ function actor_player:on_update(dt)
self:update_camera_look()
--self:update_camera_movement(dt)
self:update_body_movement(dt)
local ent = engine.get_entity_from_id(self.m_weapon_entity_id)
ent:set_relative_position_to_camera(self)
if self:get_action() == ACTION_FIRE and self.m_in_reload == false then
ent:play_animation(ent:find_animation("shoot1"), ANIM_PLAYBACK_NONE)
end
if self:get_action() == ACTION_RELOAD and self.m_in_reload == false then
ent:play_animation(ent:find_animation("reload"), ANIM_PLAYBACK_NONE)
self.m_in_reload = true
end
if ent:get_current_animation() == ent:find_animation("shoot1") and
ent:get_current_animation_time() >= ent:get_animation_time(ent:find_animation("shoot1")) then
ent:play_animation(ent:find_animation("idle1"), ANIM_PLAYBACK_REPEAT)
end
if self.m_in_reload == true and ent:get_current_animation_time() >= ent:get_animation_time(ent:find_animation("reload")) then
ent:play_animation(ent:find_animation("idle1"), ANIM_PLAYBACK_REPEAT)
self.m_in_reload = false
end
-- if ent:get_current_animation() == ent:find_animation("reload") and
-- ent:get_current_animation_time() >= ent:get_animation_time(ent:find_animation("reload")) then
-- ent:play_animation(ent:find_animation("idle1"), ANIM_PLAYBACK_NONE)
--end
end
function actor_player:on_collide(other)
console.print(string.format("actor_player:on_collide: %s", other:get_classname()))
end
end
function play_sound( filename, is_3d, posx, posy, posz )
-- body
end

View File

@@ -3,14 +3,44 @@ test_object = inherit_table(game_object)
function test_object:on_init()
game_object.on_init(self)
self:load_model("data/models/weapons/v_ump.iqm")
self.m_test_id = self:find_animation("idle1")
console.print(string.format("test_object:on_init: self.m_test_id = %d", self.m_test_id))
self:load_model("data/models/scene_walls.obj")
self.m_test = 0.0
self:play_animation(self.m_test_id, ANIM_PLAYBACK_REPEAT)
-- self.m_test = 0.0
end
function test_object:on_update(dt)
game_object.on_update(self, dt)
self:set_position(self.m_test, 0.0, 0.0)
self.m_test = self.m_test + ( 0.2 * dt )
end
-- self:set_position(self.m_test, 2.0, 0.0)
-- self.m_test = self.m_test + ( 0.2 * dt )
end
function test_object:set_relative_position_to_camera( ent )
local camX, camY, camZ = camera.get_position()
local frontX, frontY, frontZ = camera.get_front()
local rightX, rightY, rightZ = camera.get_right()
local upX, upY, upZ = camera.get_up()
local yaw = camera.get_yaw()
local pitch = camera.get_pitch()
self:set_rotation(pitch, -yaw, 0.0)
local offsetx = 0.0
local offsety = 0.0
local offsetz = 0.0
local x = camX + (rightX * offsetx) + (upX * offsety) + (frontX * offsetz)
local y = camY + (rightY * offsetx) + (upY * offsety) + (frontY * offsetz)
local z = camZ + (rightZ * offsetx) + (upZ * offsety) + (frontZ * offsetz)
self:set_position(x, y, z)
-- force update transform
self:update_transform()
end

View File

@@ -14,33 +14,9 @@ uniform mat4 u_viewMatrix;
uniform mat4 u_projectionMatrix;
uniform mat4 u_modelViewProjection;
vec3 CalcOmniLight()
{
vec3 lightPos = vec3(0.1, 2.1, 0.1);
float d = distance(lightPos, v_position);
vec3 L = normalize(lightPos-v_position);
vec3 N = normalize(v_normal);
vec3 col = vec3( max(0, dot(N, L) / d) );
col = col * 0.8 + 0.2;
return col;
}
vec3 CalcDirLight()
{
vec3 lightPos = vec3(5.0, 10.0, 1.0);
//lightPos = -lightPos;
vec3 L = normalize(lightPos);
vec3 N = normalize(v_normal);
vec3 col = vec3( max(0, dot(N, L)) );
col = col * 0.8 + 0.2;
return col;
}
void main() {
v_position = vec3( u_modelMatrix * vec4(a_position, 1.0) );
v_normal = vec3( mat3(u_modelMatrix) * a_normal );
v_texcoord = a_texcoord;
v_finalColor = CalcDirLight();
gl_Position = u_modelViewProjection * vec4(a_position, 1);
}

View File

@@ -0,0 +1,34 @@
#version 120
attribute vec3 a_position;
attribute vec3 a_normal;
attribute vec2 a_texcoord;
attribute vec4 a_boneIds;
attribute vec4 a_weights;
varying vec3 v_position;
varying vec3 v_normal;
varying vec2 v_texcoord;
varying vec3 v_finalColor;
uniform mat4 u_modelMatrix;
uniform mat4 u_viewMatrix;
uniform mat4 u_projectionMatrix;
uniform mat4 u_modelViewProjection;
uniform mat4 u_boneMatrices[128];
void main() {
// calculate bone transform
mat4 skinMatrix = a_weights.x * u_boneMatrices[ int( a_boneIds.x ) ]
+ a_weights.y * u_boneMatrices[ int( a_boneIds.y ) ]
+ a_weights.z * u_boneMatrices[ int( a_boneIds.z ) ]
+ a_weights.w * u_boneMatrices[ int( a_boneIds.w ) ];
// Position
v_position = vec3( skinMatrix * vec4( a_position, 1.0 ) );
v_position = vec3( u_modelMatrix * vec4( v_position, 1.0 ) );
v_normal = vec3( mat3(u_modelMatrix) * a_normal );
v_texcoord = a_texcoord;
gl_Position = u_projectionMatrix * u_viewMatrix * vec4( v_position, 1.0 );
}