diff --git a/.github/workflows/build-nightly.yml b/.github/workflows/build-nightly.yml index a83066bfa..154b229f0 100644 --- a/.github/workflows/build-nightly.yml +++ b/.github/workflows/build-nightly.yml @@ -5,6 +5,19 @@ on: - cron: '0 0 * * *' jobs: + + content: + runs-on: windows-latest + steps: + - uses: actions/checkout@v2 + - name: Package Content + uses: actions/upload-artifact@v2 + with: + name: Content + path: | + Content/models + Content/scripts + windows: runs-on: windows-latest steps: @@ -22,52 +35,29 @@ jobs: cd .. "C:/Program Files/Microsoft Visual Studio/2022/Enterprise/MSBuild/Current/Bin/MSBuild.exe" WickedEngine.sln /t:rebuild /m /p:Configuration=Release /p:Platform=x64 - - name: Move binaries + - name: Move files shell: cmd run: | - move BUILD\x64\Release\Editor_Windows\Editor_Windows.exe Editor\ - - move BUILD\x64\Release\Tests\Tests.exe Tests\ + move BUILD\x64\Release\Editor_Windows\Editor_Windows.exe .\ + move Editor\config.ini .\ + move Editor\startup.lua .\ + move Editor\terrain .\ + move Content\Documentation .\ - name: Package Editor uses: actions/upload-artifact@v2 with: - name: Editor (Windows x64) + name: Editor (Windows) path: | - Content/ - README.md - LICENSE.md - third_party_software.txt - features.txt - Editor/terrain/ - Editor/sound/ - Editor/*.ini - Editor/*.ico - Editor/*.lua - Editor/*.exe - - - name: Package Tests - uses: actions/upload-artifact@v2 - with: - name: Tests (Windows x64) - path: | - Content/ - README.md - LICENSE.md - third_party_software.txt - features.txt - Tests/images/ - Tests/sound/ - Tests/*.ini - Tests/*.txt - Tests/*.ico - Tests/*.lua - Tests/*.ttf - Tests/*.exe + Documentation/ + terrain/ + config.ini + startup.lua + Editor_Windows.exe linux: - runs-on: ubuntu-20.04 + runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 @@ -90,50 +80,28 @@ jobs: echo "---Rebuilding with ShaderDump---" make -B -j $(nproc) - - name: Move binaries + - name: Move files run: | - mv build/Editor/WickedEngineEditor Editor/ - mv build/Tests/Tests Tests/ + mv build/Editor/WickedEngineEditor ./ + mv Editor/config.ini ./ + mv Editor/startup.lua ./ + mv Editor/terrain ./ + mv Content/Documentation ./ - name: Package Editor uses: actions/upload-artifact@v2 with: - name: Editor (Ubuntu 20.04) + name: Editor (Linux - Ubuntu) path: | - Content/ - README.md - LICENSE.md - third_party_software.txt - features.txt - Editor/terrain/ - Editor/sound/ - Editor/*.ini - Editor/*.ico - Editor/*.lua - Editor/WickedEngineEditor - - - name: Package Tests - uses: actions/upload-artifact@v2 - with: - name: Tests (Ubuntu 20.04) - path: | - Content/ - README.md - LICENSE.md - third_party_software.txt - features.txt - Tests/images/ - Tests/sound/ - Tests/*.ini - Tests/*.txt - Tests/*.ico - Tests/*.lua - Tests/*.ttf - Tests/Tests + Documentation/ + terrain/ + config.ini + startup.lua + WickedEngineEditor linux-steamdeck: - runs-on: ubuntu-20.04 + runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 @@ -158,43 +126,21 @@ jobs: podman run --name sniper -v $PWD:/build registry.gitlab.steamos.cloud/steamrt/sniper/sdk:latest /build/build.sh podman container rm sniper - - name: Move binaries + - name: Move files run: | - mv build/Editor/WickedEngineEditor Editor/ - mv build/Tests/Tests Tests/ + mv build/Editor/WickedEngineEditor ./ + mv Editor/config.ini ./ + mv Editor/startup.lua ./ + mv Editor/terrain ./ + mv Content/Documentation ./ - name: Package Editor uses: actions/upload-artifact@v2 with: - name: Editor (Linux - Steam SDK) + name: Editor (Linux - Steam Deck) path: | - Content/ - README.md - LICENSE.md - third_party_software.txt - features.txt - Editor/terrain/ - Editor/sound/ - Editor/*.ini - Editor/*.ico - Editor/*.lua - Editor/WickedEngineEditor - - - name: Package Tests - uses: actions/upload-artifact@v2 - with: - name: Tests (Linux - Steam SDK) - path: | - Content/ - README.md - LICENSE.md - third_party_software.txt - features.txt - Tests/images/ - Tests/sound/ - Tests/*.ini - Tests/*.txt - Tests/*.ico - Tests/*.lua - Tests/*.ttf - Tests/Tests + Documentation/ + terrain/ + config.ini + startup.lua + WickedEngineEditor diff --git a/.github/workflows/build-pr.yml b/.github/workflows/build-pr.yml index 1a333d2d4..62972571d 100644 --- a/.github/workflows/build-pr.yml +++ b/.github/workflows/build-pr.yml @@ -4,6 +4,19 @@ on: pull_request jobs: + + content: + runs-on: windows-latest + steps: + - uses: actions/checkout@v2 + - name: Package Content + uses: actions/upload-artifact@v2 + with: + name: Content + path: | + Content/models + Content/scripts + windows: runs-on: windows-latest steps: @@ -21,52 +34,29 @@ jobs: cd .. "C:/Program Files/Microsoft Visual Studio/2022/Enterprise/MSBuild/Current/Bin/MSBuild.exe" WickedEngine.sln /t:rebuild /m /p:Configuration=Release /p:Platform=x64 - - name: Move binaries + - name: Move files shell: cmd run: | - move BUILD\x64\Release\Editor_Windows\Editor_Windows.exe Editor\ - - move BUILD\x64\Release\Tests\Tests.exe Tests\ + move BUILD\x64\Release\Editor_Windows\Editor_Windows.exe .\ + move Editor\config.ini .\ + move Editor\startup.lua .\ + move Editor\terrain .\ + move Content\Documentation .\ - name: Package Editor uses: actions/upload-artifact@v2 with: - name: Editor (Windows x64) + name: Editor (Windows) path: | - Content/ - README.md - LICENSE.md - third_party_software.txt - features.txt - Editor/terrain/ - Editor/sound/ - Editor/*.ini - Editor/*.ico - Editor/*.lua - Editor/*.exe - - - name: Package Tests - uses: actions/upload-artifact@v2 - with: - name: Tests (Windows x64) - path: | - Content/ - README.md - LICENSE.md - third_party_software.txt - features.txt - Tests/images/ - Tests/sound/ - Tests/*.ini - Tests/*.txt - Tests/*.ico - Tests/*.lua - Tests/*.ttf - Tests/*.exe + Documentation/ + terrain/ + config.ini + startup.lua + Editor_Windows.exe linux: - runs-on: ubuntu-20.04 + runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 @@ -92,48 +82,26 @@ jobs: - name: Move binaries run: | - mv build/Editor/WickedEngineEditor Editor/ - mv build/Tests/Tests Tests/ + mv build/Editor/WickedEngineEditor ./ + mv Editor/config.ini ./ + mv Editor/startup.lua ./ + mv Editor/terrain ./ + mv Content/Documentation ./ - name: Package Editor uses: actions/upload-artifact@v2 with: - name: Editor (Ubuntu 20.04) + name: Editor (Linux - Ubuntu) path: | - Content/ - README.md - LICENSE.md - third_party_software.txt - features.txt - Editor/terrain/ - Editor/sound/ - Editor/*.ini - Editor/*.ico - Editor/*.lua - Editor/WickedEngineEditor - - - name: Package Tests - uses: actions/upload-artifact@v2 - with: - name: Tests (Ubuntu 20.04) - path: | - Content/ - README.md - LICENSE.md - third_party_software.txt - features.txt - Tests/images/ - Tests/sound/ - Tests/*.ini - Tests/*.txt - Tests/*.ico - Tests/*.lua - Tests/*.ttf - Tests/Tests + Documentation/ + terrain/ + config.ini + startup.lua + WickedEngineEditor linux-steamdeck: - runs-on: ubuntu-20.04 + runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 @@ -158,43 +126,21 @@ jobs: podman run --name sniper -v $PWD:/build registry.gitlab.steamos.cloud/steamrt/sniper/sdk:latest /build/build.sh podman container rm sniper - - name: Move binaries + - name: Move files run: | - mv build/Editor/WickedEngineEditor Editor/ - mv build/Tests/Tests Tests/ + mv build/Editor/WickedEngineEditor ./ + mv Editor/config.ini ./ + mv Editor/startup.lua ./ + mv Editor/terrain ./ + mv Content/Documentation ./ - name: Package Editor uses: actions/upload-artifact@v2 with: - name: Editor (Linux - Steam SDK) + name: Editor (Linux - Steam Deck) path: | - Content/ - README.md - LICENSE.md - third_party_software.txt - features.txt - Editor/terrain/ - Editor/sound/ - Editor/*.ini - Editor/*.ico - Editor/*.lua - Editor/WickedEngineEditor - - - name: Package Tests - uses: actions/upload-artifact@v2 - with: - name: Tests (Linux - Steam SDK) - path: | - Content/ - README.md - LICENSE.md - third_party_software.txt - features.txt - Tests/images/ - Tests/sound/ - Tests/*.ini - Tests/*.txt - Tests/*.ico - Tests/*.lua - Tests/*.ttf - Tests/Tests + Documentation/ + terrain/ + config.ini + startup.lua + WickedEngineEditor diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 54f75cee0..15c8c6b74 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -5,6 +5,19 @@ on: branches: [ master ] jobs: + + content: + runs-on: windows-latest + steps: + - uses: actions/checkout@v2 + - name: Package Content + uses: actions/upload-artifact@v2 + with: + name: Content + path: | + Content/models + Content/scripts + windows: runs-on: windows-latest steps: @@ -22,52 +35,29 @@ jobs: cd .. "C:/Program Files/Microsoft Visual Studio/2022/Enterprise/MSBuild/Current/Bin/MSBuild.exe" WickedEngine.sln /t:rebuild /m /p:Configuration=Release /p:Platform=x64 - - name: Move binaries + - name: Move files shell: cmd run: | - move BUILD\x64\Release\Editor_Windows\Editor_Windows.exe Editor\ - - move BUILD\x64\Release\Tests\Tests.exe Tests\ + move BUILD\x64\Release\Editor_Windows\Editor_Windows.exe .\ + move Editor\config.ini .\ + move Editor\startup.lua .\ + move Editor\terrain .\ + move Content\Documentation .\ - name: Package Editor uses: actions/upload-artifact@v2 with: - name: Editor (Windows x64) + name: Editor (Windows) path: | - Content/ - README.md - LICENSE.md - third_party_software.txt - features.txt - Editor/terrain/ - Editor/sound/ - Editor/*.ini - Editor/*.ico - Editor/*.lua - Editor/*.exe - - - name: Package Tests - uses: actions/upload-artifact@v2 - with: - name: Tests (Windows x64) - path: | - Content/ - README.md - LICENSE.md - third_party_software.txt - features.txt - Tests/images/ - Tests/sound/ - Tests/*.ini - Tests/*.txt - Tests/*.ico - Tests/*.lua - Tests/*.ttf - Tests/*.exe + Documentation/ + terrain/ + config.ini + startup.lua + Editor_Windows.exe linux: - runs-on: ubuntu-20.04 + runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 @@ -91,50 +81,28 @@ jobs: make -B -j $(nproc) - - name: Move binaries + - name: Move files run: | - mv build/Editor/WickedEngineEditor Editor/ - mv build/Tests/Tests Tests/ + mv build/Editor/WickedEngineEditor ./ + mv Editor/config.ini ./ + mv Editor/startup.lua ./ + mv Editor/terrain ./ + mv Content/Documentation ./ - name: Package Editor uses: actions/upload-artifact@v2 with: - name: Editor (Ubuntu 20.04) + name: Editor (Linux - Ubuntu) path: | - Content/ - README.md - LICENSE.md - third_party_software.txt - features.txt - Editor/terrain/ - Editor/sound/ - Editor/*.ini - Editor/*.ico - Editor/*.lua - Editor/WickedEngineEditor - - - name: Package Tests - uses: actions/upload-artifact@v2 - with: - name: Tests (Ubuntu 20.04) - path: | - Content/ - README.md - LICENSE.md - third_party_software.txt - features.txt - Tests/images/ - Tests/sound/ - Tests/*.ini - Tests/*.txt - Tests/*.ico - Tests/*.lua - Tests/*.ttf - Tests/Tests + Documentation/ + terrain/ + config.ini + startup.lua + WickedEngineEditor linux-steamdeck: - runs-on: ubuntu-20.04 + runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 @@ -159,43 +127,21 @@ jobs: podman run --name sniper -v $PWD:/build registry.gitlab.steamos.cloud/steamrt/sniper/sdk:latest /build/build.sh podman container rm sniper - - name: Move binaries + - name: Move files run: | - mv build/Editor/WickedEngineEditor Editor/ - mv build/Tests/Tests Tests/ + mv build/Editor/WickedEngineEditor ./ + mv Editor/config.ini ./ + mv Editor/startup.lua ./ + mv Editor/terrain ./ + mv Content/Documentation ./ - name: Package Editor uses: actions/upload-artifact@v2 with: - name: Editor (Linux - Steam SDK) + name: Editor (Linux - Steam Deck) path: | - Content/ - README.md - LICENSE.md - third_party_software.txt - features.txt - Editor/terrain/ - Editor/sound/ - Editor/*.ini - Editor/*.ico - Editor/*.lua - Editor/WickedEngineEditor - - - name: Package Tests - uses: actions/upload-artifact@v2 - with: - name: Tests (Linux - Steam SDK) - path: | - Content/ - README.md - LICENSE.md - third_party_software.txt - features.txt - Tests/images/ - Tests/sound/ - Tests/*.ini - Tests/*.txt - Tests/*.ico - Tests/*.lua - Tests/*.ttf - Tests/Tests + Documentation/ + terrain/ + config.ini + startup.lua + WickedEngineEditor diff --git a/Content/Content.vcxitems b/Content/Content.vcxitems index df4c7dfce..114178038 100644 --- a/Content/Content.vcxitems +++ b/Content/Content.vcxitems @@ -88,136 +88,6 @@ true true - - true - true - true - true - true - true - true - true - - - true - true - true - true - true - true - true - true - - - true - true - true - true - true - true - true - true - - - true - true - true - true - true - true - true - true - - - true - true - true - true - true - true - true - true - - - true - true - true - true - true - true - true - true - - - true - true - true - true - true - true - true - true - - - true - true - true - true - true - true - true - true - - - true - true - true - true - true - true - true - true - - - true - true - true - true - true - true - true - true - - - true - true - true - true - true - true - true - true - - - true - true - true - true - true - true - true - true - - - true - true - true - true - true - true - true - true - true true @@ -228,26 +98,6 @@ true true - - true - true - true - true - true - true - true - true - - - true - true - true - true - true - true - true - true - true true @@ -258,26 +108,6 @@ true true - - true - true - true - true - true - true - true - true - - - true - true - true - true - true - true - true - true - true true @@ -298,26 +128,6 @@ true true - - true - true - true - true - true - true - true - true - - - true - true - true - true - true - true - true - true - true true @@ -332,16 +142,6 @@ true true - - true - true - true - true - true - true - true - true - true true @@ -376,16 +176,6 @@ true true - - true - true - true - true - true - true - true - true - true true @@ -514,16 +304,55 @@ true true - - true - true - true - true - true - true + true true + + true + true + + + true + true + + + true + true + + + true + true + + + true + true + + + true + true + + + true + true + + + true + true + + + true + true + + + true + true + + + true + true + + true true @@ -534,16 +363,55 @@ true true - - true - true - true - true - true - true + true true + + true + true + + + true + true + + + true + true + + + true + true + + + true + true + + + true + true + + + true + true + + + true + true + + + true + true + + + true + true + + + true + true + + true true @@ -554,16 +422,35 @@ true true - - true - true - true - true - true - true + true true + + true + true + + + true + true + + + true + true + + + true + true + + + true + true + + + true + true + + true true @@ -626,7 +513,7 @@ true true - + true true @@ -645,9 +532,6 @@ - - - @@ -730,7 +614,17 @@ - + + + + + + + + + + + diff --git a/Content/Content.vcxitems.filters b/Content/Content.vcxitems.filters index 9c8fc9a04..3648ae69b 100644 --- a/Content/Content.vcxitems.filters +++ b/Content/Content.vcxitems.filters @@ -13,18 +13,30 @@ {313c5c5a-2029-43a8-99ca-cc56f435121c} - - {6f72400d-8b00-4dc0-8015-f88dd5d4c11b} - - - {2ba616fc-e2c9-4af4-9099-948f45e2dd80} - {c66293fd-fe0c-444e-9502-f0864bfbf736} {7a1dfecb-b9bf-4fb6-94cf-39b5fb5860c1} + + {1957f2fb-352c-4e23-aa30-a421c6dbda87} + + + {4d95c5f8-6444-4426-ab19-873a8184f693} + + + {07f4c6e7-1f4b-4c5c-992b-6ab3c4d90624} + + + {a6ff27c6-f634-4cf2-844f-9696c405c67f} + + + {33988dfe-9428-4de4-b6b4-19cf5b3833f6} + + + {a8242a40-dd2a-46f8-95a9-1b7431c79043} + @@ -33,21 +45,12 @@ scripts - - scripts - scripts - - scripts - scripts - - scripts - scripts @@ -66,45 +69,6 @@ models\Sponza - - models\Havoc - - - models\dungeon - - - models\dungeon - - - models\dungeon - - - models\dungeon - - - models\dungeon - - - models\dungeon - - - models\dungeon - - - models\dungeon - - - models\dungeon - - - models\dungeon - - - models\dungeon - - - models\dungeon - models @@ -117,39 +81,18 @@ models - - models - models - - models - - - models - models - - models - - - models - models models - - models - - - models - models @@ -162,9 +105,6 @@ models - - models - models @@ -213,9 +153,6 @@ scripts - - scripts\subscript_demo - models @@ -228,6 +165,111 @@ models + + scripts\fighting_game\assets + + + scripts\fighting_game\assets + + + scripts\fighting_game\assets + + + scripts\fighting_game\assets + + + scripts\fighting_game\assets + + + scripts\fighting_game\assets + + + scripts\fighting_game\assets + + + scripts\fighting_game + + + scripts\character_controller\assets + + + scripts\character_controller\assets + + + scripts\character_controller\assets + + + scripts\character_controller\assets + + + scripts\character_controller\assets + + + scripts\character_controller\assets + + + scripts\character_controller\assets + + + scripts\character_controller\assets + + + scripts\character_controller\assets + + + scripts\character_controller\assets + + + scripts\character_controller\assets + + + scripts\character_controller\assets + + + scripts\character_controller + + + scripts\dungeon_generator\assets + + + scripts\dungeon_generator\assets + + + scripts\dungeon_generator\assets + + + scripts\dungeon_generator\assets + + + scripts\dungeon_generator\assets + + + scripts\dungeon_generator\assets + + + scripts\dungeon_generator\assets + + + scripts\dungeon_generator\assets + + + scripts\dungeon_generator\assets + + + scripts\dungeon_generator\assets + + + scripts\dungeon_generator\assets + + + scripts\dungeon_generator\assets + + + scripts\dungeon_generator + + + scripts\subscript_demo + @@ -461,12 +503,6 @@ models\Sponza\textures - - models\Havoc - - - models\Havoc - models @@ -497,9 +533,6 @@ models - - models - models @@ -515,9 +548,6 @@ models - - scripts - models @@ -527,6 +557,39 @@ models + + scripts\fighting_game\assets + + + scripts\fighting_game\assets + + + scripts\fighting_game\assets + + + scripts\fighting_game\assets + + + scripts\fighting_game\assets + + + scripts\fighting_game\assets + + + scripts\fighting_game\assets + + + scripts\fighting_game\assets + + + scripts\character_controller\assets + + + scripts\character_controller\assets + + + scripts\character_controller\assets + diff --git a/Content/Documentation/ScriptingAPI-Documentation.md b/Content/Documentation/ScriptingAPI-Documentation.md index b5ffa7065..24b01ee41 100644 --- a/Content/Documentation/ScriptingAPI-Documentation.md +++ b/Content/Documentation/ScriptingAPI-Documentation.md @@ -1228,7 +1228,7 @@ A ray is defined by an origin Vector and a normalized direction Vector. It can b
-- [constructor]Ray(Vector origin,direction) +- [constructor]Ray(Vector origin,direction, opt float Tmin=0,Tmax=FLT_MAX) - Intersects(AABB aabb) : bool result - Intersects(Sphere sphere) : bool result - Intersects(Capsule capsule) : bool result diff --git a/Content/models/dungeon/block.wiscene b/Content/models/dungeon/block.wiscene deleted file mode 100644 index 03844a3f2..000000000 Binary files a/Content/models/dungeon/block.wiscene and /dev/null differ diff --git a/Content/models/dungeon/corridor.wiscene b/Content/models/dungeon/corridor.wiscene deleted file mode 100644 index 9abab3239..000000000 Binary files a/Content/models/dungeon/corridor.wiscene and /dev/null differ diff --git a/Content/models/dungeon/crossjunction.wiscene b/Content/models/dungeon/crossjunction.wiscene deleted file mode 100644 index f11510d65..000000000 Binary files a/Content/models/dungeon/crossjunction.wiscene and /dev/null differ diff --git a/Content/models/dungeon/end.wiscene b/Content/models/dungeon/end.wiscene deleted file mode 100644 index 26bb00b03..000000000 Binary files a/Content/models/dungeon/end.wiscene and /dev/null differ diff --git a/Content/models/dungeon/oddcorridor.wiscene b/Content/models/dungeon/oddcorridor.wiscene deleted file mode 100644 index 31dd229e3..000000000 Binary files a/Content/models/dungeon/oddcorridor.wiscene and /dev/null differ diff --git a/Content/models/dungeon/room.wiscene b/Content/models/dungeon/room.wiscene deleted file mode 100644 index 87e329523..000000000 Binary files a/Content/models/dungeon/room.wiscene and /dev/null differ diff --git a/Content/models/dungeon/smallroomleft.wiscene b/Content/models/dungeon/smallroomleft.wiscene deleted file mode 100644 index c970d3138..000000000 Binary files a/Content/models/dungeon/smallroomleft.wiscene and /dev/null differ diff --git a/Content/models/dungeon/start.wiscene b/Content/models/dungeon/start.wiscene deleted file mode 100644 index 076739616..000000000 Binary files a/Content/models/dungeon/start.wiscene and /dev/null differ diff --git a/Content/models/dungeon/tjunction.wiscene b/Content/models/dungeon/tjunction.wiscene deleted file mode 100644 index b6f2f041d..000000000 Binary files a/Content/models/dungeon/tjunction.wiscene and /dev/null differ diff --git a/Content/models/dungeon/turnleft.wiscene b/Content/models/dungeon/turnleft.wiscene deleted file mode 100644 index 216f8aeca..000000000 Binary files a/Content/models/dungeon/turnleft.wiscene and /dev/null differ diff --git a/Content/models/dungeon/turnright.wiscene b/Content/models/dungeon/turnright.wiscene deleted file mode 100644 index 66959006f..000000000 Binary files a/Content/models/dungeon/turnright.wiscene and /dev/null differ diff --git a/Content/models/dungeon/upcorridor.wiscene b/Content/models/dungeon/upcorridor.wiscene deleted file mode 100644 index 3f7ff78ad..000000000 Binary files a/Content/models/dungeon/upcorridor.wiscene and /dev/null differ diff --git a/Content/models/girl.wiscene b/Content/models/girl.wiscene deleted file mode 100644 index 66261bb6e..000000000 Binary files a/Content/models/girl.wiscene and /dev/null differ diff --git a/Content/models/playground.wiscene b/Content/models/playground.wiscene deleted file mode 100644 index 0f37095bd..000000000 Binary files a/Content/models/playground.wiscene and /dev/null differ diff --git a/Content/scripts/character_controller/assets/character.wiscene b/Content/scripts/character_controller/assets/character.wiscene new file mode 100644 index 000000000..8220bc4db Binary files /dev/null and b/Content/scripts/character_controller/assets/character.wiscene differ diff --git a/Content/scripts/character_controller/assets/grassparticle.png b/Content/scripts/character_controller/assets/grassparticle.png new file mode 100644 index 000000000..aa815a2d2 Binary files /dev/null and b/Content/scripts/character_controller/assets/grassparticle.png differ diff --git a/Content/scripts/character_controller/assets/level.wiscene b/Content/scripts/character_controller/assets/level.wiscene new file mode 100644 index 000000000..f361f376d Binary files /dev/null and b/Content/scripts/character_controller/assets/level.wiscene differ diff --git a/Content/scripts/character_controller/assets/open_door.lua b/Content/scripts/character_controller/assets/open_door.lua new file mode 100644 index 000000000..23ef61da1 --- /dev/null +++ b/Content/scripts/character_controller/assets/open_door.lua @@ -0,0 +1,19 @@ +local distance = 1 +local scene = GetScene() +local zone_transform = scene.Component_GetTransform(GetEntity()) +local zone_animation = scene.Component_GetAnimation(GetEntity()) + +if zone_transform ~= nil and zone_animation ~= nil then + local zone_pos = zone_transform.GetPosition() + + for i,entity in ipairs(scene.Entity_GetHumanoidArray()) do + local transform = scene.Component_GetTransform(entity) + if transform ~= nil then + local humanoid_pos = transform.GetPosition() + if vector.Subtract(humanoid_pos, zone_pos).Length() < distance then + zone_animation.Play() + end + end + end + +end diff --git a/Content/scripts/character_controller/assets/ripple.png b/Content/scripts/character_controller/assets/ripple.png new file mode 100644 index 000000000..14edbcfac Binary files /dev/null and b/Content/scripts/character_controller/assets/ripple.png differ diff --git a/Content/scripts/character_controller/assets/waterNormalMap.jpg b/Content/scripts/character_controller/assets/waterNormalMap.jpg new file mode 100644 index 000000000..43acac176 Binary files /dev/null and b/Content/scripts/character_controller/assets/waterNormalMap.jpg differ diff --git a/Content/scripts/character_controller/assets/zone_angry.lua b/Content/scripts/character_controller/assets/zone_angry.lua new file mode 100644 index 000000000..88ef6bb21 --- /dev/null +++ b/Content/scripts/character_controller/assets/zone_angry.lua @@ -0,0 +1,2 @@ +dofile(script_dir() .. "zone_expression.lua") +zone_expression(GetEntity(), ExpressionPreset.Angry, "angry") \ No newline at end of file diff --git a/Content/scripts/character_controller/assets/zone_angry.wiscene b/Content/scripts/character_controller/assets/zone_angry.wiscene new file mode 100644 index 000000000..e3cb6e87b Binary files /dev/null and b/Content/scripts/character_controller/assets/zone_angry.wiscene differ diff --git a/Content/scripts/character_controller/assets/zone_expression.lua b/Content/scripts/character_controller/assets/zone_expression.lua new file mode 100644 index 000000000..6a430981c --- /dev/null +++ b/Content/scripts/character_controller/assets/zone_expression.lua @@ -0,0 +1,31 @@ +function zone_expression(zone_entity, expression_preset, expression_string) + local distance = 1 + local scene = GetScene() + local zone_transform = scene.Component_GetTransform(zone_entity) + if zone_transform ~= nil then + local zone_pos = zone_transform.GetPosition() + local zone_active = false + + for i,entity in ipairs(scene.Entity_GetExpressionArray()) do + local transform = scene.Component_GetTransform(entity) + local expression = scene.Component_GetExpression(entity) + if expression ~= nil and transform ~= nil then + local expression_pos = transform.GetPosition() + if vector.Subtract(expression_pos, zone_pos).Length() < distance then + expression.SetPresetWeight(expression_preset, 1) + zone_active = true + else + expression.SetPresetWeight(expression_preset, 0) + end + end + end + + local str = "If character gets close to this, it will be " .. expression_string .. "\n" + if zone_active then + str = str .. "...and a character is currently" .. expression_string .. "!" + else + str = str .. "...but no one is " .. expression_string .. " currently." + end + DrawDebugText(str, vector.Add(zone_pos, Vector(0,1,0)), Vector(1,1,1,1), 0.1, DEBUG_TEXT_DEPTH_TEST | DEBUG_TEXT_CAMERA_FACING) + end +end diff --git a/Content/scripts/character_controller/assets/zone_happy.lua b/Content/scripts/character_controller/assets/zone_happy.lua new file mode 100644 index 000000000..b6e5cf6c5 --- /dev/null +++ b/Content/scripts/character_controller/assets/zone_happy.lua @@ -0,0 +1,2 @@ +dofile(script_dir() .. "zone_expression.lua") +zone_expression(GetEntity(), ExpressionPreset.Happy, "happy") diff --git a/Content/scripts/character_controller/assets/zone_happy.wiscene b/Content/scripts/character_controller/assets/zone_happy.wiscene new file mode 100644 index 000000000..25c619815 Binary files /dev/null and b/Content/scripts/character_controller/assets/zone_happy.wiscene differ diff --git a/Content/scripts/character_controller/assets/zone_lookat.lua b/Content/scripts/character_controller/assets/zone_lookat.lua new file mode 100644 index 000000000..94e60521a --- /dev/null +++ b/Content/scripts/character_controller/assets/zone_lookat.lua @@ -0,0 +1,31 @@ +local distance = 1 +local scene = GetScene() +local zone_transform = scene.Component_GetTransform(GetEntity()) + +if zone_transform ~= nil then + local zone_pos = zone_transform.GetPosition() + local zone_active = false + + for i,entity in ipairs(scene.Entity_GetHumanoidArray()) do + local transform = scene.Component_GetTransform(entity) + local humanoid = scene.Component_GetHumanoid(entity) + if humanoid ~= nil and transform ~= nil then + local humanoid_pos = transform.GetPosition() + if vector.Subtract(humanoid_pos, zone_pos).Length() < distance then + humanoid.SetLookAtEnabled(true) + humanoid.SetLookAt(zone_pos) + zone_active = true + else + humanoid.SetLookAtEnabled(false) + end + end + end + + local str = "If character gets close to this, it will look at here...\n" + if zone_active then + str = str .. "...and a character is currently looking at this!" + else + str = str .. "...but no one is looking at this currently." + end + DrawDebugText(str, vector.Add(zone_pos, Vector(0,1,0)), Vector(1,1,1,1), 0.1, DEBUG_TEXT_DEPTH_TEST | DEBUG_TEXT_CAMERA_FACING) +end diff --git a/Content/scripts/character_controller/assets/zone_lookat.wiscene b/Content/scripts/character_controller/assets/zone_lookat.wiscene new file mode 100644 index 000000000..c9b5c9180 Binary files /dev/null and b/Content/scripts/character_controller/assets/zone_lookat.wiscene differ diff --git a/Content/scripts/character_controller/assets/zone_sad.lua b/Content/scripts/character_controller/assets/zone_sad.lua new file mode 100644 index 000000000..bc1269bde --- /dev/null +++ b/Content/scripts/character_controller/assets/zone_sad.lua @@ -0,0 +1,2 @@ +dofile(script_dir() .. "zone_expression.lua") +zone_expression(GetEntity(), ExpressionPreset.Sad, "sad") \ No newline at end of file diff --git a/Content/scripts/character_controller/assets/zone_sad.wiscene b/Content/scripts/character_controller/assets/zone_sad.wiscene new file mode 100644 index 000000000..aaccabe12 Binary files /dev/null and b/Content/scripts/character_controller/assets/zone_sad.wiscene differ diff --git a/Content/scripts/character_controller/character_controller.lua b/Content/scripts/character_controller/character_controller.lua new file mode 100644 index 000000000..bcbac92a0 --- /dev/null +++ b/Content/scripts/character_controller/character_controller.lua @@ -0,0 +1,608 @@ +-- Lua Third person camera and character controller script +-- This script will load a simple scene with a character that can be controlled +-- +-- CONTROLS: +-- WASD/left thumbstick: walk +-- SHIFT/right shoulder button: walk -> jog +-- E/left shoulder button: jog -> run +-- SPACE/gamepad X/gamepad button 2: jump +-- Right Mouse Button/Right thumbstick: rotate camera +-- Scoll middle mouse/Left-Right triggers: adjust camera distance +-- H: toggle debug draw +-- ESCAPE key: quit +-- ENTER: reload script + +-- Debug Draw Helper +local DrawAxis = function(point,f) + DrawLine(point,point:Add(Vector(f,0,0)),Vector(1,0,0,1)) + DrawLine(point,point:Add(Vector(0,f,0)),Vector(0,1,0,1)) + DrawLine(point,point:Add(Vector(0,0,f)),Vector(0,0,1,1)) +end + +local debug = true -- press H to toggle + +local scene = GetScene() + +Character = { + model = INVALID_ENTITY, + target = INVALID_ENTITY, -- Camera will look at this location, rays will be started from this location, etc. + current_anim = INVALID_ENTITY, + idle_anim = INVALID_ENTITY, + walk_anim = INVALID_ENTITY, + jog_anim = INVALID_ENTITY, + run_anim = INVALID_ENTITY, + jump_anim = INVALID_ENTITY, + swim_idle_anim = INVALID_ENTITY, + swim_anim = INVALID_ENTITY, + all_anims = {}, + neck = INVALID_ENTITY, + head = INVALID_ENTITY, + left_hand = INVALID_ENTITY, + right_hand = INVALID_ENTITY, + left_foot = INVALID_ENTITY, + right_foot = INVALID_ENTITY, + face = Vector(0,0,1), -- forward direction + force = Vector(), + velocity = Vector(), + savedPointerPos = Vector(), + walk_speed = 0.2, + jog_speed = 0.4, + run_speed = 0.8, + jump_speed = 14, + swim_speed = 0.5, + layerMask = 0x2, -- The character will be tagged to use this layer, so scene intersection can filter out the character + scale = Vector(1, 1, 1), + rotation = Vector(0,math.pi,0), + start_position = Vector(0, 1, 0), + + states = { + IDLE = "idle", + WALK = "walk", + JOG = "jog", + RUN = "run", + JUMP = "jump", + SWIM_IDLE = "swim_idle", + SWIM = "swim", + }, + + Create = function(self, model_name) + local character_scene = Scene() + self.model = LoadModel(character_scene, model_name) + local layer = character_scene.Component_GetLayer(self.model) + layer.SetLayerMask(self.layerMask) + + self.state = self.states.IDLE + self.state_prev = self.state + + for i,entity in ipairs(character_scene.Entity_GetAnimationArray()) do + table.insert(self.all_anims, entity) + end + + self.idle_anim = character_scene.Entity_FindByName("idle") + self.walk_anim = character_scene.Entity_FindByName("walk") + self.jog_anim = character_scene.Entity_FindByName("jog") + self.run_anim = character_scene.Entity_FindByName("run") + self.jump_anim = character_scene.Entity_FindByName("jump") + self.swim_idle_anim = character_scene.Entity_FindByName("swim_idle") + self.swim_anim = character_scene.Entity_FindByName("swim") + + self.collider = character_scene.Entity_GetHumanoidArray()[1] + local humanoid = character_scene.Component_GetHumanoidArray()[1] + humanoid.SetLookAtEnabled(false) + self.neck = humanoid.GetBoneEntity(HumanoidBone.Neck) + self.head = humanoid.GetBoneEntity(HumanoidBone.Head) + self.left_hand = humanoid.GetBoneEntity(HumanoidBone.LeftHand) + self.right_hand = humanoid.GetBoneEntity(HumanoidBone.RightHand) + self.left_foot = humanoid.GetBoneEntity(HumanoidBone.LeftFoot) + self.right_foot = humanoid.GetBoneEntity(HumanoidBone.RightFoot) + + local model_transform = character_scene.Component_GetTransform(self.model) + model_transform.ClearTransform() + model_transform.Scale(self.scale) + model_transform.Rotate(self.rotation) + model_transform.Translate(self.start_position) + model_transform.UpdateTransform() + + self.target = CreateEntity() + local target_transform = character_scene.Component_CreateTransform(self.target) + target_transform.Translate(character_scene.Component_GetTransform(self.head).GetPosition()) + target_transform.Translate(self.start_position) + + character_scene.Component_Attach(self.target, self.model) + + scene.Merge(character_scene) + end, + + Jump = function(self,f) + self.force.SetY(f) + self.state = self.states.JUMP + end, + MoveDirection = function(self,dir,f) + local target_transform = scene.Component_GetTransform(self.target) + dir = vector.Transform(dir:Normalize(), target_transform.GetMatrix()) + dir.SetY(0) + local dot = vector.Dot(self.face, dir) + if(dot < 0) then + self.face = vector.TransformNormal(self.face, matrix.RotationY(math.pi * 0.01)) + end + self.face = vector.Lerp(self.face, dir, 0.2); + self.face.Normalize() + if(dot > 0) then + self.force = vector.Add(self.force, self.face:Multiply(Vector(f,f,f))) + end + end, + + Update = function(self) + + local dt = getDeltaTime() + + + local model_transform = scene.Component_GetTransform(self.model) + local savedPos = model_transform.GetPosition() + model_transform.ClearTransform() + model_transform.MatrixTransform(matrix.LookTo(Vector(),self.face):Inverse()) + model_transform.Scale(self.scale) + model_transform.Rotate(self.rotation) + model_transform.Translate(savedPos) + model_transform.UpdateTransform() + scene.Component_Detach(self.target) + scene.Component_Attach(self.target, self.model) + + + -- Camera target control: + + -- read from gamepad analog stick: + local diff = input.GetAnalog(GAMEPAD_ANALOG_THUMBSTICK_R) + diff = vector.Multiply(diff, dt * 4) + + -- read from mouse: + if(input.Down(MOUSE_BUTTON_RIGHT)) then + local mouseDif = input.GetPointerDelta() + mouseDif = mouseDif:Multiply(dt * 0.3) + diff = vector.Add(diff, mouseDif) + input.SetPointer(self.savedPointerPos) + input.HidePointer(true) + else + self.savedPointerPos = input.GetPointer() + input.HidePointer(false) + end + + local target_transform = scene.Component_GetTransform(self.target) + target_transform.Rotate(Vector(diff.GetY(),diff.GetX())) + + + + -- state and animation update + if(self.state == self.states.IDLE) then + self.current_anim = self.idle_anim + elseif(self.state == self.states.WALK) then + self.current_anim = self.walk_anim + elseif(self.state == self.states.JOG) then + self.current_anim = self.jog_anim + elseif(self.state == self.states.RUN) then + self.current_anim = self.run_anim + elseif(self.state == self.states.JUMP) then + self.current_anim = self.jump_anim + elseif(self.state == self.states.SWIM_IDLE) then + self.current_anim = self.swim_idle_anim + elseif(self.state == self.states.SWIM) then + self.current_anim = self.swim_anim + end + + local current_anim = scene.Component_GetAnimation(self.current_anim) + if current_anim ~= nil then + + -- Blend in current animation: + current_anim.SetAmount(math.lerp(current_anim.GetAmount(), 1, 0.1)) + current_anim.Play() + if self.state_prev ~= self.state then + -- If anim just started in this frame, reset timer to beginning: + current_anim.SetTimer(current_anim.GetStart()) + self.state_prev = self.state + end + + -- Ease out other animations: + for i,anim in ipairs(self.all_anims) do + if (anim ~= INVALID_ENTITY) and (anim ~= self.current_anim) then + local prev_anim = scene.Component_GetAnimation(anim) + prev_anim.SetAmount(math.lerp(prev_anim.GetAmount(), 0, 0.1)) + if prev_anim.GetAmount() <= 0 then + prev_anim.Stop() + end + end + end + + -- Simple state transition to idle: + if self.state == self.states.JUMP then + if current_anim.GetTimer() > current_anim.GetEnd() then + self.state = self.states.IDLE + end + else + if self.velocity.Length() < 0.1 and self.state ~= self.states.SWIM_IDLE and self.state ~= self.states.SWIM then + self.state = self.states.IDLE + end + end + end + + if dt > 0.1 then + return -- avoid processing too large delta times to avoid instability + end + + -- swim test: + if self.neck ~= INVALID_ENTITY then + local neck_pos = scene.Component_GetTransform(self.neck).GetPosition() + local water_threshold = 0.05 + neck_pos = vector.Add(neck_pos, Vector(0, -water_threshold, 0)) + local swim_ray = Ray(neck_pos, Vector(0,1,0), 0, 100) + local water_entity, water_pos, water_normal, water_distance = scene.Intersects(swim_ray, FILTER_WATER) + if water_entity ~= INVALID_ENTITY then + model_transform.Translate(Vector(0,water_distance - water_threshold,0)) + model_transform.UpdateTransform() + self.force.SetY(0) + self.force = vector.Multiply(self.force, 0.8) -- water friction + self.velocity.SetY(0) + self.state = self.states.SWIM_IDLE + end + end + + -- Movement input: + local lookDir = Vector() + if(input.Down(KEYBOARD_BUTTON_LEFT) or input.Down(string.byte('A'))) then + lookDir = lookDir:Add( Vector(-1) ) + end + if(input.Down(KEYBOARD_BUTTON_RIGHT) or input.Down(string.byte('D'))) then + lookDir = lookDir:Add( Vector(1) ) + end + + if(input.Down(KEYBOARD_BUTTON_UP) or input.Down(string.byte('W'))) then + lookDir = lookDir:Add( Vector(0,0,1) ) + end + if(input.Down(KEYBOARD_BUTTON_DOWN) or input.Down(string.byte('S'))) then + lookDir = lookDir:Add( Vector(0,0,-1) ) + end + + local analog = input.GetAnalog(GAMEPAD_ANALOG_THUMBSTICK_L) + lookDir = vector.Add(lookDir, Vector(analog.GetX(), 0, analog.GetY())) + + if self.state ~= self.states.JUMP and self.state_prev ~= self.states.JUMP and self.velocity.GetY() == 0 then + if(lookDir.Length() > 0) then + if self.state == self.states.SWIM_IDLE then + self:MoveDirection(lookDir,self.swim_speed) + self.state = self.states.SWIM + else + if(input.Down(KEYBOARD_BUTTON_LSHIFT) or input.Down(GAMEPAD_BUTTON_6)) then + if input.Down(string.byte('E')) or input.Down(GAMEPAD_BUTTON_5) then + self:MoveDirection(lookDir,self.run_speed) + self.state = self.states.RUN + else + self:MoveDirection(lookDir,self.jog_speed) + self.state = self.states.JOG + end + else + self:MoveDirection(lookDir,self.walk_speed) + self.state = self.states.WALK + end + end + end + + if(input.Press(string.byte('J')) or input.Press(KEYBOARD_BUTTON_SPACE) or input.Press(GAMEPAD_BUTTON_2)) then + self:Jump(self.jump_speed) + end + elseif self.velocity.GetY() > 0 then + self:MoveDirection(lookDir,self.walk_speed) + end + + self.face.SetY(0) + self.face=self.face:Normalize() + + self.force = vector.Add(self.force, Vector(0, -1, 0)) -- gravity + self.velocity = vector.Multiply(self.force, dt) + + + -- Capsule collision for character: + local capsule = scene.Component_GetCollider(self.collider).GetCapsule() + local original_capsulepos = model_transform.GetPosition() + local capsulepos = original_capsulepos + local capsuleheight = vector.Subtract(capsule.GetTip(), capsule.GetBase()).Length() + local radius = capsule.GetRadius() + local ground_intersect = false + + local fixed_update_remain = dt + local fixed_update_fps = 120 + local fixed_update_rate = 1.0 / fixed_update_fps + local fixed_dt = fixed_update_rate / dt + + while fixed_update_remain > 0 do + fixed_update_remain = fixed_update_remain - fixed_update_rate + + local step = vector.Multiply(self.velocity, fixed_dt) + + capsulepos = vector.Add(capsulepos, step) + capsule = Capsule(capsulepos, vector.Add(capsulepos, Vector(0, capsuleheight)), radius) + local o2, p2, n2, depth, velocity = scene.Intersects(capsule, FILTER_NAVIGATION_MESH | FILTER_COLLIDER, ~self.layerMask) -- scene/capsule collision + if(o2 ~= INVALID_ENTITY) then + + if debug then + DrawPoint(p2,0.1,Vector(1,1,0,1)) + DrawLine(p2, vector.Add(p2, n2), Vector(1,1,0,1)) + end + + local ground_slope = vector.Dot(n2, Vector(0,1,0)) + local slope_threshold = 0.1 + + if self.velocity.GetY() < 0 and ground_slope > slope_threshold then + -- Ground intersection, remove falling motion: + self.velocity.SetY(0) + capsulepos = vector.Add(capsulepos, Vector(0, depth, 0)) + capsulepos = vector.Add(capsulepos, velocity) -- apply moving platform velocity + self.force = vector.Multiply(self.force, 0.85) -- ground friction + ground_intersect = true + elseif ground_slope <= slope_threshold then + -- Slide on contact surface: + local velocityLen = self.velocity.Length() + local velocityNormalized = self.velocity.Normalize() + local undesiredMotion = n2:Multiply(vector.Dot(velocityNormalized, n2)) + local desiredMotion = vector.Subtract(velocityNormalized, undesiredMotion) + if ground_intersect then + desiredMotion.SetY(0) + end + self.velocity = vector.Multiply(desiredMotion, velocityLen) + capsulepos = vector.Add(capsulepos, vector.Multiply(n2, depth)) + end + + end + + end + + model_transform.Translate(vector.Subtract(capsulepos, original_capsulepos)) -- transform by the capsule offset + model_transform.UpdateTransform() + + -- try to put water ripple: + if self.velocity.Length() > 0.01 and self.state ~= self.states.SWIM_IDLE then + local w,wp = scene.Intersects(capsule, FILTER_WATER) + if w ~= INVALID_ENTITY then + PutWaterRipple(script_dir() .. "assets/ripple.png", wp) + end + end + + end, + +} + +-- Third person camera controller class: +ThirdPersonCamera = { + camera = INVALID_ENTITY, + character = nil, + side_offset = 0.2, + rest_distance = 1, + rest_distance_new = 1, + min_distance = 0.5, + zoom_speed = 0.3, + + Create = function(self, character) + self.character = character + + self.camera = CreateEntity() + local camera_transform = scene.Component_CreateTransform(self.camera) + end, + + Update = function(self) + if self.character == nil then + return + end + + -- Mouse scroll or gamepad triggers will move the camera distance: + local scroll = input.GetPointer().GetZ() -- pointer.z is the mouse wheel delta this frame + scroll = scroll + input.GetAnalog(GAMEPAD_ANALOG_TRIGGER_R).GetX() + scroll = scroll - input.GetAnalog(GAMEPAD_ANALOG_TRIGGER_L).GetX() + scroll = scroll * self.zoom_speed + self.rest_distance_new = math.max(self.rest_distance_new - scroll, self.min_distance) -- do not allow too close using max + self.rest_distance = math.lerp(self.rest_distance, self.rest_distance_new, 0.1) -- lerp will smooth out the zooming + + -- We update the scene so that character's target_transform will be using up to date values + scene.UpdateHierarchy() + + local camera_transform = scene.Component_GetTransform(self.camera) + local target_transform = scene.Component_GetTransform(self.character.target) + + + -- First calculate the rest orientation (transform) of the camera: + local mat = matrix.Translation(Vector(self.side_offset, 0, -self.rest_distance)) + mat = matrix.Multiply(mat, target_transform.GetMatrix()) + camera_transform.ClearTransform() + camera_transform.MatrixTransform(mat) + camera_transform.UpdateTransform() + + + -- Camera collision: + + -- Compute the relation vectors between camera and target: + local camPos = camera_transform.GetPosition() + local targetPos = target_transform.GetPosition() + local camDistance = vector.Subtract(camPos, targetPos).Length() + + -- These will store the closest collision distance and required camera position: + local bestDistance = camDistance + local bestPos = camPos + local camera = GetCamera() + + -- Update global camera matrices for rest position: + camera.TransformCamera(camera_transform) + camera.UpdateCamera() + + -- Cast rays from target to clip space points on the camera near plane to avoid clipping through objects: + local unproj = camera.GetInvViewProjection() -- camera matrix used to unproject from clip space to world space + local clip_coords = { + Vector(0,0,1,1), -- center + Vector(-1,-1,1,1), -- bottom left + Vector(-1,1,1,1), -- top left + Vector(1,-1,1,1), -- bottom right + Vector(1,1,1,1), -- top right + } + for i,coord in ipairs(clip_coords) do + local corner = vector.TransformCoord(coord, unproj) + local target_to_corner = vector.Subtract(corner, targetPos) + local corner_to_campos = vector.Subtract(camPos, corner) + local TMin = 0 + local TMax = target_to_corner.Length() -- optimization: limit the ray tracing distance + + local ray = Ray(targetPos, target_to_corner.Normalize(), TMin, TMax) + + local collObj,collPos,collNor = scene.Intersects(ray, FILTER_NAVIGATION_MESH | FILTER_COLLIDER, ~self.character.layerMask) + if(collObj ~= INVALID_ENTITY) then + -- It hit something, see if it is between the player and camera: + local collDiff = vector.Subtract(collPos, targetPos) + local collDist = collDiff.Length() + if(collDist > 0 and collDist < bestDistance) then + bestDistance = collDist + bestPos = vector.Add(collPos, corner_to_campos) + --DrawPoint(collPos, 0.1, Vector(1,0,0,1)) + end + end + end + + -- We have the best candidate for new camera position now, so offset the camera with the delta between the old and new camera position: + local collision_offset = vector.Subtract(bestPos, camPos) + mat = matrix.Multiply(mat, matrix.Translation(collision_offset)) + camera_transform.ClearTransform() + camera_transform.MatrixTransform(mat) + camera_transform.UpdateTransform() + --DrawPoint(bestPos, 0.1, Vector(1,1,0,1)) + + -- Feed back camera after collision: + camera.TransformCamera(camera_transform) + camera.UpdateCamera() + + end, +} + + +ClearWorld() +LoadModel(script_dir() .. "assets/level.wiscene") +--LoadModel(script_dir() .. "assets/terrain.wiscene") +--dofile(script_dir() .. "../dungeon_generator/dungeon_generator.lua") + +local player = Character +player:Create(script_dir() .. "assets/character.wiscene") +local camera = ThirdPersonCamera +camera:Create(player) + +-- Main loop: +runProcess(function() + + -- We will override the render path so we can invoke the script from Editor and controls won't collide with editor scripts + -- Also save the active component that we can restore when ESCAPE is pressed + local prevPath = application.GetActivePath() + local path = RenderPath3D() + --path.SetLightShaftsEnabled(true) + path.SetLightShaftsStrength(0.01) + path.SetAO(AO_MSAO) + path.SetAOPower(0.25) + path.SetOutlineEnabled(true) + path.SetOutlineThreshold(0.11) + path.SetOutlineThickness(1.7) + path.SetOutlineColor(0,0,0,0.6) + path.SetBloomThreshold(5) + application.SetActivePath(path) + + --application.SetInfoDisplay(false) + application.SetFPSDisplay(true) + --path.SetResolutionScale(0.5) + + while true do + + player:Update() + camera:Update() + update() + + if(input.Press(KEYBOARD_BUTTON_ESCAPE)) then + -- restore previous component + -- so if you loaded this script from the editor, you can go back to the editor with ESC + backlog_post("EXIT") + killProcesses() + application.SetActivePath(prevPath) + return + end + if(input.Press(string.byte('R'))) then + -- reload script + backlog_post("RELOAD") + killProcesses() + application.SetActivePath(prevPath) + dofile(script_file()) + return + end + + end + +end) + +-- Draw +runProcess(function() + + local help_text = "Wicked Engine Character demo (LUA)\n\n" + help_text = help_text .. "Controls:\n" + help_text = help_text .. "#############\n" + help_text = help_text .. "WASD/arrows/left analog stick: walk\n" + help_text = help_text .. "SHIFT/right shoulder button: walk -> jog\n" + help_text = help_text .. "E/left shoulder button: jog -> run\n" + help_text = help_text .. "SPACE/gamepad X/gamepad button 2: Jump\n" + help_text = help_text .. "Right Mouse Button/Right thumbstick: rotate camera\n" + help_text = help_text .. "Scoll middle mouse/Left-Right triggers: adjust camera distance\n" + help_text = help_text .. "ESCAPE key: quit\n" + help_text = help_text .. "R: reload script\n" + help_text = help_text .. "H: toggle debug draw\n" + + while true do + + -- Do some debug draw geometry: + + DrawDebugText(help_text, Vector(0,2,2), Vector(1,1,1,1), 0.1, DEBUG_TEXT_DEPTH_TEST) + + if input.Press(string.byte('H')) then + debug = not debug + end + + if debug and backlog_isactive() == false then + + local model_transform = scene.Component_GetTransform(player.model) + local target_transform = scene.Component_GetTransform(player.target) + + --velocity + DrawLine(target_transform.GetPosition(),target_transform.GetPosition():Add(player.velocity)) + --face + DrawLine(target_transform.GetPosition(),target_transform.GetPosition():Add(player.face:Normalize()),Vector(0,1,0,1)) + --intersection + --DrawAxis(player.p,0.5) + + -- camera target box and axis + --DrawBox(target_transform.GetMatrix()) + + -- Neck bone + DrawPoint(scene.Component_GetTransform(player.neck).GetPosition(),0.05, Vector(0,1,1,1)) + -- Head bone + DrawPoint(scene.Component_GetTransform(player.head).GetPosition(),0.05, Vector(0,1,1,1)) + -- Left hand bone + DrawPoint(scene.Component_GetTransform(player.left_hand).GetPosition(),0.05, Vector(0,1,1,1)) + -- Right hand bone + DrawPoint(scene.Component_GetTransform(player.right_hand).GetPosition(),0.05, Vector(0,1,1,1)) + -- Left foot bone + DrawPoint(scene.Component_GetTransform(player.left_foot).GetPosition(),0.05, Vector(0,1,1,1)) + -- Right foot bone + DrawPoint(scene.Component_GetTransform(player.right_foot).GetPosition(),0.05, Vector(0,1,1,1)) + + + local capsule = scene.Component_GetCollider(player.collider).GetCapsule() + DrawCapsule(capsule) + + local str = "State: " .. player.state .. "\n" + --str = str .. "Velocity = " .. player.velocity.GetX() .. ", " .. player.velocity.GetY() .. "," .. player.velocity.GetZ() .. "\n" + --str = str .. "Force = " .. player.force.GetX() .. ", " .. player.force.GetY() .. "," .. player.force.GetZ() .. "\n" + DrawDebugText(str, vector.Add(capsule.GetBase(), Vector(0,0.4)), Vector(1,1,1,1), 1, DEBUG_TEXT_CAMERA_FACING | DEBUG_TEXT_CAMERA_SCALING) + + end + + -- Wait for the engine to render the scene + render() + end +end) + diff --git a/Content/scripts/character_controller_tps.lua b/Content/scripts/character_controller_tps.lua deleted file mode 100644 index cc7a4d5ab..000000000 --- a/Content/scripts/character_controller_tps.lua +++ /dev/null @@ -1,501 +0,0 @@ --- Lua Third person camera and character controller script --- This script will load a simple scene with a character that can be controlled --- --- CONTROLS: --- WASD/left thumbstick: walk --- SHIFT/right shoulder button: speed --- SPACE/gamepad X/gamepad button 2: Jump --- Right Mouse Button/Right thumbstick: rotate camera --- Scoll middle mouse/Left-Right triggers: adjust camera distance --- ESCAPE key: quit --- ENTER: reload script - --- Debug Draw Helper -local DrawAxis = function(point,f) - DrawLine(point,point:Add(Vector(f,0,0)),Vector(1,0,0,1)) - DrawLine(point,point:Add(Vector(0,f,0)),Vector(0,1,0,1)) - DrawLine(point,point:Add(Vector(0,0,f)),Vector(0,0,1,1)) -end - -local scene = GetScene() - -Character = { - model = INVALID_ENTITY, - target = INVALID_ENTITY, -- Camera will look at this location, rays will be started from this location, etc. - idle_anim = INVALID_ENTITY, - walk_anim = INVALID_ENTITY, - head = INVALID_ENTITY, - left_hand = INVALID_ENTITY, - right_hand = INVALID_ENTITY, - left_foot = INVALID_ENTITY, - right_foot = INVALID_ENTITY, - face = Vector(0,0,1), -- forward direction - force = Vector(), - velocity = Vector(), - gravity = Vector(), - savedPointerPos = Vector(), - moveSpeed = 90, - layerMask = 0x2, -- The character will be tagged to use this layer, so scene Picking can filter out the character - scale = Vector(0.8,0.8,0.8), - rotation = Vector(0,3.1415,0), - - states = { - STAND = 0, - WALK = 1, - JUMP = 2, - }, - state = STAND, - state_prev = STAND, - - Create = function(self,entity) - self.model = entity - local layer = scene.Component_GetLayer(self.model) - layer.SetLayerMask(self.layerMask) - - self.idle_anim = scene.Entity_FindByName("idle") - self.walk_anim = scene.Entity_FindByName("walk") - self.head = scene.Entity_FindByName("testa") - self.left_hand = scene.Entity_FindByName("mano_L") - self.right_hand = scene.Entity_FindByName("mano_R") - self.left_foot = scene.Entity_FindByName("piede_L") - self.right_foot = scene.Entity_FindByName("piede_R") - - self.collider = scene.Entity_FindByName("girl") - - local model_transform = scene.Component_GetTransform(self.model) - model_transform.ClearTransform() - model_transform.Scale(self.scale) - model_transform.Rotate(self.rotation) - model_transform.UpdateTransform() - - self.target = CreateEntity() - local target_transform = scene.Component_CreateTransform(self.target) - target_transform.ClearTransform() - target_transform.Translate(Vector(0,3)) - - scene.Component_Attach(self.target, self.model) - end, - - Jump = function(self,f) - self.force = vector.Add(self.force, Vector(0,f,0)) - self.state = self.states.JUMP - end, - MoveDirection = function(self,dir,f) - local model_transform = scene.Component_GetTransform(self.model) - local target_transform = scene.Component_GetTransform(self.target) - local savedPos = model_transform.GetPosition() - model_transform.ClearTransform() - dir = vector.Transform(dir:Normalize(), target_transform.GetMatrix()) - dir.SetY(0) - local dot = vector.Dot(self.face, dir) - if(dot < 0) then - self.face = vector.TransformNormal(self.face, matrix.RotationY(3.1415 * 0.01)) - end - self.face = vector.Lerp(self.face, dir, 0.2); - self.face.Normalize() - model_transform.MatrixTransform(matrix.LookTo(Vector(),self.face):Inverse()) - model_transform.Scale(self.scale) - model_transform.Rotate(self.rotation) - model_transform.Translate(savedPos) - model_transform.UpdateTransform() - scene.Component_Detach(self.target) - scene.Component_Attach(self.target, self.model) - if(dot > 0) then - self.force = vector.Add(self.force, self.face:Multiply(Vector(f,f,f))) - end - self.state = self.states.WALK - end, - - Input = function(self) - - local lookDir = Vector() - if(input.Down(KEYBOARD_BUTTON_LEFT) or input.Down(string.byte('A'))) then - lookDir = lookDir:Add( Vector(-1) ) - end - if(input.Down(KEYBOARD_BUTTON_RIGHT) or input.Down(string.byte('D'))) then - lookDir = lookDir:Add( Vector(1) ) - end - - if(input.Down(KEYBOARD_BUTTON_UP) or input.Down(string.byte('W'))) then - lookDir = lookDir:Add( Vector(0,0,1) ) - end - if(input.Down(KEYBOARD_BUTTON_DOWN) or input.Down(string.byte('S'))) then - lookDir = lookDir:Add( Vector(0,0,-1) ) - end - - local analog = input.GetAnalog(GAMEPAD_ANALOG_THUMBSTICK_L) - lookDir = vector.Add(lookDir, Vector(analog.GetX(), 0, analog.GetY())) - - if(lookDir:Length()>0) then - if(input.Down(KEYBOARD_BUTTON_LSHIFT) or input.Down(GAMEPAD_BUTTON_6)) then - self:MoveDirection(lookDir,self.moveSpeed*2) - else - self:MoveDirection(lookDir,self.moveSpeed) - end - end - - if( input.Press(string.byte('J')) or input.Press(KEYBOARD_BUTTON_SPACE) or input.Press(GAMEPAD_BUTTON_2) ) then - self:Jump(2000) - end - - -- state and animation update - if(self.state == self.states.STAND) then - scene.Component_GetAnimation(self.walk_anim).Stop() - local anim = scene.Component_GetAnimation(self.idle_anim) - anim.Play() - anim.SetAmount(math.lerp(anim.GetAmount(), 1, 0.1)) - if(self.state ~= self.state_prev) then - anim.SetAmount(0) - end - elseif(self.state == self.states.WALK) then - scene.Component_GetAnimation(self.idle_anim).Stop() - local anim = scene.Component_GetAnimation(self.walk_anim) - anim.Play() - anim.SetAmount(math.lerp(anim.GetAmount(), 1, 0.1)) - if(self.state ~= self.state_prev) then - anim.SetAmount(0) - end - elseif(self.state == self.states.JUMP) then - scene.Component_GetAnimation(self.walk_anim).Stop() - local anim = scene.Component_GetAnimation(self.idle_anim) - anim.Play() - anim.SetAmount(math.lerp(anim.GetAmount(), 1, 0.1)) - if(self.state ~= self.state_prev) then - anim.SetAmount(0) - end - end - self.state_prev = self.state - - -- Camera target control: - - -- read from gamepad analog stick: - local diff = input.GetAnalog(GAMEPAD_ANALOG_THUMBSTICK_R) - diff = vector.Multiply(diff, getDeltaTime() * 4) - - -- read from mouse: - if(input.Down(MOUSE_BUTTON_RIGHT)) then - local mouseDif = input.GetPointerDelta() - mouseDif = mouseDif:Multiply(getDeltaTime() * 0.3) - diff = vector.Add(diff, mouseDif) - input.SetPointer(self.savedPointerPos) - input.HidePointer(true) - else - self.savedPointerPos = input.GetPointer() - input.HidePointer(false) - end - - local target_transform = scene.Component_GetTransform(self.target) - target_transform.Rotate(Vector(diff.GetY(),diff.GetX())) - self.face.SetY(0) - self.face=self.face:Normalize() - - end, - - Update = function(self) - local model_transform = scene.Component_GetTransform(self.model) - local target_transform = scene.Component_GetTransform(self.target) - - -- apply force: - self.velocity = vector.Add(self.velocity, vector.Multiply(self.force, 0.016)) - self.force = Vector(0,0,0,0) - - local capsule = scene.Component_GetCollider(self.collider).GetCapsule() - - -- Capsule collision for character: - local original_capsulepos = model_transform.GetPosition() - local capsulepos = original_capsulepos - local capsuleheight = vector.Subtract(capsule.GetTip(), capsule.GetBase()).Length() - local radius = capsule.GetRadius() - local ccd_max = 3 - local ccd = 0 - while(ccd < ccd_max) do - ccd = ccd + 1 - local step = vector.Multiply(self.velocity, 1.0 / ccd_max * 0.016) - - capsulepos = vector.Add(capsulepos, step) - capsule = Capsule(capsulepos, vector.Add(capsulepos, Vector(0, capsuleheight)), radius) - local o2, p2, n2, depth = scene.Intersects(capsule, FILTER_NAVIGATION_MESH | FILTER_COLLIDER, ~self.layerMask) -- scene/capsule collision - if(o2 ~= INVALID_ENTITY) then - DrawPoint(p2,0.1,Vector(1,1,0,1)) - DrawLine(p2, vector.Add(p2, n2), Vector(1,1,0,1)) - - -- Slide on contact surface: - local velocityLen = self.velocity.Length() - local velocityNormalized = self.velocity.Normalize() - local undesiredMotion = n2:Multiply(vector.Dot(velocityNormalized, n2)) - local desiredMotion = vector.Subtract(velocityNormalized, undesiredMotion) - self.velocity = vector.Multiply(desiredMotion, velocityLen) - - -- Remove penetration (penetration epsilon added to handle infinitely small penetration): - capsulepos = vector.Add(capsulepos, vector.Multiply(n2, depth + 0.0001)) - - end - end - - -- Gravity collision is separate: - -- This is to avoid sliding down slopes and easier traversing of slopes/stairs - -- Unlike normal character motion collision, surface sliding is not computed - self.gravity = vector.Add(self.gravity, Vector(0,-9.8*0.1,0)) - ccd = 0 - ccd_max = 3 - while(ccd < ccd_max) do - ccd = ccd + 1 - local step = vector.Multiply(self.gravity, 1.0 / ccd_max * 0.016) - - capsulepos = vector.Add(capsulepos, step) - capsule = Capsule(capsulepos, vector.Add(capsulepos, Vector(0, capsuleheight)), radius) - local o2, p2, n2, depth = scene.Intersects(capsule, FILTER_NAVIGATION_MESH | FILTER_COLLIDER, ~self.layerMask) -- scene/capsule collision - if(o2 ~= INVALID_ENTITY) then - DrawPoint(p2,0.1,Vector(1,1,0,1)) - DrawLine(p2, vector.Add(p2, n2), Vector(1,1,0,1)) - - -- Remove penetration (penetration epsilon added to handle infinitely small penetration): - capsulepos = vector.Add(capsulepos, vector.Multiply(n2, depth + 0.0001)) - - -- Check whether it is intersecting the ground (ground normal is upwards) - if(vector.Dot(n2, Vector(0,1,0)) > 0.3) then - self.gravity = vector.Multiply(self.gravity, 0) - break - end - - end - end - - self.velocity = vector.Multiply(self.velocity, 0.85) -- ground friction - - if(vector.Length(self.velocity) < 0.001) then - self.state = self.states.STAND - end - model_transform.Translate(vector.Subtract(capsulepos, original_capsulepos)) -- transform by the capsule offset - model_transform.UpdateTransform() - - -- try to put water ripple if character head is directly above water - local head_transform = scene.Component_GetTransform(self.head) - local waterRay = Ray(head_transform.GetPosition(),Vector(0,-1,0)) - local w,wp,wn = scene.Intersects(waterRay,FILTER_WATER) - if(w ~= INVALID_ENTITY and self.velocity.Length() > 2) then - PutWaterRipple(script_dir() .. "../models/ripple.png",wp) - end - - end, - -} - --- Third person camera controller class: -ThirdPersonCamera = { - camera = INVALID_ENTITY, - character = nil, - side_offset = 1, - height = 0, - rest_distance = 6, - rest_distance_new = 6, - - Create = function(self, character) - self.character = character - - self.camera = CreateEntity() - local camera_transform = scene.Component_CreateTransform(self.camera) - end, - - Update = function(self) - if(self.character ~= nil) then - - -- Mouse scroll or gamepad triggers will move the camera distance: - local scroll = input.GetPointer().GetZ() -- pointer.z is the mouse wheel delta this frame - scroll = scroll + input.GetAnalog(GAMEPAD_ANALOG_TRIGGER_R).GetX() - scroll = scroll - input.GetAnalog(GAMEPAD_ANALOG_TRIGGER_L).GetX() - self.rest_distance_new = math.max(self.rest_distance_new - scroll, 2) -- do not allow too close using max - self.rest_distance = math.lerp(self.rest_distance, self.rest_distance_new, 0.1) -- lerp will smooth out the zooming - - -- We update the scene so that character's target_transform will be using up to date values - scene.Update(0) - - local camera_transform = scene.Component_GetTransform(self.camera) - local target_transform = scene.Component_GetTransform(self.character.target) - - - -- First calculate the rest orientation (transform) of the camera: - local mat = matrix.Translation(Vector(self.side_offset, self.height, -self.rest_distance)) - mat = matrix.Multiply(mat, target_transform.GetMatrix()) - camera_transform.ClearTransform() - camera_transform.MatrixTransform(mat) - camera_transform.UpdateTransform() - - - -- Camera collision: - - -- Compute the relation vectors between camera and target: - local camPos = camera_transform.GetPosition() - local targetPos = target_transform.GetPosition() - local camDistance = vector.Subtract(camPos, targetPos).Length() - - -- These will store the closest collision distance and required camera position: - local bestDistance = camDistance - local bestPos = camPos - - -- Update global camera matrices for rest position: - GetCamera().TransformCamera(camera_transform) - GetCamera().UpdateCamera() - - -- Cast rays from target to clip space points on the camera near plane to avoid clipping through objects: - local unproj = GetCamera().GetInvViewProjection() -- camera matrix used to unproject from clip space to world space - local clip_coords = { - Vector(0,0,1,1), -- center - Vector(-1,-1,1,1), -- bottom left - Vector(-1,1,1,1), -- top left - Vector(1,-1,1,1), -- bottom right - Vector(1,1,1,1), -- top right - } - for i,coord in ipairs(clip_coords) do - local corner = vector.TransformCoord(coord, unproj) - local target_to_corner = vector.Subtract(corner, targetPos) - local corner_to_campos = vector.Subtract(camPos, corner) - local TMin = 0 - local TMax = target_to_corner.Length() -- optimization: limit the ray tracing distance - - local ray = Ray(targetPos, target_to_corner.Normalize(), TMin, TMax) - - local collObj,collPos,collNor = scene.Intersects(ray, FILTER_NAVIGATION_MESH | FILTER_COLLIDER, ~self.character.layerMask) - if(collObj ~= INVALID_ENTITY) then - -- It hit something, see if it is between the player and camera: - local collDiff = vector.Subtract(collPos, targetPos) - local collDist = collDiff.Length() - if(collDist > 0 and collDist < bestDistance) then - bestDistance = collDist - bestPos = vector.Add(collPos, corner_to_campos) - --DrawPoint(collPos, 0.1, Vector(1,0,0,1)) - end - end - end - - -- We have the best candidate for new camera position now, so offset the camera with the delta between the old and new camera position: - local collision_offset = vector.Subtract(bestPos, camPos) - mat = matrix.Multiply(mat, matrix.Translation(collision_offset)) - camera_transform.ClearTransform() - camera_transform.MatrixTransform(mat) - camera_transform.UpdateTransform() - --DrawPoint(bestPos, 0.1, Vector(1,1,0,1)) - - -- Feed back camera after collision: - GetCamera().TransformCamera(camera_transform) - GetCamera().UpdateCamera() - - end - end, -} - - --- Player Controller -local player = Character --- Third Person camera -local camera = ThirdPersonCamera - --- Main loop: -runProcess(function() - - ClearWorld() - - -- We will override the render path so we can invoke the script from Editor and controls won't collide with editor scripts - -- Also save the active component that we can restore when ESCAPE is pressed - local prevPath = application.GetActivePath() - local path = RenderPath3D() - path.SetLightShaftsEnabled(true) - path.SetLightShaftsStrength(0.01) - path.SetAO(AO_MSAO) - path.SetAOPower(0.25) - --path.SetResolutionScale(0.5) - application.SetActivePath(path) - - local font = SpriteFont("This script is showcasing how to perform scene collision with raycasts for character and camera.\nControls:\n#####################\n\nWASD/arrows/left analog stick: walk\nSHIFT/right shoulder button: movement speed\nSPACE/gamepad X/gamepad button 2: Jump\nRight Mouse Button/Right thumbstick: rotate camera\nScoll middle mouse/Left-Right triggers: adjust camera distance\nESCAPE key: quit\nR: reload script"); - font.SetSize(14) - font.SetPos(Vector(10, GetScreenHeight() - 10)) - font.SetAlign(WIFALIGN_LEFT, WIFALIGN_BOTTOM) - font.SetColor(0xFFADA3FF) - font.SetShadowColor(Vector(0,0,0,1)) - path.AddFont(font) - - LoadModel(script_dir() .. "../models/playground.wiscene") - - player:Create(LoadModel(script_dir() .. "../models/girl.wiscene")) - camera:Create(player) - - while true do - player:Update() - fixedupdate() - - if(input.Press(KEYBOARD_BUTTON_ESCAPE)) then - -- restore previous component - -- so if you loaded this script from the editor, you can go back to the editor with ESC - backlog_post("EXIT") - killProcesses() - application.SetActivePath(prevPath) - return - end - if(input.Press(string.byte('R'))) then - -- reload script - backlog_post("RELOAD") - killProcesses() - application.SetActivePath(prevPath) - dofile(script_dir() .. "character_controller_tps.lua") - return - end - - end -end) - -runProcess(function() - - while true do - camera:Update() - player:Input() - - update() - end -end) - - --- Draw -runProcess(function() - - while true do - - -- Do some debug draw geometry: - - -- If backlog is opened, skip debug draw: - while(backlog_isactive()) do - waitSeconds(1) - end - - local model_transform = scene.Component_GetTransform(player.model) - local target_transform = scene.Component_GetTransform(player.target) - - --velocity - DrawLine(target_transform.GetPosition(),target_transform.GetPosition():Add(player.velocity)) - --face - DrawLine(target_transform.GetPosition(),target_transform.GetPosition():Add(player.face:Normalize()),Vector(0,1,0,1)) - --intersection - --DrawAxis(player.p,0.5) - - -- camera target box and axis - --DrawBox(target_transform.GetMatrix()) - - -- Head bone - DrawPoint(scene.Component_GetTransform(player.head).GetPosition(),0.2, Vector(0,1,1,1)) - -- Left hand bone - DrawPoint(scene.Component_GetTransform(player.left_hand).GetPosition(),0.2, Vector(0,1,1,1)) - -- Right hand bone - DrawPoint(scene.Component_GetTransform(player.right_hand).GetPosition(),0.2, Vector(0,1,1,1)) - -- Left foot bone - DrawPoint(scene.Component_GetTransform(player.left_foot).GetPosition(),0.2, Vector(0,1,1,1)) - -- Right foot bone - DrawPoint(scene.Component_GetTransform(player.right_foot).GetPosition(),0.2, Vector(0,1,1,1)) - - - local capsule = scene.Component_GetCollider(player.collider).GetCapsule() - DrawCapsule(capsule) - - -- Wait for the engine to render the scene - render() - end -end) - diff --git a/Content/scripts/dungeon_generator/assets/block.wiscene b/Content/scripts/dungeon_generator/assets/block.wiscene new file mode 100644 index 000000000..6311108e1 Binary files /dev/null and b/Content/scripts/dungeon_generator/assets/block.wiscene differ diff --git a/Content/scripts/dungeon_generator/assets/corridor.wiscene b/Content/scripts/dungeon_generator/assets/corridor.wiscene new file mode 100644 index 000000000..3cd334f0d Binary files /dev/null and b/Content/scripts/dungeon_generator/assets/corridor.wiscene differ diff --git a/Content/scripts/dungeon_generator/assets/crossjunction.wiscene b/Content/scripts/dungeon_generator/assets/crossjunction.wiscene new file mode 100644 index 000000000..00112c609 Binary files /dev/null and b/Content/scripts/dungeon_generator/assets/crossjunction.wiscene differ diff --git a/Content/scripts/dungeon_generator/assets/end.wiscene b/Content/scripts/dungeon_generator/assets/end.wiscene new file mode 100644 index 000000000..dc25b7322 Binary files /dev/null and b/Content/scripts/dungeon_generator/assets/end.wiscene differ diff --git a/Content/models/dungeon/obj_source/block.obj b/Content/scripts/dungeon_generator/assets/obj_source/block.obj similarity index 100% rename from Content/models/dungeon/obj_source/block.obj rename to Content/scripts/dungeon_generator/assets/obj_source/block.obj diff --git a/Content/models/dungeon/obj_source/corridor.obj b/Content/scripts/dungeon_generator/assets/obj_source/corridor.obj similarity index 100% rename from Content/models/dungeon/obj_source/corridor.obj rename to Content/scripts/dungeon_generator/assets/obj_source/corridor.obj diff --git a/Content/models/dungeon/obj_source/crossjunction.obj b/Content/scripts/dungeon_generator/assets/obj_source/crossjunction.obj similarity index 100% rename from Content/models/dungeon/obj_source/crossjunction.obj rename to Content/scripts/dungeon_generator/assets/obj_source/crossjunction.obj diff --git a/Content/models/dungeon/obj_source/end.obj b/Content/scripts/dungeon_generator/assets/obj_source/end.obj similarity index 100% rename from Content/models/dungeon/obj_source/end.obj rename to Content/scripts/dungeon_generator/assets/obj_source/end.obj diff --git a/Content/models/dungeon/obj_source/oddcorridor.obj b/Content/scripts/dungeon_generator/assets/obj_source/oddcorridor.obj similarity index 100% rename from Content/models/dungeon/obj_source/oddcorridor.obj rename to Content/scripts/dungeon_generator/assets/obj_source/oddcorridor.obj diff --git a/Content/models/dungeon/obj_source/room.obj b/Content/scripts/dungeon_generator/assets/obj_source/room.obj similarity index 100% rename from Content/models/dungeon/obj_source/room.obj rename to Content/scripts/dungeon_generator/assets/obj_source/room.obj diff --git a/Content/models/dungeon/obj_source/smallroomleft.obj b/Content/scripts/dungeon_generator/assets/obj_source/smallroomleft.obj similarity index 100% rename from Content/models/dungeon/obj_source/smallroomleft.obj rename to Content/scripts/dungeon_generator/assets/obj_source/smallroomleft.obj diff --git a/Content/models/dungeon/obj_source/start.obj b/Content/scripts/dungeon_generator/assets/obj_source/start.obj similarity index 100% rename from Content/models/dungeon/obj_source/start.obj rename to Content/scripts/dungeon_generator/assets/obj_source/start.obj diff --git a/Content/models/dungeon/obj_source/tjunction.obj b/Content/scripts/dungeon_generator/assets/obj_source/tjunction.obj similarity index 100% rename from Content/models/dungeon/obj_source/tjunction.obj rename to Content/scripts/dungeon_generator/assets/obj_source/tjunction.obj diff --git a/Content/models/dungeon/obj_source/turnleft.obj b/Content/scripts/dungeon_generator/assets/obj_source/turnleft.obj similarity index 100% rename from Content/models/dungeon/obj_source/turnleft.obj rename to Content/scripts/dungeon_generator/assets/obj_source/turnleft.obj diff --git a/Content/models/dungeon/obj_source/turnright.obj b/Content/scripts/dungeon_generator/assets/obj_source/turnright.obj similarity index 100% rename from Content/models/dungeon/obj_source/turnright.obj rename to Content/scripts/dungeon_generator/assets/obj_source/turnright.obj diff --git a/Content/models/dungeon/obj_source/upcorridor.obj b/Content/scripts/dungeon_generator/assets/obj_source/upcorridor.obj similarity index 100% rename from Content/models/dungeon/obj_source/upcorridor.obj rename to Content/scripts/dungeon_generator/assets/obj_source/upcorridor.obj diff --git a/Content/scripts/dungeon_generator/assets/oddcorridor.wiscene b/Content/scripts/dungeon_generator/assets/oddcorridor.wiscene new file mode 100644 index 000000000..89bf222b3 Binary files /dev/null and b/Content/scripts/dungeon_generator/assets/oddcorridor.wiscene differ diff --git a/Content/scripts/dungeon_generator/assets/room.wiscene b/Content/scripts/dungeon_generator/assets/room.wiscene new file mode 100644 index 000000000..7075e85f5 Binary files /dev/null and b/Content/scripts/dungeon_generator/assets/room.wiscene differ diff --git a/Content/scripts/dungeon_generator/assets/smallroomleft.wiscene b/Content/scripts/dungeon_generator/assets/smallroomleft.wiscene new file mode 100644 index 000000000..2dba7b0e7 Binary files /dev/null and b/Content/scripts/dungeon_generator/assets/smallroomleft.wiscene differ diff --git a/Content/scripts/dungeon_generator/assets/start.wiscene b/Content/scripts/dungeon_generator/assets/start.wiscene new file mode 100644 index 000000000..d7e256d99 Binary files /dev/null and b/Content/scripts/dungeon_generator/assets/start.wiscene differ diff --git a/Content/scripts/dungeon_generator/assets/tjunction.wiscene b/Content/scripts/dungeon_generator/assets/tjunction.wiscene new file mode 100644 index 000000000..ae6898a79 Binary files /dev/null and b/Content/scripts/dungeon_generator/assets/tjunction.wiscene differ diff --git a/Content/scripts/dungeon_generator/assets/turnleft.wiscene b/Content/scripts/dungeon_generator/assets/turnleft.wiscene new file mode 100644 index 000000000..4fb0e0394 Binary files /dev/null and b/Content/scripts/dungeon_generator/assets/turnleft.wiscene differ diff --git a/Content/scripts/dungeon_generator/assets/turnright.wiscene b/Content/scripts/dungeon_generator/assets/turnright.wiscene new file mode 100644 index 000000000..bde6f7967 Binary files /dev/null and b/Content/scripts/dungeon_generator/assets/turnright.wiscene differ diff --git a/Content/scripts/dungeon_generator/assets/upcorridor.wiscene b/Content/scripts/dungeon_generator/assets/upcorridor.wiscene new file mode 100644 index 000000000..6b27b2f64 Binary files /dev/null and b/Content/scripts/dungeon_generator/assets/upcorridor.wiscene differ diff --git a/Content/scripts/dungeon_generator.lua b/Content/scripts/dungeon_generator/dungeon_generator.lua similarity index 86% rename from Content/scripts/dungeon_generator.lua rename to Content/scripts/dungeon_generator/dungeon_generator.lua index 17c81bc3c..3afc58c1f 100644 --- a/Content/scripts/dungeon_generator.lua +++ b/Content/scripts/dungeon_generator/dungeon_generator.lua @@ -1,13 +1,11 @@ -- Simplistic random dungeon generator lua script -- You can call this from Editor for example, and it will load a complete dungeon from set pieces -local modelpath = script_dir() .. "../models/" - dungeon={ Generate = function(complexity) - local scalingMat = matrix.Scale(Vector(6,6,6)) + local scalingMat = matrix.Scale(Vector(2,2,2)) -- This will hold the bounding boxes of the placed segments local boxes = {} @@ -53,7 +51,7 @@ dungeon={ end if place then - LoadModel(modelpath .. "dungeon/end.wiscene",exitTransforms[i]) + LoadModel(script_dir() .. "assets/end.wiscene",exitTransforms[i]) end end end @@ -76,21 +74,21 @@ dungeon={ local select2 = math.random(0, 6) if(select2 < 1) then --left turn if CheckSegmentCanBePlaced(AABB(Vector(-1,0,0),Vector(1,2,2)).Transform(transformMat)) then - LoadModel(modelpath .. "dungeon/turnleft.wiscene",transformMat) + LoadModel(script_dir() .. "assets/turnleft.wiscene",transformMat) GenerateDungeon(remaining,pos:Add(Vector(-1,0,1):Transform(rotMat)),rotY-0.5*math.pi) else GenerateDungeon(remaining,pos,rotY) end elseif(select2 < 2) then --right turn if CheckSegmentCanBePlaced(AABB(Vector(-1,0,0),Vector(1,2,2)).Transform(transformMat)) then - LoadModel(modelpath .. "dungeon/turnright.wiscene",transformMat) + LoadModel(script_dir() .. "assets/turnright.wiscene",transformMat) GenerateDungeon(remaining,pos:Add(Vector(1,0,1):Transform(rotMat)),rotY+0.5*math.pi) else GenerateDungeon(remaining,pos,rotY) end elseif(select2 < 3) then --t-junction if CheckSegmentCanBePlaced(AABB(Vector(-1,0,0),Vector(1,2,2)).Transform(transformMat)) then - LoadModel(modelpath .. "dungeon/tjunction.wiscene",transformMat) + LoadModel(script_dir() .. "assets/tjunction.wiscene",transformMat) -- right GenerateDungeon(remaining,pos:Add(Vector(1,0,1):Transform(rotMat)),rotY+0.5*math.pi) -- left @@ -100,7 +98,7 @@ dungeon={ end elseif(select2 < 4) then --cross-junction if CheckSegmentCanBePlaced(AABB(Vector(-1,0,0),Vector(1,2,2)).Transform(transformMat)) then - LoadModel(modelpath .. "dungeon/crossjunction.wiscene",transformMat) + LoadModel(script_dir() .. "assets/crossjunction.wiscene",transformMat) -- right GenerateDungeon(remaining,pos:Add(Vector(1,0,1):Transform(rotMat)),rotY+0.5*math.pi) -- left @@ -112,7 +110,7 @@ dungeon={ end else --straight block if CheckSegmentCanBePlaced(AABB(Vector(-1,0,0),Vector(1,2,2)).Transform(transformMat)) then - LoadModel(modelpath .. "dungeon/block.wiscene",transformMat) + LoadModel(script_dir() .. "assets/block.wiscene",transformMat) GenerateDungeon(remaining,pos:Add(Vector(0,0,2):Transform(rotMat)),rotY) else GenerateDungeon(remaining,pos,rotY) @@ -122,28 +120,28 @@ dungeon={ local select2 = math.random(0, 100) if( select2 < 20 ) then --small room left if CheckSegmentCanBePlaced(AABB(Vector(-5,0,0),Vector(1,2,6)).Transform(transformMat)) then - LoadModel(modelpath .. "dungeon/smallroomleft.wiscene",transformMat ) + LoadModel(script_dir() .. "assets/smallroomleft.wiscene",transformMat ) GenerateDungeon(remaining,pos:Add(Vector(-5,0,5):Transform(rotMat)),rotY-0.5*math.pi) else GenerateDungeon(remaining,pos,rotY) end elseif( select2 < 30 ) then --odd corridor if CheckSegmentCanBePlaced(AABB(Vector(-1,0,0),Vector(3,2,8)).Transform(transformMat)) then - LoadModel(modelpath .. "dungeon/oddcorridor.wiscene",transformMat ) + LoadModel(script_dir() .. "assets/oddcorridor.wiscene",transformMat ) GenerateDungeon(remaining,pos:Add(Vector(2,0,8):Transform(rotMat)),rotY) else GenerateDungeon(remaining,pos,rotY) end elseif( select2 < 60 ) then --up corridor if CheckSegmentCanBePlaced(AABB(Vector(-1,0,0),Vector(1,4,6)).Transform(transformMat)) then - LoadModel(modelpath .. "dungeon/upcorridor.wiscene",transformMat ) + LoadModel(script_dir() .. "assets/upcorridor.wiscene",transformMat ) GenerateDungeon(remaining,pos:Add(Vector(0,2,6):Transform(rotMat)),rotY) else GenerateDungeon(remaining,pos,rotY) end else --corridor if CheckSegmentCanBePlaced(AABB(Vector(-1,0,0),Vector(1,2,6)).Transform(transformMat)) then - LoadModel(modelpath .. "dungeon/corridor.wiscene",transformMat ) + LoadModel(script_dir() .. "assets/corridor.wiscene",transformMat ) GenerateDungeon(remaining,pos:Add(Vector(0,0,6):Transform(rotMat)),rotY) else GenerateDungeon(remaining,pos,rotY) @@ -151,7 +149,7 @@ dungeon={ end else -- rare pieces if CheckSegmentCanBePlaced(AABB(Vector(-4,0,0),Vector(4,8,8)).Transform(transformMat)) then - LoadModel(modelpath .. "dungeon/room.wiscene",transformMat ) + LoadModel(script_dir() .. "assets/room.wiscene",transformMat ) -- right GenerateDungeon(remaining,pos:Add(Vector(4,0,4):Transform(rotMat)),rotY + 0.5*math.pi) -- left @@ -166,7 +164,7 @@ dungeon={ -- Place the start piece of the dungeon - LoadModel(modelpath .. "dungeon/start.wiscene",scalingMat) + LoadModel(script_dir() .. "assets/start.wiscene",scalingMat) CheckSegmentCanBePlaced(AABB(Vector(-1,0,-2),Vector(1,2,0))) -- Call recursive generator function GenerateDungeon(complexity,Vector(0,0,0),0) diff --git a/Content/models/Havoc/baseColor.png b/Content/scripts/fighting_game/assets/baseColor.png similarity index 100% rename from Content/models/Havoc/baseColor.png rename to Content/scripts/fighting_game/assets/baseColor.png diff --git a/Content/models/Havoc/havoc.wiscene b/Content/scripts/fighting_game/assets/character.wiscene similarity index 100% rename from Content/models/Havoc/havoc.wiscene rename to Content/scripts/fighting_game/assets/character.wiscene diff --git a/Content/models/dojo.wiscene b/Content/scripts/fighting_game/assets/dojo.wiscene similarity index 100% rename from Content/models/dojo.wiscene rename to Content/scripts/fighting_game/assets/dojo.wiscene diff --git a/Content/models/emitter_dust.wiscene b/Content/scripts/fighting_game/assets/emitter_dust.wiscene similarity index 100% rename from Content/models/emitter_dust.wiscene rename to Content/scripts/fighting_game/assets/emitter_dust.wiscene diff --git a/Content/models/emitter_fireball.wiscene b/Content/scripts/fighting_game/assets/emitter_fireball.wiscene similarity index 100% rename from Content/models/emitter_fireball.wiscene rename to Content/scripts/fighting_game/assets/emitter_fireball.wiscene diff --git a/Content/models/emitter_guardeffect.wiscene b/Content/scripts/fighting_game/assets/emitter_guardeffect.wiscene similarity index 100% rename from Content/models/emitter_guardeffect.wiscene rename to Content/scripts/fighting_game/assets/emitter_guardeffect.wiscene diff --git a/Content/models/emitter_hiteffect.wiscene b/Content/scripts/fighting_game/assets/emitter_hiteffect.wiscene similarity index 100% rename from Content/models/emitter_hiteffect.wiscene rename to Content/scripts/fighting_game/assets/emitter_hiteffect.wiscene diff --git a/Content/models/emitter_spark.wiscene b/Content/scripts/fighting_game/assets/emitter_spark.wiscene similarity index 100% rename from Content/models/emitter_spark.wiscene rename to Content/scripts/fighting_game/assets/emitter_spark.wiscene diff --git a/Content/scripts/fighting_game/assets/fire.jpg b/Content/scripts/fighting_game/assets/fire.jpg new file mode 100644 index 000000000..3a757eb08 Binary files /dev/null and b/Content/scripts/fighting_game/assets/fire.jpg differ diff --git a/Content/models/grid.dds b/Content/scripts/fighting_game/assets/grid.dds similarity index 100% rename from Content/models/grid.dds rename to Content/scripts/fighting_game/assets/grid.dds diff --git a/Content/scripts/hp_bar.png b/Content/scripts/fighting_game/assets/hp_bar.png similarity index 100% rename from Content/scripts/hp_bar.png rename to Content/scripts/fighting_game/assets/hp_bar.png diff --git a/Content/models/Havoc/normalMap.png b/Content/scripts/fighting_game/assets/normalMap.png similarity index 100% rename from Content/models/Havoc/normalMap.png rename to Content/scripts/fighting_game/assets/normalMap.png diff --git a/Content/scripts/fighting_game/assets/orb.dds b/Content/scripts/fighting_game/assets/orb.dds new file mode 100644 index 000000000..e2d13cf59 Binary files /dev/null and b/Content/scripts/fighting_game/assets/orb.dds differ diff --git a/Content/scripts/fighting_game/assets/ripple.png b/Content/scripts/fighting_game/assets/ripple.png new file mode 100644 index 000000000..14edbcfac Binary files /dev/null and b/Content/scripts/fighting_game/assets/ripple.png differ diff --git a/Content/scripts/fighting_game/assets/smoke0.png b/Content/scripts/fighting_game/assets/smoke0.png new file mode 100644 index 000000000..2fbdd99fb Binary files /dev/null and b/Content/scripts/fighting_game/assets/smoke0.png differ diff --git a/Content/scripts/fighting_game.lua b/Content/scripts/fighting_game/fighting_game.lua similarity index 98% rename from Content/scripts/fighting_game.lua rename to Content/scripts/fighting_game/fighting_game.lua index 0e4a94815..cf7341ca6 100644 --- a/Content/scripts/fighting_game.lua +++ b/Content/scripts/fighting_game/fighting_game.lua @@ -1234,7 +1234,7 @@ local function Character(face, skin_color, shirt_color, hair_color, shoe_color) -- We use a custom scene because if two models are loaded into the global scene, they will have name collisions -- and thus we couldn't properly query entities by name local model_scene = Scene() - self.model = LoadModel(model_scene, script_dir() .. "../models/Havoc/havoc.wiscene") + self.model = LoadModel(model_scene, script_dir() .. "assets/character.wiscene") -- Place model according to starting facing direction: self.face = face @@ -1270,31 +1270,31 @@ local function Character(face, skin_color, shirt_color, hair_color, shoe_color) local effect_scene = Scene() effect_scene.Clear() - LoadModel(effect_scene, script_dir() .. "../models/emitter_dust.wiscene") + LoadModel(effect_scene, script_dir() .. "assets/emitter_dust.wiscene") self.effect_dust = effect_scene.Entity_FindByName("dust") -- query the emitter entity by name effect_scene.Component_GetEmitter(self.effect_dust).SetEmitCount(0) -- don't emit continuously scene.Merge(effect_scene) effect_scene.Clear() - LoadModel(effect_scene, script_dir() .. "../models/emitter_hiteffect.wiscene") + LoadModel(effect_scene, script_dir() .. "assets/emitter_hiteffect.wiscene") self.effect_hit = effect_scene.Entity_FindByName("hit") -- query the emitter entity by name effect_scene.Component_GetEmitter(self.effect_hit).SetEmitCount(0) -- don't emit continuously scene.Merge(effect_scene) effect_scene.Clear() - LoadModel(effect_scene, script_dir() .. "../models/emitter_guardeffect.wiscene") + LoadModel(effect_scene, script_dir() .. "assets/emitter_guardeffect.wiscene") self.effect_guard = effect_scene.Entity_FindByName("guard") -- query the emitter entity by name effect_scene.Component_GetEmitter(self.effect_guard).SetEmitCount(0) -- don't emit continuously scene.Merge(effect_scene) effect_scene.Clear() - LoadModel(effect_scene, script_dir() .. "../models/emitter_spark.wiscene") + LoadModel(effect_scene, script_dir() .. "assets/emitter_spark.wiscene") self.effect_spark = effect_scene.Entity_FindByName("spark") -- query the emitter entity by name effect_scene.Component_GetEmitter(self.effect_spark).SetEmitCount(0) -- don't emit continuously scene.Merge(effect_scene) effect_scene.Clear() - self.model_fireball = LoadModel(effect_scene, script_dir() .. "../models/emitter_fireball.wiscene") + self.model_fireball = LoadModel(effect_scene, script_dir() .. "assets/emitter_fireball.wiscene") self.effect_fireball = effect_scene.Entity_FindByName("fireball") -- query the emitter entity by name effect_scene.Component_GetEmitter(self.effect_fireball).SetEmitCount(0) -- don't emit continuously self.effect_fireball_haze = effect_scene.Entity_FindByName("haze") -- query the emitter entity by name @@ -1307,7 +1307,7 @@ local function Character(face, skin_color, shirt_color, hair_color, shoe_color) -- HP bar, etc. sprites: local renderPath = application.GetActivePath() - self.sprite_hpbar_background = Sprite(script_dir() .. "hp_bar.png") + self.sprite_hpbar_background = Sprite(script_dir() .. "assets/hp_bar.png") local fx = self.sprite_hpbar_background.GetParams() fx.SetStencilRefMode(STENCILREFMODE_USER) -- we set the stencil ref in user space fx.SetStencil(STENCILMODE_NOT, stencilref_cutout) @@ -1323,7 +1323,7 @@ local function Character(face, skin_color, shirt_color, hair_color, shoe_color) self.sprite_hpbar_background.SetParams(fx) renderPath.AddSprite(self.sprite_hpbar_background) - self.sprite_hpbar_hp = Sprite(script_dir() .. "hp_bar.png") + self.sprite_hpbar_hp = Sprite(script_dir() .. "assets/hp_bar.png") fx = self.sprite_hpbar_hp.GetParams() fx.SetStencilRefMode(STENCILREFMODE_USER) -- we set the stencil ref in user space fx.SetStencil(STENCILMODE_NOT, stencilref_cutout) @@ -1339,7 +1339,7 @@ local function Character(face, skin_color, shirt_color, hair_color, shoe_color) self.sprite_hpbar_hp.SetParams(fx) renderPath.AddSprite(self.sprite_hpbar_hp) - self.sprite_hpbar_pattern = Sprite(script_dir() .. "hp_bar.png", script_dir() .. "hp_bar.png") + self.sprite_hpbar_pattern = Sprite(script_dir() .. "assets/hp_bar.png", script_dir() .. "assets/hp_bar.png") fx = self.sprite_hpbar_pattern.GetParams() fx.SetStencilRefMode(STENCILREFMODE_USER) -- we set the stencil ref in user space fx.SetStencil(STENCILMODE_NOT, stencilref_cutout) @@ -1361,7 +1361,7 @@ local function Character(face, skin_color, shirt_color, hair_color, shoe_color) self.sprite_hpbar_pattern.SetAnim(pattern_anim) renderPath.AddSprite(self.sprite_hpbar_pattern) - self.sprite_hpbar_pattern2 = Sprite(script_dir() .. "hp_bar.png", script_dir() .. "hp_bar.png") + self.sprite_hpbar_pattern2 = Sprite(script_dir() .. "assets/hp_bar.png", script_dir() .. "assets/hp_bar.png") fx = self.sprite_hpbar_pattern2.GetParams() fx.SetStencilRefMode(STENCILREFMODE_USER) -- we set the stencil ref in user space fx.SetStencil(STENCILMODE_NOT, stencilref_cutout) @@ -1383,7 +1383,7 @@ local function Character(face, skin_color, shirt_color, hair_color, shoe_color) self.sprite_hpbar_pattern2.SetAnim(pattern_anim) renderPath.AddSprite(self.sprite_hpbar_pattern2) - self.sprite_hpbar_border = Sprite(script_dir() .. "hp_bar.png") + self.sprite_hpbar_border = Sprite(script_dir() .. "assets/hp_bar.png") fx = self.sprite_hpbar_border.GetParams() fx.SetStencilRefMode(STENCILREFMODE_USER) -- we set the stencil ref in user space fx.SetStencil(STENCILMODE_NOT, stencilref_cutout) @@ -1399,7 +1399,7 @@ local function Character(face, skin_color, shirt_color, hair_color, shoe_color) renderPath.AddSprite(self.sprite_hpbar_border) if(self.face > 0) then - self.sprite_timer = Sprite(script_dir() .. "hp_bar.png") + self.sprite_timer = Sprite(script_dir() .. "assets/hp_bar.png") fx = self.sprite_timer.GetParams() fx.SetStencilRefMode(STENCILREFMODE_USER) -- we set the stencil ref in user space fx.SetStencil(STENCILMODE_NOT, stencilref_cutout) @@ -1960,7 +1960,7 @@ runProcess(function() info.SetShadowColor(Vector(0,0,0,1)) path.AddFont(info) - LoadModel(script_dir() .. "../models/dojo.wiscene") + LoadModel(script_dir() .. "assets/dojo.wiscene") -- Create the two player characters. Parameters are facing direction and material colors to differentiate between them: -- Facing: skin color: shirt color hair color shoe color diff --git a/Content/scripts/script_tracking.lua b/Content/scripts/script_tracking.lua index 84b8668ec..283188e34 100644 --- a/Content/scripts/script_tracking.lua +++ b/Content/scripts/script_tracking.lua @@ -48,7 +48,7 @@ local proc_success, proc_coroutine = runProcess(function() -- With the new scripting system, use script_dir() string variable to load files relative to the script directory. -- Also running a script can now return its PID, which you can use to kill the script you just launched in this script -- Down below is a small demo to open a file on another script and open it relative to that script's path - D.subscript_PID = dofile(script_dir() .. "subscript_demo/load_dojo.lua", true) + D.subscript_PID = dofile(script_dir() .. "subscript_demo/load_model.lua", true) backlog_post("subscript PID: "..D.subscript_PID) end diff --git a/Content/scripts/subscript_demo/load_dojo.lua b/Content/scripts/subscript_demo/load_dojo.lua deleted file mode 100644 index 40440ce54..000000000 --- a/Content/scripts/subscript_demo/load_dojo.lua +++ /dev/null @@ -1,8 +0,0 @@ --- This script shows how content can be accessed relative to the current script directory --- This will work when calling scripts from scripts - -backlog_post("---> START SCRIPT: load_dojo.lua") - -LoadModel(script_dir() .. "../../models/dojo.wiscene") - -backlog_post("---> END SCRIPT: load_dojo.lua") diff --git a/Content/scripts/subscript_demo/load_model.lua b/Content/scripts/subscript_demo/load_model.lua new file mode 100644 index 000000000..9e4b040c2 --- /dev/null +++ b/Content/scripts/subscript_demo/load_model.lua @@ -0,0 +1,8 @@ +-- This script shows how content can be accessed relative to the current script directory +-- This will work when calling scripts from scripts + +backlog_post("---> START SCRIPT: load_model.lua") + +LoadModel(script_dir() .. "../../models/teapot.wiscene") + +backlog_post("---> END SCRIPT: load_model.lua") diff --git a/Tests/Tests.cpp b/Tests/Tests.cpp index 81a96d876..c7d91a3da 100644 --- a/Tests/Tests.cpp +++ b/Tests/Tests.cpp @@ -359,9 +359,13 @@ void TestsRenderer::Load() case INVERSEKINEMATICSTEST: { Scene scene; - LoadModel(scene, "../Content/models/girl.wiscene", XMMatrixScaling(0.7f, 0.7f, 0.7f)); + LoadModel(scene, "../Content/scripts/character_controller/assets/character.wiscene", XMMatrixScaling(2, 2, 2)); + if (scene.humanoids.GetCount() == 0) + break; - ik_entity = scene.Entity_FindByName("mano_L"); // hand bone in girl.wiscene + HumanoidComponent& humanoid = scene.humanoids[0]; + humanoid.SetLookAtEnabled(false); + ik_entity = humanoid.bones[(size_t)HumanoidComponent::HumanoidBone::LeftHand]; if (ik_entity != INVALID_ENTITY) { InverseKinematicsComponent& ik = scene.inverse_kinematics.Create(ik_entity); diff --git a/WickedEngine/wiPrimitive_BindLua.cpp b/WickedEngine/wiPrimitive_BindLua.cpp index 82279da2a..bb9edbd48 100644 --- a/WickedEngine/wiPrimitive_BindLua.cpp +++ b/WickedEngine/wiPrimitive_BindLua.cpp @@ -61,7 +61,7 @@ namespace wi::lua::primitive } else { - wi::lua::SError(L, "Ray(Vector origin,direction) requires two arguments of Vector type!"); + wi::lua::SError(L, "Ray(Vector origin,direction, opt float Tmin = 0, TMax = FLT_MAX) requires two arguments of Vector type!"); } } else diff --git a/WickedEngine/wiTerrain.cpp b/WickedEngine/wiTerrain.cpp index 9289af5b5..bc23831a8 100644 --- a/WickedEngine/wiTerrain.cpp +++ b/WickedEngine/wiTerrain.cpp @@ -813,22 +813,12 @@ namespace wi::terrain { wi::Archive archive = wi::Archive(prop.data.data()); EntitySerializer seri; - wi::scene::Scene::EntitySerializeFlags flags = wi::scene::Scene::EntitySerializeFlags::RECURSIVE; - if (serializer_state.empty()) - { - // This means the terrain was not serialized, but prop assets provided in this session, so we can keep references to them: - flags |= wi::scene::Scene::EntitySerializeFlags::KEEP_INTERNAL_ENTITY_REFERENCES; - } - else - { - // This means that terrain was serialized, so we have to resolve prop source asset dependencies: - seri.remap = serializer_state; - } Entity entity = generator->scene.Entity_Serialize( archive, seri, INVALID_ENTITY, - flags + wi::scene::Scene::EntitySerializeFlags::RECURSIVE | + wi::scene::Scene::EntitySerializeFlags::KEEP_INTERNAL_ENTITY_REFERENCES ); NameComponent* name = generator->scene.names.GetComponent(entity); if (name != nullptr) @@ -1053,6 +1043,32 @@ namespace wi::terrain if (seri.GetVersion() >= 1) { archive >> prop.data; + + if (!prop.data.empty()) + { + // Serialize the prop data in read mode and remap internal entity references: + Scene tmp_scene; + wi::Archive tmp_archive = wi::Archive(prop.data.data()); + Entity entity = tmp_scene.Entity_Serialize( + tmp_archive, + seri, + INVALID_ENTITY, + wi::scene::Scene::EntitySerializeFlags::RECURSIVE + ); + + // Serialize again with the remapped references: + wi::Archive remapped_archive; + remapped_archive.SetReadModeAndResetPos(false); + tmp_scene.Entity_Serialize( + remapped_archive, + seri, + entity, + wi::scene::Scene::EntitySerializeFlags::RECURSIVE + ); + + // Replace original data with remapped references for current session: + remapped_archive.WriteData(prop.data); + } } else { @@ -1163,7 +1179,6 @@ namespace wi::terrain archive >> modifier->frequency; } - serializer_state = seri.remap; } else { diff --git a/WickedEngine/wiTerrain.h b/WickedEngine/wiTerrain.h index b938321d8..abfa5349a 100644 --- a/WickedEngine/wiTerrain.h +++ b/WickedEngine/wiTerrain.h @@ -107,7 +107,6 @@ namespace wi::terrain Chunk center_chunk = {}; wi::noise::Perlin perlin_noise; wi::vector props; - wi::unordered_map serializer_state; // For generating scene on a background thread: std::shared_ptr generator;