Skip to content

Commit

Permalink
WIP: Loading suicide
Browse files Browse the repository at this point in the history
Telojuriol committed Apr 12, 2018
1 parent 97f7f55 commit eae5b2b
Showing 18 changed files with 191 additions and 35 deletions.
1 change: 0 additions & 1 deletion Bin/data/boot.json
Original file line number Diff line number Diff line change
@@ -6,7 +6,6 @@
"data/scenes/milestone1_map_colliders.scene",
"data/scenes/enemy.scene",
"data/scenes/camera.scene",
"data/scenes/capsules.scene",
"data/scenes/bt_test.scene",
"data/scenes/skeleton_demo.scene"
],
28 changes: 28 additions & 0 deletions Bin/data/prefabs/player.prefab
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
[ {
"entity":
{
"name": "superplayer",
"transform":
{
"pos": "0 0 0",
"rotation": "0.0 0.0 0.0 1.0"
},
"skeleton": {
"skeleton": "data/skeletons/player/player.skeleton"
},
"abs_aabb":true,
"local_aabb":true,
"player_animator":true,
"render" : [
{
"mesh": "data/skeletons/player/body_.mesh"
,
"materials":
[
"data/skeletons/paladin/paladin.material"
]
}
]
}
}
]
48 changes: 23 additions & 25 deletions Bin/data/scenes/skeleton_demo.scene
Original file line number Diff line number Diff line change
@@ -1,30 +1,28 @@
[
{
"entity":
{
"name": "Paladin"
,
"transform":
{
"pos": "0 0 0",
"rotation": "0.0 0.0 0.0 1.0"
},
"skeleton": {
"skeleton": "data/skeletons/cally/cally.skeleton"
},
"abs_aabb":true,
"local_aabb":true,
"player_animator":true,
"render" : [
{
"mesh": "data/skeletons/cally/cally.mesh"
,
"materials":
[
"data/skeletons/paladin/paladin.material"
]
}
]
}
{
"name": "superplayer",
"transform":
{
"pos": "-10 0 -5",
"rotation": "0.0 0.0 0.0 1.0"
},
"skeleton": {
"skeleton": "data/skeletons/Bip001/player.skeleton"
},
"abs_aabb":true,
"local_aabb":true,
"render" : [
{
"mesh": "data/skeletons/Bip001/Bip001.mesh"
,
"materials":
[
"data/skeletons/paladin/paladin.material"
]
}
]
}
}
]
Binary file added Bin/data/skeletons/Bip001/Bip001.csf
Binary file not shown.
Binary file added Bin/data/skeletons/Bip001/Bip001.mesh
Binary file not shown.
6 changes: 6 additions & 0 deletions Bin/data/skeletons/Bip001/player.skeleton
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"name":"Bip001",
"anims" : [
{ "name" : "prova_uri07" }
]
}
Binary file added Bin/data/skeletons/Bip001/prova_uri07.caf
Binary file not shown.
Binary file added Bin/data/skeletons/skeletons/Bip001/Bip001.csf
Binary file not shown.
Binary file added Bin/data/skeletons/skeletons/Bip001/body.cmf
Binary file not shown.
Binary file added Bin/data/skeletons/skeletons/Bip001/hood.cmf
Binary file not shown.
Binary file not shown.
Binary file added Bin/data/skeletons/skeletons/Bip001/tira_L.cmf
Binary file not shown.
Binary file added Bin/data/skeletons/skeletons/Bip001/tira_R.cmf
Binary file not shown.
3 changes: 1 addition & 2 deletions maxscript/MCVExportScene.ms
Original file line number Diff line number Diff line change
@@ -202,8 +202,7 @@ struct TSceneExporter (
print ("Obj " + obj.name + " does NOT have a material")
)
if mat != undefined and not (isValidName mat.name) then (
throw ("Obj " + obj.name + " has a material with an invalid name " + mat.name )
)
q )

fs.beginObj()

121 changes: 121 additions & 0 deletions maxscript/MCVExportSkeletons.ms
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
clearListener()

