diff options
| author | ilotterytea <iltsu@alright.party> | 2025-01-20 19:29:50 +0500 |
|---|---|---|
| committer | ilotterytea <iltsu@alright.party> | 2025-01-20 19:29:50 +0500 |
| commit | 043834fa0adf502f61ba09fe312fa3e90b8a6bcc (patch) | |
| tree | 6b140cc4fdb73c954d564b2baf6ff1086a4ada76 /core/src | |
initial commit
Diffstat (limited to 'core/src')
3 files changed, 151 insertions, 0 deletions
diff --git a/core/src/main/java/kz/ilotterytea/frogartha/FrogarthaGame.gwt.xml b/core/src/main/java/kz/ilotterytea/frogartha/FrogarthaGame.gwt.xml new file mode 100644 index 0000000..8dd5046 --- /dev/null +++ b/core/src/main/java/kz/ilotterytea/frogartha/FrogarthaGame.gwt.xml @@ -0,0 +1,9 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE module PUBLIC "-//Google Inc.//DTD Google Web Toolkit 2.11.0//EN" "https://www.gwtproject.org/doctype/2.11.0/gwt-module.dtd"> +<module> + <!-- Paths to source are relative to this file and separated by slashes ('/'). --> + <source path="" /> + <!-- Reflection includes may be needed for your code or library code. Each value is separated by periods ('.'). --> + <!-- You can include a full package by not including the name of a type at the end. --> + +</module>
\ No newline at end of file diff --git a/core/src/main/java/kz/ilotterytea/frogartha/FrogarthaGame.java b/core/src/main/java/kz/ilotterytea/frogartha/FrogarthaGame.java new file mode 100644 index 0000000..149dcc7 --- /dev/null +++ b/core/src/main/java/kz/ilotterytea/frogartha/FrogarthaGame.java @@ -0,0 +1,21 @@ +package kz.ilotterytea.frogartha; + +import com.badlogic.gdx.Game; +import kz.ilotterytea.frogartha.screens.GameScreen; + +/** + * {@link com.badlogic.gdx.ApplicationListener} implementation shared by all platforms. + */ +public class FrogarthaGame extends Game { + private static FrogarthaGame instance; + + @Override + public void create() { + setScreen(new GameScreen()); + } + + public static FrogarthaGame getInstance() { + if (instance == null) instance = new FrogarthaGame(); + return instance; + } +} diff --git a/core/src/main/java/kz/ilotterytea/frogartha/screens/GameScreen.java b/core/src/main/java/kz/ilotterytea/frogartha/screens/GameScreen.java new file mode 100644 index 0000000..509566e --- /dev/null +++ b/core/src/main/java/kz/ilotterytea/frogartha/screens/GameScreen.java @@ -0,0 +1,121 @@ +package kz.ilotterytea.frogartha.screens; + +import com.badlogic.gdx.Gdx; +import com.badlogic.gdx.Screen; +import com.badlogic.gdx.graphics.*; +import com.badlogic.gdx.graphics.g3d.Material; +import com.badlogic.gdx.graphics.g3d.Model; +import com.badlogic.gdx.graphics.g3d.ModelInstance; +import com.badlogic.gdx.graphics.g3d.attributes.ColorAttribute; +import com.badlogic.gdx.graphics.g3d.decals.CameraGroupStrategy; +import com.badlogic.gdx.graphics.g3d.decals.DecalBatch; +import com.badlogic.gdx.graphics.g3d.utils.ModelBuilder; +import com.badlogic.gdx.math.Vector3; +import net.mgsx.gltf.scene3d.attributes.PBRCubemapAttribute; +import net.mgsx.gltf.scene3d.attributes.PBRTextureAttribute; +import net.mgsx.gltf.scene3d.lights.DirectionalShadowLight; +import net.mgsx.gltf.scene3d.lights.PointLightEx; +import net.mgsx.gltf.scene3d.scene.Scene; +import net.mgsx.gltf.scene3d.scene.SceneManager; +import net.mgsx.gltf.scene3d.scene.SceneSkybox; +import net.mgsx.gltf.scene3d.utils.IBLBuilder; + +public class GameScreen implements Screen { + private PerspectiveCamera camera; + private SceneManager sceneManager; + private DecalBatch decalBatch; + + @Override + public void show() { + create3D(); + } + + @Override + public void render(float delta) { + Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT | GL20.GL_DEPTH_BUFFER_BIT); + sceneManager.update(delta); + sceneManager.render(); + + decalBatch.flush(); + } + + @Override + public void resize(int width, int height) { + sceneManager.updateViewport(width, height); + } + + @Override + public void pause() { + hide(); + } + + @Override + public void resume() { + show(); + } + + @Override + public void hide() { + dispose(); + } + + @Override + public void dispose() { + sceneManager.dispose(); + decalBatch.dispose(); + } + + private void create3D() { + sceneManager = new SceneManager(); + + // Building a dummy scene + ModelBuilder modelBuilder = new ModelBuilder(); + Model plane = modelBuilder.createBox(20f, 0.1f, 20f, new Material(ColorAttribute.createDiffuse(Color.LIME)), + VertexAttributes.Usage.Position | VertexAttributes.Usage.Normal); + Scene planeScene = new Scene(new ModelInstance(plane)); + sceneManager.addScene(planeScene); + + camera = new PerspectiveCamera(60f, Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); + camera.near = 1f; + camera.far = 300f; + camera.position.set(0f, 8f, 15f); + camera.lookAt(planeScene.modelInstance.transform.getTranslation(new Vector3())); + camera.update(); + + sceneManager.setCamera(camera); + + DirectionalShadowLight light = new DirectionalShadowLight(1024, 1024, 60f, 60f, 1f, 300f); + light.set(new Color(0xdcccffff), -1f, -0.8f, -0.2f); + light.intensity = 5f; + sceneManager.environment.add(light); + sceneManager.environment.shadowMap = light; + + PointLightEx signLight = new PointLightEx(); + signLight.set(Color.PINK, new Vector3(2f, 6f, 2f), 80f, 100f); + + PointLightEx windowLight = new PointLightEx(); + windowLight.set(Color.BLUE, new Vector3(-1.1f, 7.3f, 0.5f), 80f, 100f); + + sceneManager.environment.add(windowLight, signLight); + + // setup quick IBL (image based lighting) + IBLBuilder iblBuilder = IBLBuilder.createOutdoor(light); + + Cubemap environmentCubemap = iblBuilder.buildEnvMap(1000); + + Cubemap diffuseCubemap = iblBuilder.buildIrradianceMap(256); + Cubemap specularCubemap = iblBuilder.buildRadianceMap(10); + iblBuilder.dispose(); + + Texture brdfLUT = new Texture(Gdx.files.classpath("net/mgsx/gltf/shaders/brdfLUT.png")); + + sceneManager.setAmbientLight(1f); + sceneManager.environment.set(new PBRTextureAttribute(PBRTextureAttribute.BRDFLUTTexture, brdfLUT)); + sceneManager.environment.set(PBRCubemapAttribute.createSpecularEnv(specularCubemap)); + sceneManager.environment.set(PBRCubemapAttribute.createDiffuseEnv(diffuseCubemap)); + + sceneManager.setSkyBox(new SceneSkybox(environmentCubemap)); + + decalBatch = new DecalBatch(new CameraGroupStrategy(camera)); + } +} |
