diff --git a/res/chapter9/NavMesh/all_tiles_tilecache.bin b/res/chapter9/NavMesh/all_tiles_tilecache.bin new file mode 100644 index 0000000..f61e2e9 Binary files /dev/null and b/res/chapter9/NavMesh/all_tiles_tilecache.bin differ diff --git a/res/chapter9/NavMesh/geomset.txt b/res/chapter9/NavMesh/geomset.txt new file mode 100644 index 0000000..b8c9e26 --- /dev/null +++ b/res/chapter9/NavMesh/geomset.txt @@ -0,0 +1,4 @@ +f Meshes/scene.obj +c -13.588468 8.489700 -3.117989 5.127029 8.489700 -2.654125 0.600000 1 5 8 +c -20.038349 8.489704 3.686111 -33.257217 1.000000 -1.603912 0.600000 1 5 8 +c 11.820250 8.489700 3.516487 23.950550 1.000000 -1.226341 0.600000 1 5 8 diff --git a/res/chapter9/NavMesh/maps/scenetex.png b/res/chapter9/NavMesh/maps/scenetex.png new file mode 100644 index 0000000..ce473f8 Binary files /dev/null and b/res/chapter9/NavMesh/maps/scenetex.png differ diff --git a/res/chapter9/NavMesh/scene.mtl b/res/chapter9/NavMesh/scene.mtl new file mode 100644 index 0000000..025154c --- /dev/null +++ b/res/chapter9/NavMesh/scene.mtl @@ -0,0 +1,16 @@ +# 3ds Max Wavefront OBJ Exporter v0.97b - (c)2007 guruware +# �������ļ�:18.06.2015 14:07:57 + +newmtl 01___Default + Ns 10.0000 + Ni 1.5000 + d 1.0000 + Tr 0.0000 + Tf 1.0000 1.0000 1.0000 + illum 2 + Ka 0.8353 0.8353 0.8353 + Kd 0.8353 0.8353 0.8353 + Ks 0.0000 0.0000 0.0000 + Ke 0.0000 0.0000 0.0000 + map_Ka maps\scenetex.png + map_Kd maps\scenetex.png diff --git a/res/chapter9/NavMesh/scene.obj b/res/chapter9/NavMesh/scene.obj new file mode 100644 index 0000000..4b23962 --- /dev/null +++ b/res/chapter9/NavMesh/scene.obj @@ -0,0 +1,209 @@ +# 3ds Max Wavefront OBJ Exporter v0.97b - (c)2007 guruware +# �������ļ�:18.06.2015 14:07:57 + +mtllib scene.mtl + +# +# object ____001 +# + +# +# object Box006 +# + +v -24.2372 0.0000 8.3985 +v -24.2372 0.0000 -7.0529 +v -10.7449 0.0000 -7.0529 +v -10.7449 0.0000 8.3985 +v -24.2372 8.4897 8.3985 +v -10.7449 8.4897 8.3985 +v -10.7449 8.4897 -7.0529 +v -24.2372 8.4897 -7.0529 +# 8 vertices + +vn 0.0000 -1.0000 -0.0000 +vn 0.0000 1.0000 -0.0000 +vn 0.0000 0.0000 1.0000 +vn 1.0000 0.0000 -0.0000 +vn 0.0000 0.0000 -1.0000 +vn -1.0000 0.0000 -0.0000 +# 6 vertex normals + +vt 1.0000 0.0000 0.0000 +vt 1.0000 1.0000 0.0000 +vt 0.0000 1.0000 0.0000 +vt 0.0000 0.0000 0.0000 +# 4 texture coords + +g Box006 +usemtl 01___Default +s 2 +f 1/1/1 2/2/1 3/3/1 +f 3/3/1 4/4/1 1/1/1 +s 4 +f 5/4/2 6/1/2 7/2/2 +f 7/2/2 8/3/2 5/4/2 +s 8 +f 1/4/3 4/1/3 6/2/3 +f 6/2/3 5/3/3 1/4/3 +s 16 +f 4/4/4 3/1/4 7/2/4 +f 7/2/4 6/3/4 4/4/4 +s 32 +f 3/4/5 2/1/5 8/2/5 +f 8/2/5 7/3/5 3/4/5 +s 64 +f 2/4/6 1/1/6 5/2/6 +f 5/2/6 8/3/6 2/4/6 +# 12 faces + +# +# object Box008 +# + +v -0.0752 0.0000 50.0000 +v -0.0752 0.0000 -50.0000 +v 47.8119 0.0000 -50.0000 +v 47.8119 0.0000 50.0000 +v -0.0752 1.0000 50.0000 +v 47.8119 1.0000 50.0000 +v 47.8119 1.0000 -50.0000 +v -0.0752 1.0000 -50.0000 +# 8 vertices + +vn 0.0000 -1.0000 -0.0000 +vn 0.0000 1.0000 -0.0000 +vn 0.0000 0.0000 1.0000 +vn 1.0000 0.0000 -0.0000 +vn 0.0000 0.0000 -1.0000 +vn -1.0000 0.0000 -0.0000 +# 6 vertex normals + +vt 1.0000 0.0000 0.0000 +vt 1.0000 1.0000 0.0000 +vt 0.0000 1.0000 0.0000 +vt 0.0000 0.0000 0.0000 +# 4 texture coords + +g Box008 +usemtl 01___Default +s 2 +f 9/5/7 10/6/7 11/7/7 +f 11/7/7 12/8/7 9/5/7 +s 4 +f 13/8/8 14/5/8 15/6/8 +f 15/6/8 16/7/8 13/8/8 +s 8 +f 9/8/9 12/5/9 14/6/9 +f 14/6/9 13/7/9 9/8/9 +s 16 +f 12/8/10 11/5/10 15/6/10 +f 15/6/10 14/7/10 12/8/10 +s 32 +f 11/8/11 10/5/11 16/6/11 +f 16/6/11 15/7/11 11/8/11 +s 64 +f 10/8/12 9/5/12 13/6/12 +f 13/6/12 16/7/12 10/8/12 +# 12 faces + +# +# object Box009 +# + +v -57.6132 0.0000 50.0000 +v -57.6132 0.0000 -50.0000 +v -9.7261 0.0000 -50.0000 +v -9.7261 0.0000 50.0000 +v -57.6132 1.0000 50.0000 +v -9.7261 1.0000 50.0000 +v -9.7261 1.0000 -50.0000 +v -57.6132 1.0000 -50.0000 +# 8 vertices + +vn 0.0000 -1.0000 -0.0000 +vn 0.0000 1.0000 -0.0000 +vn 0.0000 0.0000 1.0000 +vn 1.0000 0.0000 -0.0000 +vn 0.0000 0.0000 -1.0000 +vn -1.0000 0.0000 -0.0000 +# 6 vertex normals + +vt 1.0000 0.0000 0.0000 +vt 1.0000 1.0000 0.0000 +vt 0.0000 1.0000 0.0000 +vt 0.0000 0.0000 0.0000 +# 4 texture coords + +g Box009 +usemtl 01___Default +s 2 +f 17/9/13 18/10/13 19/11/13 +f 19/11/13 20/12/13 17/9/13 +s 4 +f 21/12/14 22/9/14 23/10/14 +f 23/10/14 24/11/14 21/12/14 +s 8 +f 17/12/15 20/9/15 22/10/15 +f 22/10/15 21/11/15 17/12/15 +s 16 +f 20/12/16 19/9/16 23/10/16 +f 23/10/16 22/11/16 20/12/16 +s 32 +f 19/12/17 18/9/17 24/10/17 +f 24/10/17 23/11/17 19/12/17 +s 64 +f 18/12/18 17/9/18 21/10/18 +f 21/10/18 24/11/18 18/12/18 +# 12 faces + +# +# object Box010 +# + +v 1.8428 0.0000 8.3985 +v 1.8428 0.0000 -7.0529 +v 15.3351 0.0000 -7.0529 +v 15.3351 0.0000 8.3985 +v 1.8428 8.4897 8.3985 +v 15.3351 8.4897 8.3985 +v 15.3351 8.4897 -7.0529 +v 1.8428 8.4897 -7.0529 +# 8 vertices + +vn 0.0000 -1.0000 -0.0000 +vn 0.0000 1.0000 -0.0000 +vn 0.0000 0.0000 1.0000 +vn 1.0000 0.0000 -0.0000 +vn 0.0000 0.0000 -1.0000 +vn -1.0000 0.0000 -0.0000 +# 6 vertex normals + +vt 1.0000 0.0000 0.0000 +vt 1.0000 1.0000 0.0000 +vt 0.0000 1.0000 0.0000 +vt 0.0000 0.0000 0.0000 +# 4 texture coords + +g Box010 +usemtl 01___Default +s 2 +f 25/13/19 26/14/19 27/15/19 +f 27/15/19 28/16/19 25/13/19 +s 4 +f 29/16/20 30/13/20 31/14/20 +f 31/14/20 32/15/20 29/16/20 +s 8 +f 25/16/21 28/13/21 30/14/21 +f 30/14/21 29/15/21 25/16/21 +s 16 +f 28/16/22 27/13/22 31/14/22 +f 31/14/22 30/15/22 28/16/22 +s 32 +f 27/16/23 26/13/23 32/14/23 +f 32/14/23 31/15/23 27/16/23 +s 64 +f 26/16/24 25/13/24 29/14/24 +f 29/14/24 32/15/24 26/16/24 +# 12 faces + diff --git a/res/chapter9/Particle3D/materials/pu_mediapack_01.material b/res/chapter9/Particle3D/materials/pu_mediapack_01.material new file mode 100644 index 0000000..890c4da --- /dev/null +++ b/res/chapter9/Particle3D/materials/pu_mediapack_01.material @@ -0,0 +1,1323 @@ +//----------------------------------------------------------------------------------------------------------------------- +// This script is part of the Particle Universe Media Pack product. +// +// Copyright (c) 2008 Henry van Merode +// +// Usage of this program is licensed under the terms of the Particle Universe Commercial License. +// You can find a copy of the Commercial License in the Particle Universe package. +//----------------------------------------------------------------------------------------------------------------------- +material PUMediaPack/Bubble +{ + technique + { + pass + { + lighting off + scene_blend alpha_blend + depth_write off + + texture_unit + { + texture pump_bubble.png + tex_address_mode clamp + } + } + } +} + +//----------------------------------------------------------------------------------------------------------------------- +material PUMediaPack/BlurredBubble +{ + technique + { + pass + { + lighting off + scene_blend alpha_blend + depth_write off + + texture_unit + { + texture pump_bubble_blurred.png + tex_address_mode clamp + } + } + } +} + +//----------------------------------------------------------------------------------------------------------------------- +material PUMediaPack/Streak_01 +{ + technique + { + pass + { + lighting off + scene_blend add + depth_write off + + texture_unit + { + texture pump_streak_01.png + tex_address_mode clamp + } + } + } +} + +//----------------------------------------------------------------------------------------------------------------------- +material PUMediaPack/Streak_02 +{ + technique + { + pass + { + lighting off + scene_blend add + depth_write off + texture_unit + { + texture pump_streak_02.png + tex_address_mode clamp + } + } + } +} + +//----------------------------------------------------------------------------------------------------------------------- +material PUMediaPack/Streak_03 +{ + technique + { + pass + { + lighting off + scene_blend add + depth_write off + + texture_unit + { + texture pump_streak_03.png + tex_address_mode clamp + } + } + } +} + +//----------------------------------------------------------------------------------------------------------------------- +material PUMediaPack/Streak_04 +{ + technique + { + pass + { + lighting off + scene_blend add + depth_write off + + texture_unit + { + texture pump_streak_04.png + tex_address_mode clamp + } + } + } +} + +//----------------------------------------------------------------------------------------------------------------------- +material PUMediaPack/Flare_01 +{ + technique + { + pass + { + lighting off + scene_blend add + depth_write off + + texture_unit + { + texture pump_flare_01.png + tex_address_mode clamp + } + } + } +} + +//----------------------------------------------------------------------------------------------------------------------- +material PUMediaPack/Flare_02 +{ + technique + { + pass + { + lighting off + scene_blend add + depth_write off + + texture_unit + { + texture pump_flare_02.png + tex_address_mode clamp + } + } + } +} + +//----------------------------------------------------------------------------------------------------------------------- +material PUMediaPack/Flare_03 +{ + technique + { + pass + { + lighting off + scene_blend add + depth_write off + + texture_unit + { + texture pump_flare_03.png + tex_address_mode clamp + } + } + } +} + +//----------------------------------------------------------------------------------------------------------------------- +material PUMediaPack/Flare_04 +{ + technique + { + pass + { + lighting off + scene_blend add + depth_write off + + texture_unit + { + texture pump_flare_04.png + tex_address_mode clamp + } + } + } +} + +//----------------------------------------------------------------------------------------------------------------------- +material PUMediaPack/Flare_05 +{ + technique + { + pass + { + lighting off + scene_blend add + depth_write off + + texture_unit + { + texture pump_flare_05.png + tex_address_mode clamp + } + } + } +} + +//----------------------------------------------------------------------------------------------------------------------- +material PUMediaPack/Flare_06 +{ + technique + { + pass + { + lighting off + scene_blend add + depth_write off + + texture_unit + { + texture pump_flare_06.png + tex_address_mode clamp + } + } + } +} + +//----------------------------------------------------------------------------------------------------------------------- +material PUMediaPack/Watch +{ + technique + { + pass + { + lighting off + depth_write off + scene_blend add + + texture_unit + { + texture pump_watch.png + tex_address_mode clamp + } + } + } +} + +//----------------------------------------------------------------------------------------------------------------------- +material PUMediaPack/Hourglass +{ + technique + { + pass + { + lighting off + depth_write off + scene_blend add + + texture_unit + { + texture pump_hourglass.png + tex_address_mode clamp + } + } + } +} + +//----------------------------------------------------------------------------------------------------------------------- +material PUMediaPack/Leave +{ + technique + { + pass + { + lighting off + scene_blend alpha_blend + depth_write off + + texture_unit + { + texture pump_leave.png + tex_address_mode clamp + } + } + } +} + +//----------------------------------------------------------------------------------------------------------------------- +material PUMediaPack/Smoke_01 +{ + technique + { + pass + { + lighting off + scene_blend add + depth_write off + + texture_unit + { + texture pump_smoke_01.png + tex_address_mode clamp + } + } + } +} + +//----------------------------------------------------------------------------------------------------------------------- +material PUMediaPack/Smoke_11 +{ + technique + { + pass + { + lighting off + scene_blend alpha_blend + depth_write off + + texture_unit + { + texture pump_smoke_01.png + tex_address_mode clamp + } + } + } +} + +//----------------------------------------------------------------------------------------------------------------------- +material PUMediaPack/Dirt_11 +{ + technique + { + pass + { + lighting off + scene_blend alpha_blend + depth_write off + + texture_unit + { + texture pump_dirt_01.png + tex_address_mode clamp + } + } + } +} + +//----------------------------------------------------------------------------------------------------------------------- +material PUMediaPack/Dirt_12 +{ + technique + { + pass + { + lighting off + scene_blend alpha_blend + depth_write off + + texture_unit + { + texture pump_dirt_02.png + tex_address_mode clamp + } + } + } +} + +//----------------------------------------------------------------------------------------------------------------------- +material PUMediaPack/Lightning_01 +{ + technique + { + pass + { + lighting off + scene_blend add + depth_write off + + texture_unit + { + texture pump_lightning_01.png + tex_address_mode clamp + } + } + } +} + +//----------------------------------------------------------------------------------------------------------------------- +material PUMediaPack/Lightning_02 +{ + technique + { + pass + { + lighting off + scene_blend add + depth_write off + + texture_unit + { + texture pump_lightning_02.png + tex_address_mode clamp + } + } + } +} + +//----------------------------------------------------------------------------------------------------------------------- +material PUMediaPack/Lightning_03 +{ + technique + { + pass + { + lighting off + scene_blend add + depth_write off + + texture_unit + { + texture pump_lightning_03.png + tex_address_mode clamp + } + } + } +} + +//----------------------------------------------------------------------------------------------------------------------- +material PUMediaPack/Lightning_04 +{ + technique + { + pass + { + lighting off + scene_blend add + depth_write off + + texture_unit + { + texture pump_lightning_04.png + tex_address_mode clamp + } + } + } +} + +//----------------------------------------------------------------------------------------------------------------------- +material PUMediaPack/Spark_01 +{ + technique + { + pass + { + lighting off + scene_blend add + depth_write off + + texture_unit + { + texture pump_spark_01.png + tex_address_mode clamp + } + } + } +} + +//----------------------------------------------------------------------------------------------------------------------- +material PUMediaPack/Star_01 +{ + technique + { + pass + { + lighting off + scene_blend add + depth_write off + + texture_unit + { + texture pump_star_01.png + tex_address_mode clamp + } + } + } +} + +//----------------------------------------------------------------------------------------------------------------------- +material PUMediaPack/Star_02 +{ + technique + { + pass + { + lighting off + scene_blend add + depth_write off + + texture_unit + { + texture pump_star_02.png + tex_address_mode clamp + } + } + } +} + +//----------------------------------------------------------------------------------------------------------------------- +material PUMediaPack/Star_03 +{ + technique + { + pass + { + lighting off + scene_blend add + depth_write off + + texture_unit + { + texture pump_star_03.png + tex_address_mode clamp + } + } + } +} + +//----------------------------------------------------------------------------------------------------------------------- +material PUMediaPack/Star_04 +{ + technique + { + pass + { + lighting off + scene_blend add + depth_write off + + texture_unit + { + texture pump_star_04.png + tex_address_mode clamp + } + } + } +} + +//----------------------------------------------------------------------------------------------------------------------- +material PUMediaPack/Star_05 +{ + technique + { + pass + { + lighting off + scene_blend add + depth_write off + + texture_unit + { + texture pump_star_05.png + tex_address_mode clamp + } + } + } +} + +//----------------------------------------------------------------------------------------------------------------------- +material PUMediaPack/Genesis_11 +{ + technique + { + pass + { + lighting off + scene_blend alpha_blend + depth_write off + + texture_unit + { + texture pump_genesis_01.png + tex_address_mode clamp + } + } + } +} + +//----------------------------------------------------------------------------------------- +material PUMediaPack/Genesis_12 +{ + technique + { + pass + { + lighting off + scene_blend alpha_blend + depth_write off + + texture_unit + { + texture pump_genesis_02.png + tex_address_mode clamp + } + } + } +} + +//----------------------------------------------------------------------------------------- +material ParticleUniverse/Swirl_01 +{ + technique + { + pass + { + lighting off + scene_blend add + depth_write off + + texture_unit + { + texture pump_swirl_01.png + tex_address_mode clamp + } + } + } +} + +//----------------------------------------------------------------------------------------- +material ParticleUniverse/Swirl_02 +{ + technique + { + pass + { + lighting off + scene_blend add + depth_write off + + texture_unit + { + texture pump_swirl_02.png + tex_address_mode clamp + } + } + } +} + +//----------------------------------------------------------------------------------------- +material ParticleUniverse/Swirl_03 +{ + technique + { + pass + { + lighting off + scene_blend add + depth_write off + + texture_unit + { + texture pump_swirl_03.png + tex_address_mode clamp + } + } + } +} + +//----------------------------------------------------------------------------------------- +material PUMediaPack/Ring_01 +{ + technique + { + pass + { + lighting off + scene_blend add + depth_write off + + texture_unit + { + texture pump_ring_01.png + tex_address_mode clamp + } + } + } +} + +//----------------------------------------------------------------------------------------- +material PUMediaPack/Ring_02 +{ + technique + { + pass + { + lighting off + scene_blend add + depth_write off + + texture_unit + { + texture pump_ring_02.png + tex_address_mode clamp + } + } + } +} + +//----------------------------------------------------------------------------------------- +material PUMediaPack/Ring_03 +{ + technique + { + pass + { + lighting off + scene_blend add + depth_write off + + texture_unit + { + texture pump_ring_03.png + tex_address_mode clamp + } + } + } +} + +//----------------------------------------------------------------------------------------- +material PUMediaPack/Ring_14 +{ + technique + { + pass + { + lighting off + scene_blend alpha_blend + depth_write off + + texture_unit + { + texture pump_ring_04.png + tex_address_mode clamp + } + } + } +} + +//----------------------------------------------------------------------------------------- +material PUMediaPack/Ring_05 +{ + technique + { + pass + { + lighting off + scene_blend add + depth_write off + + texture_unit + { + texture pump_ring_05.png + tex_address_mode clamp + } + } + } +} + +//----------------------------------------------------------------------------------------------------------------------- +material PUMediaPack/Metal_01 +{ + technique + { + pass + { + lighting off + scene_blend add + depth_write off + + texture_unit + { + texture pump_metal_01.png + tex_address_mode clamp + } + } + } +} + +//----------------------------------------------------------------------------------------------------------------------- +material PUMediaPack/Metal_02 +{ + technique + { + pass + { + lighting off + scene_blend add + depth_write off + + texture_unit + { + texture pump_metal_02.png + tex_address_mode clamp + } + } + } +} +//----------------------------------------------------------------------------------------------------------------------- +material PUMediaPack/Fire_01 +{ + technique + { + pass + { + lighting off + scene_blend add + depth_write off + + texture_unit + { + texture pump_flame_01.png + tex_address_mode clamp + } + } + } +} + +//--------------------------------------------------------------------- +material PUMediaPack/Fire_02 +{ + technique + { + pass + { + lighting off + scene_blend add + depth_write off + + texture_unit + { + texture pump_flame_02.png + tex_address_mode clamp + } + } + } +} + +//--------------------------------------------------------------------- +material PUMediaPack/Fire_03 +{ + technique + { + pass + { + lighting off + scene_blend add + depth_write off + + texture_unit + { + texture pump_flame_03.png + tex_address_mode clamp + } + } + } +} + +//--------------------------------------------------------------------- +material PUMediaPack/Fire_04 +{ + technique + { + pass + { + lighting off + scene_blend add + depth_write off + + texture_unit + { + texture pump_flame_04.png + tex_address_mode clamp + } + } + } +} + +//--------------------------------------------------------------------- +material PUMediaPack/AtlasSmoke +{ + technique + { + pass + { + lighting off + scene_blend alpha_blend + depth_write off + + texture_unit + { + texture pump_atlas_smoke.png + tex_address_mode clamp + } + } + } +} + +//--------------------------------------------------------------------- +material PUMediaPack/Snow_01 +{ + technique + { + pass + { + lighting off + scene_blend alpha_blend + depth_write off + + texture_unit + { + texture pump_snow_01.png + tex_address_mode clamp + } + } + } +} +//----------------------------------------------------------------------------------------------------------------------- +material PUMediaPack/BBal +{ + technique + { + pass + { + lighting off + depth_write off + + texture_unit + { + texture pu_bbal.png + tex_address_mode clamp + } + } + } +} + +//----------------------------------------------------------------------------------------------------------------------- +material PUMediaPack/BioHazzard +{ + technique + { + pass + { + lighting off + scene_blend add + depth_write off + + texture_unit + { + texture pump_biohazzard.png + tex_address_mode clamp + } + } + } +} + +//----------------------------------------------------------------------------------------------------------------------- +material PUMediaPack/CelticKnot +{ + technique + { + pass + { + lighting off + scene_blend add + depth_write off + + texture_unit + { + texture pump_celticknot.png + tex_address_mode clamp + } + } + } +} + +//----------------------------------------------------------------------------------------------------------------------- +material PUMediaPack/Pentagram_01 +{ + technique + { + pass + { + lighting off + scene_blend add + depth_write off + + texture_unit + { + texture pump_pentagram_01.png + tex_address_mode clamp + } + } + } +} + +//----------------------------------------------------------------------------------------------------------------------- +material PUMediaPack/Pentagram_02 +{ + technique + { + pass + { + lighting off + scene_blend add + depth_write off + + texture_unit + { + texture pump_pentagram_02.png + tex_address_mode clamp + } + } + } +} + +//----------------------------------------------------------------------------------------------------------------------- +// This script is part of the Particle Universe Media Pack 1 product. +// +// Copyright (c) 2010 Henry van Merode +// +// Usage of this program is licensed under the terms of the Particle Universe Commercial License Media Pack 1. +// You can find a copy of the Commercial License in the Media Pack 1 package. +//----------------------------------------------------------------------------------------------------------------------- + +material mp_explosion_smoke_01 +{ + technique + { + pass + { + lighting off + depth_write off + scene_blend alpha_blend + + texture_unit + { + texture mp_explosion_smoke_01.dds + } + } + } +} +//----------------------------------------------------------------------------------------------------------------------- +material mp_explosion_smoke_01_add +{ + technique + { + pass + { + lighting off + depth_write off + scene_blend add + texture_unit + { + texture mp_explosion_smoke_01_add.dds + } + } + } +} +//----------------------------------------------------------------------------------------------------------------------- +material mp_explosion_flare_01 +{ + technique + { + pass + { + lighting off + depth_write off + scene_blend add + + texture_unit + { + texture mp_explosion_flare_01.dds + } + } + } +} +//----------------------------------------------------------------------------------------------------------------------- +material mp_explosion_flare_02 +{ + technique + { + pass + { + lighting off + depth_write off + scene_blend add + + texture_unit + { + texture mp_explosion_flare_02.dds + } + } + } +} +//----------------------------------------------------------------------------------------------------------------------- +material mp_explosion_dirt +{ + technique + { + pass + { + lighting off + depth_write off + scene_blend alpha_blend + + texture_unit + { + texture mp_explosion_dirt.dds + } + } + } +} +//----------------------------------------------------------------------------------------------------------------------- +material mp_explosion_flame_01 +{ + technique + { + pass + { + lighting off + depth_write off + scene_blend add + + texture_unit + { + texture mp_explosion_flame_01.dds + } + } + } +} +//----------------------------------------------------------------------------------------------------------------------- +material mp_explosion_flame_02 +{ + technique + { + pass + { + lighting off + depth_write off + scene_blend add + + texture_unit + { + texture mp_explosion_flame_02.dds + } + } + } +} +//----------------------------------------------------------------------------------------------------------------------- +material mp_explosion_smoke_02 +{ + technique + { + pass + { + lighting off + depth_write off + scene_blend alpha_blend + + texture_unit + { + texture mp_explosion_smoke_02.dds + } + } + } +} +//----------------------------------------------------------------------------------------------------------------------- +material mp_explosion_smoke_03 +{ + technique + { + pass + { + lighting off + depth_write off + scene_blend alpha_blend + + texture_unit + { + texture mp_explosion_smoke_03.dds + } + } + } +} +//----------------------------------------------------------------------------------------------------------------------- +material mp_explosion_debris +{ + technique + { + pass + { + lighting off + depth_write off + scene_blend add + + texture_unit + { + texture mp_explosion_debris.dds + } + } + } +} +//----------------------------------------------------------------------------------------------------------------------- +material mp_explosion_debris_large +{ + technique + { + pass + { + lighting off + depth_write off + scene_blend alpha_blend + + texture_unit + { + texture mp_explosion_debris_large_4x4.dds + } + } + } +} +//----------------------------------------------------------------------------------------------------------------------- +material mp_explosion_04 +{ + technique + { + pass + { + lighting off + depth_write off + scene_blend add + texture_unit + { + texture mp_explosion_04.dds + } + } + } +} +//----------------------------------------------------------------------------------------------------------------------- +material mp_explosion_trail +{ + technique + { + pass + { + lighting off + depth_write off + scene_blend add + + texture_unit + { + texture mp_explosion_trail_01.dds + } + } + } +} +//----------------------------------------------------------------------------------------------------------------------- +material mp_explosion_water +{ + technique + { + pass + { + lighting off + depth_write off + scene_blend alpha_blend + + texture_unit + { + texture mp_explosion_water.dds + } + } + } +} +//----------------------------------------------------------------------------------------------------------------------- +material weaponTrail +{ + technique + { + pass + { + lighting off + scene_blend add + depth_write off + cull_hardware none + cull_software none + + texture_unit + { + texture weaponTrail.png + tex_address_mode clamp + } + } + } +} + diff --git a/res/chapter9/Particle3D/scripts/blackHole.pu b/res/chapter9/Particle3D/scripts/blackHole.pu new file mode 100644 index 0000000..3abffa7 --- /dev/null +++ b/res/chapter9/Particle3D/scripts/blackHole.pu @@ -0,0 +1,76 @@ +system blackHole +{ + technique + { + visual_particle_quota 2500 + material PUMediaPack/Flare_04 + default_particle_width 12 + default_particle_height 12 + renderer Billboard + { + } + emitter SphereSurface + { + emission_rate 200 + velocity 3 + radius 12 + } + affector Colour + { + time_colour 0 0 0 0.2 1 + time_colour 0.9 0.8 0.8 1 1 + time_colour 1 1 1 1 1 + } + affector Gravity + { + gravity 2700 + } + affector Scale + { + xyz_scale -4.5 + } + } + technique + { + visual_particle_quota 250 + material PUMediaPack/Streak_03 + renderer Billboard + { + billboard_type oriented_self + } + emitter Point + { + emission_rate 50 + angle 360 + time_to_live 4 + velocity 1 + particle_width dyn_random + { + min 2 + max 4 + } + particle_height dyn_random + { + min 45 + max 60 + } + colour 0.1 0.1 1 1 + } + affector Scale + { + x_scale -1.2 + } + affector Scale + { + y_scale -45 + } + affector Colour + { + time_colour 0 0 0 0 0 + time_colour 0.2 1 1 1 1 + time_colour 0.8 1 1 1 1 + time_colour 1 0 0 0 0 + colour_operation multiply + } + } +} diff --git a/res/chapter9/Particle3D/scripts/lightningBolt.pu b/res/chapter9/Particle3D/scripts/lightningBolt.pu new file mode 100644 index 0000000..4494103 --- /dev/null +++ b/res/chapter9/Particle3D/scripts/lightningBolt.pu @@ -0,0 +1,174 @@ +system lightningBolt +{ + technique + { + visual_particle_quota 100 + material PUMediaPack/Smoke_01 + renderer Billboard + { + } + emitter Point + { + emission_rate 40 + angle 360 + time_to_live dyn_random + { + min 1 + max 3 + } + velocity 3 + all_particle_dimensions dyn_random + { + min 0.3 + max 0.6 + } + colour 0.46 0.06 0.82 1 + } + affector Scale + { + xyz_scale 6 + } + affector Colour + { + time_colour 0 1 1 1 1 + time_colour 1 0 0 0 0 + colour_operation multiply + } + } + technique Lightning_1 + { + visual_particle_quota 20 + material PUMediaPack/Lightning_01 + renderer Billboard + { + billboard_type oriented_self + billboard_origin top_center + } + emitter Point + { + emission_rate 20 + angle 360 + time_to_live dyn_random + { + min 0.05 + max 0.15 + } + velocity 1e-005 + all_particle_dimensions dyn_random + { + min 7.68 + max 15.36 + } + colour 0.46 0.06 0.82 1 + } + affector Colour + { + time_colour 0 1 1 1 1 + time_colour 0.5 1 1 1 1 + time_colour 1 0 0 0 0 + colour_operation multiply + } + } + technique Lightning_2 + { + visual_particle_quota 5 + material PUMediaPack/Lightning_02 + renderer Billboard + { + billboard_type oriented_self + billboard_origin top_center + } + emitter Point + { + emission_rate 20 + angle 360 + time_to_live dyn_random + { + min 0.05 + max 0.15 + } + velocity 1e-005 + all_particle_dimensions dyn_random + { + min 7.68 + max 15.36 + } + colour 0.46 0.06 0.82 1 + } + affector Colour + { + time_colour 0 1 1 1 1 + time_colour 0.5 1 1 1 1 + time_colour 1 0 0 0 0 + colour_operation multiply + } + } + technique Lightning_3 + { + visual_particle_quota 5 + material PUMediaPack/Lightning_03 + renderer Billboard + { + billboard_type oriented_self + billboard_origin top_center + } + emitter Point + { + emission_rate 20 + angle 360 + time_to_live dyn_random + { + min 0.05 + max 0.15 + } + velocity 1e-005 + all_particle_dimensions dyn_random + { + min 7.68 + max 15.36 + } + colour 0.46 0.06 0.82 1 + } + affector Colour + { + time_colour 0 1 1 1 1 + time_colour 0.5 1 1 1 1 + time_colour 1 0 0 0 0 + colour_operation multiply + } + } + technique Lightning_4 + { + visual_particle_quota 5 + material PUMediaPack/Lightning_04 + renderer Billboard + { + billboard_type oriented_self + billboard_origin top_center + } + emitter Point + { + emission_rate 20 + angle 360 + time_to_live dyn_random + { + min 0.05 + max 0.15 + } + velocity 1e-005 + all_particle_dimensions dyn_random + { + min 7.68 + max 15.36 + } + colour 0.46 0.06 0.82 1 + } + affector Colour + { + time_colour 0 1 1 1 1 + time_colour 0.5 1 1 1 1 + time_colour 1 0 0 0 0 + colour_operation multiply + } + } +} diff --git a/res/chapter9/Particle3D/scripts/lineStreak.pu b/res/chapter9/Particle3D/scripts/lineStreak.pu new file mode 100644 index 0000000..ea1cace --- /dev/null +++ b/res/chapter9/Particle3D/scripts/lineStreak.pu @@ -0,0 +1,43 @@ +system lineStreak +{ + category LightFX + technique + { + keep_local true + visual_particle_quota 250 + material PUMediaPack/Pentagram_02 + renderer Billboard + { + billboard_type oriented_self + } + emitter Point + { + emission_rate 200 + angle 360 + time_to_live 1 + velocity dyn_random + { + min 3 + max 7.5 + } + particle_width dyn_random + { + min 0.3 + max 1.4 + } + particle_height dyn_random + { + min 6 + max 12 + } + colour 1 0.84 0.45 1 + } + affector Colour + { + time_colour 0 1 1 1 1 + time_colour 0.8 1 1 1 1 + time_colour 1 0 0 0 0 + colour_operation multiply + } + } +} diff --git a/res/chapter9/Particle3D/textures/pump_flare_04.png b/res/chapter9/Particle3D/textures/pump_flare_04.png new file mode 100644 index 0000000..868431e Binary files /dev/null and b/res/chapter9/Particle3D/textures/pump_flare_04.png differ diff --git a/res/chapter9/Particle3D/textures/pump_lightning_01.png b/res/chapter9/Particle3D/textures/pump_lightning_01.png new file mode 100644 index 0000000..a48297d Binary files /dev/null and b/res/chapter9/Particle3D/textures/pump_lightning_01.png differ diff --git a/res/chapter9/Particle3D/textures/pump_lightning_02.png b/res/chapter9/Particle3D/textures/pump_lightning_02.png new file mode 100644 index 0000000..a9dd25c Binary files /dev/null and b/res/chapter9/Particle3D/textures/pump_lightning_02.png differ diff --git a/res/chapter9/Particle3D/textures/pump_lightning_03.png b/res/chapter9/Particle3D/textures/pump_lightning_03.png new file mode 100644 index 0000000..095c119 Binary files /dev/null and b/res/chapter9/Particle3D/textures/pump_lightning_03.png differ diff --git a/res/chapter9/Particle3D/textures/pump_lightning_04.png b/res/chapter9/Particle3D/textures/pump_lightning_04.png new file mode 100644 index 0000000..01f9f07 Binary files /dev/null and b/res/chapter9/Particle3D/textures/pump_lightning_04.png differ diff --git a/res/chapter9/Particle3D/textures/pump_pentagram_02.png b/res/chapter9/Particle3D/textures/pump_pentagram_02.png new file mode 100644 index 0000000..49ddcbc Binary files /dev/null and b/res/chapter9/Particle3D/textures/pump_pentagram_02.png differ diff --git a/res/chapter9/Particle3D/textures/pump_smoke_01.png b/res/chapter9/Particle3D/textures/pump_smoke_01.png new file mode 100644 index 0000000..3e2735a Binary files /dev/null and b/res/chapter9/Particle3D/textures/pump_smoke_01.png differ diff --git a/res/chapter9/Particle3D/textures/pump_streak_03.png b/res/chapter9/Particle3D/textures/pump_streak_03.png new file mode 100644 index 0000000..a9cd103 Binary files /dev/null and b/res/chapter9/Particle3D/textures/pump_streak_03.png differ diff --git a/res/chapter9/box.c3t b/res/chapter9/box.c3t new file mode 100644 index 0000000..876194a --- /dev/null +++ b/res/chapter9/box.c3t @@ -0,0 +1,94 @@ +{ + "version": "0.6", + "id": "", + "meshes": [ + { + "attributes": [{ + "size": 3, + "type": "GL_FLOAT", + "attribute": "VERTEX_ATTRIB_POSITION" + }, { + "size": 3, + "type": "GL_FLOAT", + "attribute": "VERTEX_ATTRIB_NORMAL" + }, { + "size": 2, + "type": "GL_FLOAT", + "attribute": "VERTEX_ATTRIB_TEX_COORD" + }], + "vertices": [ + 0.500000, -0.500000, -0.500000, 0.000000, 0.000000, -1.000000, 0.000000, 0.000000, + -0.500000, -0.500000, -0.500000, 0.000000, 0.000000, -1.000000, 1.000000, 0.000000, + 0.500000, 0.500000, -0.500000, 0.000000, 0.000000, -1.000000, 0.000000, 1.000000, + -0.500000, 0.500000, -0.500000, 0.000000, 0.000000, -1.000000, 1.000000, 1.000000, + 0.500000, 0.500000, 0.500000, 0.000000, 0.000000, 1.000000, 1.000000, 1.000000, + -0.500000, 0.500000, 0.500000, 0.000000, 0.000000, 1.000000, 0.000000, 1.000000, + -0.500000, -0.500000, 0.500000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, + 0.500000, -0.500000, 0.500000, 0.000000, 0.000000, 1.000000, 1.000000, 0.000000, + 0.500000, -0.500000, 0.500000, 0.000000, -1.000000, 0.000000, 1.000000, 1.000000, + -0.500000, -0.500000, 0.500000, 0.000000, -1.000000, 0.000000, 0.000000, 1.000000, + -0.500000, -0.500000, -0.500000, 0.000000, -1.000000, 0.000000, 0.000000, 0.000000, + 0.500000, -0.500000, -0.500000, 0.000000, -1.000000, 0.000000, 1.000000, 0.000000, + 0.500000, 0.500000, 0.500000, 1.000000, 0.000000, 0.000000, 1.000000, 1.000000, + 0.500000, -0.500000, 0.500000, 1.000000, 0.000000, 0.000000, 0.000000, 1.000000, + 0.500000, -0.500000, -0.500000, 1.000000, 0.000000, 0.000000, 0.000000, 0.000000, + 0.500000, 0.500000, -0.500000, 1.000000, 0.000000, 0.000000, 1.000000, 0.000000, + -0.500000, 0.500000, 0.500000, 0.000000, 1.000000, 0.000000, 1.000000, 1.000000, + 0.500000, 0.500000, 0.500000, 0.000000, 1.000000, 0.000000, 0.000000, 1.000000, + 0.500000, 0.500000, -0.500000, 0.000000, 1.000000, 0.000000, 0.000000, 0.000000, + -0.500000, 0.500000, -0.500000, 0.000000, 1.000000, 0.000000, 1.000000, 0.000000, + -0.500000, -0.500000, 0.500000, -1.000000, 0.000000, 0.000000, 1.000000, 1.000000, + -0.500000, 0.500000, 0.500000, -1.000000, 0.000000, 0.000000, 0.000000, 1.000000, + -0.500000, 0.500000, -0.500000, -1.000000, 0.000000, 0.000000, 0.000000, 0.000000, + -0.500000, -0.500000, -0.500000, -1.000000, 0.000000, 0.000000, 1.000000, 0.000000 + ], + "parts": [ + { + "id": "shape1_part1", + "type": "TRIANGLES", + "indices": [ + 0, 1, 2, 1, 3, 2, 4, 5, 6, 4, 6, 7, + 8, 9, 10, 8, 10, 11, 12, 13, 14, 12, 14, 15, + 16, 17, 18, 16, 18, 19, 20, 21, 22, 20, 22, 23 + ], + "aabb": [-0.500000, -0.500000, -0.500000, 0.500000, 0.500000, 0.500000] + } + ] + } + ], + "materials": [ + { + "id": "01 - Default", + "ambient": [ 0.588235, 0.588235, 0.588235], + "diffuse": [ 0.588235, 0.588235, 0.588235], + "emissive": [ 0.000000, 0.000000, 0.000000], + "opacity": 1.000000, + "specular": [ 0.900000, 0.900000, 0.900000], + "shininess": 2.000000, + "textures": [ + { + "id": "Map #1", + "filename": "", + "type": "DIFFUSE", + "wrapModeU": "REPEAT", + "wrapModeV": "REPEAT" + } + ] + } + ], + "nodes": [ + { + "id": "Box001", + "skeleton": false, + "transform": [ 1.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, -1.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 1.000000], + "parts": [ + { + "meshpartid": "shape1_part1", + "materialid": "01 - Default", + "uvMapping": [[ 0]] + } + ] + } + ], + "animations": [] +} \ No newline at end of file diff --git a/src/chapter9/Chapter9.cpp b/src/chapter9/Chapter9.cpp index d861efb..2490b68 100644 --- a/src/chapter9/Chapter9.cpp +++ b/src/chapter9/Chapter9.cpp @@ -9,6 +9,9 @@ #include "Chapter9_8.h" #include "Chapter9_9.h" #include "Chapter9_10.h" +#include "Chapter9_11.h" +#include "Chapter9_12.h" +#include "Chapter9_13.h" USING_NS_CC; @@ -50,7 +53,7 @@ bool Chapter9::init() "CloseSelected.png", CC_CALLBACK_1(Chapter9::onMenuCloseCallback, this)); - closeItem->setPosition(Vec2(origin.x + visibleSize.width - closeItem->getContentSize().width/2 , + closeItem->setPosition(Vec2(origin.x + visibleSize.width - closeItem->getContentSize().width/2 , origin.y + closeItem->getContentSize().height/2)); // create menu, it's an autorelease object @@ -183,6 +186,44 @@ bool Chapter9::init() mainmenu->addChild(menuItem,2); mainmenu->setPosition(Vec2::ZERO); + + // add "Test Particle3D" + itemlabel = LabelTTF::create("Particle3D", "Arial", 24); + menuItem = MenuItemLabel::create(itemlabel); + menuItem->setCallback([&](cocos2d::Ref *sender) { + Director::getInstance()->replaceScene(Chapter9_11::createScene()); + }); + menuItem->setPosition(Vec2(origin.x + visibleSize.width / 2, origin.y + visibleSize.height / 2).x, + (Vec2(origin.x + visibleSize.width / 2, origin.y + visibleSize.height).y - (++index) * 40)); + + mainmenu->addChild(menuItem, 2); + mainmenu->setPosition(Vec2::ZERO); + + + // add "Test Physics3D" + itemlabel = LabelTTF::create("Physics3D", "Arial", 24); + menuItem = MenuItemLabel::create(itemlabel); + menuItem->setCallback([&](cocos2d::Ref *sender) { + Director::getInstance()->replaceScene(Chapter9_12::createScene()); + }); + menuItem->setPosition(Vec2(origin.x + visibleSize.width / 2, origin.y + visibleSize.height / 2).x, + (Vec2(origin.x + visibleSize.width / 2, origin.y + visibleSize.height).y - (++index) * 40)); + + mainmenu->addChild(menuItem, 2); + mainmenu->setPosition(Vec2::ZERO); + + + // add "Test NavMesh" + itemlabel = LabelTTF::create("NavMesh", "Arial", 24); + menuItem = MenuItemLabel::create(itemlabel); + menuItem->setCallback([&](cocos2d::Ref *sender) { + Director::getInstance()->replaceScene(Chapter9_13::createScene()); + }); + menuItem->setPosition(Vec2(origin.x + visibleSize.width / 2, origin.y + visibleSize.height / 2).x, + (Vec2(origin.x + visibleSize.width / 2, origin.y + visibleSize.height).y - (++index) * 40)); + + mainmenu->addChild(menuItem, 2); + mainmenu->setPosition(Vec2::ZERO); // add main menu this->addChild(mainmenu, 1); @@ -207,7 +248,7 @@ bool Chapter9::init() void Chapter9::onMenuCloseCallback(Ref* sender) { #if (CC_TARGET_PLATFORM == CC_PLATFORM_WP8) || (CC_TARGET_PLATFORM == CC_PLATFORM_WINRT) - MessageBox("You pressed the close button. Windows Store Apps do not implement a close button.","Alert"); + MessageBox("You pressed the close button. Windows Store Apps do not implement a close button.","Alert"); return; #endif diff --git a/src/chapter9/Chapter9_11.cpp b/src/chapter9/Chapter9_11.cpp new file mode 100644 index 0000000..5de0b39 --- /dev/null +++ b/src/chapter9/Chapter9_11.cpp @@ -0,0 +1,86 @@ +#include "Chapter9_11.h" +#include "Chapter9.h" +#include "extensions/Particle3D/PU/CCPUParticleSystem3D.h" + +USING_NS_CC; + +Scene* Chapter9_11::createScene() +{ + //cocos2d::Rect visibleRect = Director::getInstance()->getOpenGLView()->getVisibleRect(); + FileUtils::getInstance()->addSearchPath("Particle3D/scripts"); + Size visibleSize = Director::getInstance()->getVisibleSize(); + Vec2 origin = Director::getInstance()->getVisibleOrigin(); + auto winSize = Director::getInstance()->getWinSize(); + + // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + // create a scene + // 'scene' is an autorelease object + // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + auto scene = Scene::create(); + + // add title + auto label = LabelTTF::create("Particle3D Test", "Arial", 24); + label->setPosition(Vec2(origin.x+visibleSize.width/2, origin.y+visibleSize.height/2).x, + Vec2(origin.x+visibleSize.width/2, origin.y+visibleSize.height).y - 30); + + scene->addChild(label, -1); + + //add the menu item for back to main menu + label = LabelTTF::create("MainMenu", "Arial", 24); + + auto menuItem = MenuItemLabel::create(label); + menuItem->setCallback([&](cocos2d::Ref *sender) { + Director::getInstance()->replaceScene(Chapter9::createScene()); + }); + + auto menu = Menu::create(menuItem, nullptr); + + menu->setPosition( Vec2::ZERO ); + menuItem->setPosition( Vec2( Vec2(origin.x+visibleSize.width, origin.y+visibleSize.height/2).x - 80, Vec2(origin.x+visibleSize.width/2, origin.y).y + 25) ); + + scene->addChild(menu, 1); + + + auto camera = Camera::createPerspective(60, (GLfloat)winSize.width / winSize.height, 1.0f, 1000.0f); + camera->setCameraFlag(CameraFlag::USER1); + camera->setPosition3D(Vec3(0.0, 0.0, 60)); + camera->lookAt(Vec3(0.0, 0.0, 0.0), Vec3(0.0, 1.0, 0.0)); + scene->addChild(camera); + + + auto sprite3d = Sprite3D::create("orc.c3b"); + sprite3d->setPosition3D(Vec3(-30.0f, 0.0f, 0.0f)); + sprite3d->setRotation3D(Vec3(0.0f, 180.0f, 0.0f)); + scene->addChild(sprite3d); + auto animation = Animation3D::create("orc.c3b"); + if (animation) + { + auto animate = Animate3D::create(animation); + sprite3d->runAction(RepeatForever::create(animate)); + } + auto handlerps = PUParticleSystem3D::create("lightningBolt.pu"); + //handlerps->setScale(10.0f); + handlerps->startParticleSystem(); + sprite3d->getAttachNode("Bip001 L Hand")->addChild(handlerps); + sprite3d->setCameraMask((unsigned short)CameraFlag::USER1); + + + auto ps1 = PUParticleSystem3D::create("lineStreak.pu"); + ps1->setPosition3D(Vec3(30.0f, 0.0f, 0.0f)); + ps1->setScale(2.0f); + ps1->setCameraMask((unsigned short)CameraFlag::USER1); + ps1->startParticleSystem(); + scene->addChild(ps1); + + auto ps2 = PUParticleSystem3D::create("blackHole.pu"); + ps2->setPosition(-20.0f, 0.0f); + auto moveby = MoveBy::create(2.0f, Vec2(40.0f, 0.0f)); + auto moveby1 = MoveBy::create(2.0f, Vec2(-40.0f, 0.0f)); + ps2->runAction(RepeatForever::create(Sequence::create(moveby, moveby1, nullptr))); + ps2->setCameraMask((unsigned short)CameraFlag::USER1); + ps2->startParticleSystem(); + scene->addChild(ps2); + + // return the scene + return scene; +} \ No newline at end of file diff --git a/src/chapter9/Chapter9_11.h b/src/chapter9/Chapter9_11.h new file mode 100644 index 0000000..170b4cc --- /dev/null +++ b/src/chapter9/Chapter9_11.h @@ -0,0 +1,15 @@ +#ifndef __CHAPTER_9_11_H__ +#define __CHAPTER_9_11_H__ + +#include "cocos2d.h" +#include "DrawNode3D.h" + +USING_NS_CC; + +class Chapter9_11 : public Ref +{ +public: + static cocos2d::Scene* createScene(); +}; + +#endif // __CHAPTER_9_11_H__ \ No newline at end of file diff --git a/src/chapter9/Chapter9_12.cpp b/src/chapter9/Chapter9_12.cpp new file mode 100644 index 0000000..98d829b --- /dev/null +++ b/src/chapter9/Chapter9_12.cpp @@ -0,0 +1,143 @@ +#include "Chapter9_12.h" +#include "Chapter9.h" +#include "physics3d/CCPhysics3D.h" +#include "3d/CCBundle3D.h" + +USING_NS_CC; + +#define START_POS_X -15.0 +#define START_POS_Y 10.0 +#define START_POS_Z -0.5 + +#define ARRAY_SIZE_X 4 +#define ARRAY_SIZE_Y 3 +#define ARRAY_SIZE_Z 4 + +Scene* Chapter9_12::createScene() +{ + //cocos2d::Rect visibleRect = Director::getInstance()->getOpenGLView()->getVisibleRect(); + Size visibleSize = Director::getInstance()->getVisibleSize(); + Vec2 origin = Director::getInstance()->getVisibleOrigin(); + auto winSize = Director::getInstance()->getWinSize(); + + // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + // create a scene + // 'scene' is an autorelease object + // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + auto scene = Scene::create(); + if (!scene->initWithPhysics()) return nullptr; + + // add title + auto label = LabelTTF::create("Physics3D Test", "Arial", 24); + label->setPosition(Vec2(origin.x+visibleSize.width/2, origin.y+visibleSize.height/2).x, + Vec2(origin.x+visibleSize.width/2, origin.y+visibleSize.height).y - 30); + + scene->addChild(label, -1); + + //add the menu item for back to main menu + label = LabelTTF::create("MainMenu", "Arial", 24); + + auto menuItem = MenuItemLabel::create(label); + menuItem->setCallback([&](cocos2d::Ref *sender) { + Director::getInstance()->replaceScene(Chapter9::createScene()); + }); + + auto menu = Menu::create(menuItem, nullptr); + + menu->setPosition( Vec2::ZERO ); + menuItem->setPosition( Vec2( Vec2(origin.x+visibleSize.width, origin.y+visibleSize.height/2).x - 80, Vec2(origin.x+visibleSize.width/2, origin.y).y + 25) ); + + scene->addChild(menu, 1); + + + auto camera = Camera::createPerspective(60, (GLfloat)winSize.width / winSize.height, 1.0f, 1000.0f); + camera->setCameraFlag(CameraFlag::USER1); + camera->setPosition3D(Vec3(0.0, 0.0f, 60.0f)); + camera->lookAt(Vec3(0.0, 0.0, 0.0), Vec3(0.0, 1.0, 0.0)); + scene->addChild(camera); + + //PhysicsSprite3D = Sprite3D + Physics3DComponent + Physics3DRigidBodyDes rbDes; + rbDes.disableSleep = true; + auto sprite = Sprite3D::create("orc.c3b"); + rbDes.mass = 10.f; + rbDes.shape = Physics3DShape::createBox(Vec3(5.0f, 5.0f, 5.0f)); + auto rigidBody = Physics3DRigidBody::create(&rbDes); + Quaternion quat; + Quaternion::createFromAxisAngle(Vec3(0.f, 1.f, 0.f), CC_DEGREES_TO_RADIANS(180), &quat); + auto component = Physics3DComponent::create(rigidBody, Vec3(0.f, -3.f, 0.f), quat); + sprite->addComponent(component); + scene->addChild(sprite); + sprite->setCameraMask((unsigned short)CameraFlag::USER1); + sprite->setScale(0.4f); + sprite->setPosition3D(Vec3(10.f, 0.f, 0.f)); + //sync node position to physics + component->syncNodeToPhysics(); + //physics controlled, we will not set position for it, so we can skip sync node position to physics + component->setSyncFlag(Physics3DComponent::PhysicsSyncFlag::PHYSICS_TO_NODE); + //create point to point constraint + Physics3DConstraint* constraint = Physics3DPointToPointConstraint::create(rigidBody, Vec3(2.5f, 2.5f, 2.5f)); + scene->getPhysics3DWorld()->addPhysics3DConstraint(constraint); + + + //create kinematic + rbDes.mass = 0.f; //kinematic objects. zero mass so that it can not be affected by other dynamic objects + rbDes.shape = Physics3DShape::createBox(Vec3(100.0f, 2.0f, 100.0f)); + auto phySprite = PhysicsSprite3D::create("box.c3t", &rbDes); + phySprite->setTexture("HelloWorld.png"); + phySprite->setCameraMask((unsigned short)CameraFlag::USER1); + rigidBody = static_cast(phySprite->getPhysicsObj()); + rigidBody->setKinematic(true); + scene->addChild(phySprite); + phySprite->setScale(100.0f); + phySprite->setScaleY(2.0f); + phySprite->setPosition3D(Vec3(0.0f, -20.0f, 0.0f)); + phySprite->setRotation3D(Vec3(0.0f, 180.0f, 0.0f)); + //create mesh + std::vector trianglesList = Bundle3D::getTrianglesList("boss.c3b"); + + rbDes.mass = 0.0f; + rbDes.shape = Physics3DShape::createMesh(&trianglesList[0], (int)trianglesList.size() / 3); + rigidBody = Physics3DRigidBody::create(&rbDes); + component = Physics3DComponent::create(rigidBody); + sprite = Sprite3D::create("boss.c3b"); + sprite->addComponent(component); + sprite->setRotation3D(Vec3(-90.0f, 0.0f, 0.0f)); + sprite->setPosition3D(Vec3(-10.0f, 0.0f, 0.0f)); + sprite->setCameraMask((unsigned short)CameraFlag::USER1); + scene->addChild(sprite); + + //create several boxes using PhysicsSprite3D + rbDes.mass = 1.f; + rbDes.shape = Physics3DShape::createBox(Vec3(2.0f, 2.0f, 2.0f)); + float start_x = START_POS_X - ARRAY_SIZE_X / 2; + float start_y = START_POS_Y; + float start_z = START_POS_Z - ARRAY_SIZE_Z / 2; + for (int k = 0; k < ARRAY_SIZE_Y; k++) + { + for (int i = 0; i < ARRAY_SIZE_X; i++) + { + for (int j = 0; j < ARRAY_SIZE_Z; j++) + { + float x = 10.0*i + start_x; + float y = 5.0 + 1.0*k + start_y; + float z = 10.0*j + start_z; + + auto sprite = PhysicsSprite3D::create("box.c3t", &rbDes); + sprite->setTexture("HelloWorld.png"); + sprite->setPosition3D(Vec3(x, y, z)); + sprite->syncNodeToPhysics(); + sprite->setSyncFlag(Physics3DComponent::PhysicsSyncFlag::PHYSICS_TO_NODE); + sprite->setCameraMask((unsigned short)CameraFlag::USER1); + sprite->setScale(2.0f); + scene->addChild(sprite); + } + } + } + + //scene->getPhysics3DWorld()->setDebugDrawEnable(true); + scene->setPhysics3DDebugCamera(camera); + + // return the scene + return scene; +} \ No newline at end of file diff --git a/src/chapter9/Chapter9_12.h b/src/chapter9/Chapter9_12.h new file mode 100644 index 0000000..ba90d64 --- /dev/null +++ b/src/chapter9/Chapter9_12.h @@ -0,0 +1,15 @@ +#ifndef __CHAPTER_9_12_H__ +#define __CHAPTER_9_12_H__ + +#include "cocos2d.h" +#include "DrawNode3D.h" + +USING_NS_CC; + +class Chapter9_12 : public Ref +{ +public: + static cocos2d::Scene* createScene(); +}; + +#endif // __CHAPTER_9_12_H__ \ No newline at end of file diff --git a/src/chapter9/Chapter9_13.cpp b/src/chapter9/Chapter9_13.cpp new file mode 100644 index 0000000..7009df1 --- /dev/null +++ b/src/chapter9/Chapter9_13.cpp @@ -0,0 +1,128 @@ +#include "Chapter9_13.h" +#include "Chapter9.h" +#include "navmesh/CCNavMesh.h" +#include "physics3d/CCPhysics3D.h" +#include "3d/CCBundle3D.h" + +USING_NS_CC; + +Scene* Chapter9_13::createScene() +{ + //cocos2d::Rect visibleRect = Director::getInstance()->getOpenGLView()->getVisibleRect(); + FileUtils::getInstance()->addSearchPath("Particle3D/scripts"); + Size visibleSize = Director::getInstance()->getVisibleSize(); + Vec2 origin = Director::getInstance()->getVisibleOrigin(); + auto winSize = Director::getInstance()->getWinSize(); + + // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + // create a scene + // 'scene' is an autorelease object + // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + auto scene = Scene::create(); + if (!scene->initWithPhysics()) return nullptr; + + auto navMesh = NavMesh::create("NavMesh/all_tiles_tilecache.bin", "NavMesh/geomset.txt"); + scene->setNavMesh(navMesh); + + // add title + auto label = LabelTTF::create("NavMesh Test", "Arial", 24); + label->setPosition(Vec2(origin.x+visibleSize.width/2, origin.y+visibleSize.height/2).x, + Vec2(origin.x+visibleSize.width/2, origin.y+visibleSize.height).y - 30); + + scene->addChild(label, -1); + + //add the menu item for back to main menu + label = LabelTTF::create("MainMenu", "Arial", 24); + + auto menuItem = MenuItemLabel::create(label); + menuItem->setCallback([&](cocos2d::Ref *sender) { + Director::getInstance()->replaceScene(Chapter9::createScene()); + }); + + auto menu = Menu::create(menuItem, nullptr); + + menu->setPosition( Vec2::ZERO ); + menuItem->setPosition( Vec2( Vec2(origin.x+visibleSize.width, origin.y+visibleSize.height/2).x - 80, Vec2(origin.x+visibleSize.width/2, origin.y).y + 25) ); + + scene->addChild(menu, 1); + + + auto camera = Camera::createPerspective(60, (GLfloat)winSize.width / winSize.height, 1.0f, 1000.0f); + camera->setCameraFlag(CameraFlag::USER1); + camera->setPosition3D(Vec3(0.0f, 30.0f, 60.0f)); + camera->lookAt(Vec3(0.0, 0.0, 0.0), Vec3(0.0, 1.0, 0.0)); + scene->addChild(camera); + + //create mesh + std::vector trianglesList = Bundle3D::getTrianglesList("NavMesh/scene.obj"); + + Physics3DRigidBodyDes rbDes; + rbDes.mass = 0.0f; + rbDes.shape = Physics3DShape::createMesh(&trianglesList[0], (int)trianglesList.size() / 3); + auto rigidBody = Physics3DRigidBody::create(&rbDes); + auto component = Physics3DComponent::create(rigidBody); + auto sprite = Sprite3D::create("NavMesh/scene.obj"); + sprite->addComponent(component); + sprite->setCameraMask((unsigned short)CameraFlag::USER1); + scene->addChild(sprite); + + + std::string filePath = "girl.c3b"; + NavMeshAgentParam param; + param.radius = 2.0f; + param.height = 8.0f; + param.maxSpeed = 8.0f; + auto agent = NavMeshAgent::create(param); + auto agentNode = Sprite3D::create(filePath); + agent->setOrientationRefAxes(Vec3(-1.0f, 0.0f, 1.0f)); + agentNode->setPosition3D(Vec3(30.0f, 1.0f, 0.0f)); + agentNode->setScale(0.05f); + agentNode->addComponent(agent); + agentNode->setCameraMask((unsigned short)CameraFlag::USER1); + scene->addChild(agentNode); + + { + auto obstacle = NavMeshObstacle::create(2.0f, 6.0f); + auto obstacleNode = Sprite3D::create("box.c3t"); + obstacleNode->setTexture("HelloWorld.png"); + obstacleNode->setPosition3D(Vec3(35.0f, 1.0f, 10.0f)); + obstacleNode->setScale(3.0f); + obstacleNode->setScaleY(10.0f); + obstacleNode->addComponent(obstacle); + obstacleNode->setCameraMask((unsigned short)CameraFlag::USER1); + scene->addChild(obstacleNode); + } + + { + auto obstacle = NavMeshObstacle::create(2.0f, 6.0f); + auto obstacleNode = Sprite3D::create("box.c3t"); + obstacleNode->setTexture("HelloWorld.png"); + obstacleNode->setPosition3D(Vec3(-35.0f, 1.0f, 0.0f)); + obstacleNode->setScale(3.0f); + obstacleNode->setScaleY(10.0f); + obstacleNode->addComponent(obstacle); + obstacleNode->setCameraMask((unsigned short)CameraFlag::USER1); + scene->addChild(obstacleNode); + } + + agentNode->runAction(RepeatForever::create(Sequence::create(CallFunc::create([=](){ + float x = cocos2d::random(-50.0f, 50.0f); + float z = cocos2d::random(-50.0f, 50.0f); + Physics3DWorld::HitResult result; + scene->getPhysics3DWorld()->rayCast(Vec3(x, 50.0f, z), Vec3(x, -50.0f, z), &result); + agent->move(result.hitPosition); + }), DelayTime::create(5.0f), nullptr))); + + auto animation = Animation3D::create(filePath); + auto animate = Animate3D::create(animation); + if (animate){ + agentNode->runAction(RepeatForever::create(animate)); + //animate->setSpeed(0); + } + + navMesh->setDebugDrawEnable(true); + scene->setNavMeshDebugCamera(camera); + + // return the scene + return scene; +} \ No newline at end of file diff --git a/src/chapter9/Chapter9_13.h b/src/chapter9/Chapter9_13.h new file mode 100644 index 0000000..7b82c1e --- /dev/null +++ b/src/chapter9/Chapter9_13.h @@ -0,0 +1,16 @@ +#ifndef __CHAPTER_9_13_H__ +#define __CHAPTER_9_13_H__ + +#include "cocos2d.h" +#include "DrawNode3D.h" + +USING_NS_CC; + +class Chapter9_13 : public Ref +{ +public: + static cocos2d::Scene* createScene(); + +}; + +#endif // __CHAPTER_9_13_H__ \ No newline at end of file