struct TSkeletonsExporter (
project_path = "C:/Users/mcv16_alumne/Desktop/Deep Shadows/Bin/data/skeletons/",
skel_name = "player", -- smurf
skel_root_path, -- "C:/../bin/data/skeletons/smurf/,
skel_file, -- "C:/../bin/data/skeletons/smurf/smurf.csf"

fn isBone obj = (
-- Discard black bones
return classof obj == Biped_Object and obj.wireColor != Black
),

-- Search the root bones in the scene to define the .csf
fn findSkelCandidates = (
local obj_bones = #()
for obj in $* do (
if isBone obj and obj.parent == undefined then (
format "% is a root bone\n" obj.name
append obj_bones obj
)
)
return obj_bones
),

-- Find in the scene the bones which will be exported as part of the animation
-- Change the color to black to discard the bones
fn findBoneCandidates = (
local objs = #()
for obj in $* do (
if isBone obj then (
format "% is a bone for the animation\n" obj.name
append objs obj
)
)
return objs
),

-- Returns an array of meshes which have the skin modifier and will be exported as .cmf
fn findMeshCandidates = (
local objs = #()
for obj in $* do (
if (classof obj == PolyMeshObject) or (classof obj == Editable_Mesh) then (
if obj.modifiers[#Skin] != undefined then (
format "% is a skinned mesh \n" obj.name
append objs obj
)
)
)
return objs
),


fn setSkelName new_name = (
skel_name = new_name
skel_root_path = project_path + "skeletons/" + skel_name + "/"
makedir skel_root_path
skel_file = skel_root_path + skel_name + ".csf"
),

-- Find a bone candidate to be the root, and choose his name as name of the output file
fn findRootBone = (
local root_bones = findSkelCandidates()
local root = root_bones[1]
setSkelName root.name
return root_bones
),

fn exportSkelAndMeshes = (
if ExportCalSkel == undefined then throw "Please, install the cal3d tools"

local root_bones = findRootBone()
local root = root_bones[1]

-- Pasar a modo figura si esta en modo pose
local was_in_figure_mode = root.controller.figureMode
root.controller.figureMode = true
local bones_to_export = findBoneCandidates()

for b in bones_to_export do (
format "Bone Skel is %\n" b.name
)

format "Exporting cal csf to %\n" skel_file
local rc = ExportCalSkel skel_file bones_to_export off

-- Export la mesh...
local obj_meshes = findMeshCandidates()
for obj in obj_meshes do (
local mesh_file = skel_root_path + obj.name + ".cmf"
-- 0.01 threshold, no LOD, no springs
local rc = ExportCalMesh mesh_file skel_file obj 4 0.01 false false
if rc != 0 then throw ("Failed to export cal3d mesh from object " + obj.name )
)

-- Restaurar el modo pose si es q estaba en modo pose inicialmente
if was_in_figure_mode == false then root.controller.figureMode = false
),

fn exportAnim = (
local root_bones = findRootBone()

-- Export anims.
-- Take the name of the output file from the .max filename
local anim_name = getFilenameFile maxfilename
local animation_file = skel_root_path + anim_name + ".caf"
-- Get all the bones to export
local bones_to_export = findBoneCandidates()
-- frames to integer-frames
-- From 60f we need to get the 60 as integer
local begin_time = animationRange.start as integer * frameRate / 4800
local end_time = animationRange.end as integer * frameRate / 4800
local rc = ExportCalAnim animation_file skel_file bones_to_export begin_time end_time 0 frameRate
if rc != 0 then throw ("Failed to export cal3d anim: " + (rc as integer) )
)
)

gc()
se = TSkeletonsExporter()
se.exportSkelAndMeshes()
se.exportAnim()
3 changes: 2 additions & 1 deletion source/components/skeleton/game_core_skeleton.cpp
Original file line number Diff line number Diff line change
@@ -235,6 +235,7 @@ bool CGameCoreSkeleton::create(const std::string& res_name) {
if (!is_ok)
return false;


// Check if there is already a .mesh
std::string cmf = root_path + name + ".cmf";
if (fileExists(cmf)) {
@@ -244,7 +245,7 @@ bool CGameCoreSkeleton::create(const std::string& res_name) {
std::string skin_mesh_file = root_path + name + ".mesh";
convertCalCoreMesh2RenderMesh(getCoreMesh(mesh_id), skin_mesh_file);
// Delete the cmf file
// std::remove(cmf.c_str());
std::remove(cmf.c_str());
}

// Read all anims
4 changes: 3 additions & 1 deletion source/render/render_objects.cpp
Original file line number Diff line number Diff line change
@@ -239,8 +239,10 @@ void renderMesh(const CRenderMesh* mesh, MAT44 new_matrix, VEC4 color) {
tech_name = "textured.tech";
else if (vdecl->name == "PosNUvUv")
tech_name = "textured_bk.tech";
else if (vdecl->name == "PosNUvSkin")
else if (vdecl->name == "PosNUvSkin") {
tech_name = "solid_objs_skin.tech";
return;
}
else if (vdecl->name == "PosNUvTanSkin")
tech_name = "solid_objs_skin.tech";

12 changes: 7 additions & 5 deletions source/render/render_utils.cpp
Original file line number Diff line number Diff line change
@@ -3,12 +3,14 @@
#include "render_objects.h"

void renderLine(VEC3 src, VEC3 dst, VEC4 color) {
MAT44 world = MAT44::CreateLookAt(src, dst, VEC3(0, 1, 0)).Invert();
float distance = VEC3::Distance(src, dst);
world = MAT44::CreateScale(1, 1, -distance) * world;
cb_object.obj_world = world;
cb_object.obj_color = color;
cb_object.updateGPU();
if (distance != 0.f) {
MAT44 world = MAT44::CreateLookAt(src, dst, VEC3(0, 1, 0)).Invert();
world = MAT44::CreateScale(1, 1, -distance) * world;
cb_object.obj_world = world;
cb_object.obj_color = color;
cb_object.updateGPU();
}

auto mesh = Resources.get("line.mesh")->as<CRenderMesh>();
mesh->activateAndRender();

0 comments on commit eae5b2b

Please sign in to comment.