use of com.badlogic.gdx.graphics.g3d.Environment in project nhglib by VoidZombie.
the class LightComponentJson method parse.
@Override
public void parse(JsonValue jsonValue) {
GraphicsSystem graphicsSystem = entities.getEntitySystem(GraphicsSystem.class);
LightComponent lightComponent = entities.createComponent(entity, LightComponent.class);
LightType lightType = LightType.fromString(jsonValue.getString("lightType"));
float range = jsonValue.getFloat("range", 1f);
float intensity = jsonValue.getFloat("intensity", 1f);
float innerAngle = jsonValue.getFloat("innerAngle", 0f);
float outerAngle = jsonValue.getFloat("outerAngle", 0f);
if (innerAngle > outerAngle) {
innerAngle = outerAngle;
}
if (range < 1.0f) {
range = 1.0f;
}
JsonValue colorJson = jsonValue.get("color");
Color color = new Color(colorJson.getFloat("r"), colorJson.getFloat("g"), colorJson.getFloat("b"), colorJson.getFloat("a"));
/*JsonValue directionJson = jsonValue.get("direction");
Vector3 direction = VectorPool.getVector3();
if (directionJson != null) {
direction.set(
directionJson.getFloat("x"),
directionJson.getFloat("y"),
directionJson.getFloat("z"));
}*/
NhgLight light = null;
switch(lightType) {
case DIRECTIONAL_LIGHT:
light = NhgLight.directional(intensity, color);
break;
case POINT_LIGHT:
light = NhgLight.point(intensity, range, color);
break;
case SPOT_LIGHT:
light = NhgLight.spot(intensity, range, innerAngle, outerAngle, color);
break;
}
if (light == null)
return;
Environment environment = graphicsSystem.getEnvironment();
NhgLightsAttribute attribute = (NhgLightsAttribute) environment.get(NhgLightsAttribute.Type);
if (attribute == null) {
attribute = new NhgLightsAttribute();
environment.set(attribute);
}
attribute.lights.add(light);
lightComponent.light = light;
lightComponent.type = lightType;
output = lightComponent;
}
use of com.badlogic.gdx.graphics.g3d.Environment in project nhglib by VoidZombie.
the class ShaderUtils method createPrefix.
public static String createPrefix(Renderable renderable, boolean skinned) {
String prefix = "";
final int n = renderable.meshPart.mesh.getVertexAttributes().size();
for (int i = 0; i < n; i++) {
final VertexAttribute attr = renderable.meshPart.mesh.getVertexAttributes().get(i);
if (attr.usage == VertexAttributes.Usage.BoneWeight) {
prefix += "#define boneWeight" + attr.unit + "Flag\n";
}
}
if (skinned) {
prefix += "#define skinningFlag\n";
}
Environment environment = renderable.environment;
// Ambient lighting
ColorAttribute ambientLightAttribute = (ColorAttribute) environment.get(ColorAttribute.AmbientLight);
if (ambientLightAttribute != null) {
prefix += "#define ambientLighting\n";
}
// Directional lighting
DirectionalLightsAttribute directionalLightsAttribute = (DirectionalLightsAttribute) environment.get(DirectionalLightsAttribute.Type);
if (directionalLightsAttribute != null) {
Array<DirectionalLight> directionalLights = directionalLightsAttribute.lights;
if (directionalLights.size > 0) {
prefix += "#define numDirectionalLights " + directionalLights.size + "\n";
}
}
// Point lighting
PointLightsAttribute pointLightsAttribute = (PointLightsAttribute) environment.get(PointLightsAttribute.Type);
if (pointLightsAttribute != null) {
Array<PointLight> pointLights = pointLightsAttribute.lights;
if (pointLights.size > 0) {
prefix += "#define numPointLights " + pointLights.size + "\n";
}
}
// Spot lighting
SpotLightsAttribute spotLightsAttribute = (SpotLightsAttribute) environment.get(SpotLightsAttribute.Type);
if (spotLightsAttribute != null) {
Array<SpotLight> spotLights = spotLightsAttribute.lights;
if (spotLights.size > 0) {
prefix += "#define numSpotLights " + spotLights.size + "\n";
}
}
return prefix;
}
use of com.badlogic.gdx.graphics.g3d.Environment in project nhglib by VoidZombie.
the class Main method engineStarted.
@Override
public void engineStarted() {
super.engineStarted();
Nhg.debugLogs = true;
Gdx.input.setCursorCatched(true);
world = new NhgWorld(nhg.messaging, nhg.entities, nhg.assets, new DefaultWorldStrategy(), new Bounds(2f, 2f, 2f));
fpsLogger = new FPSLogger();
renderer20 = new ImmediateModeRenderer20(false, true, 0);
nhg.input.addListener(this);
nhg.assets.queueAsset(new Asset("scene", "myscene.nhs", Scene.class));
nhg.assets.queueAsset(new Asset("inputMap", "input.nhc", JsonValue.class));
GraphicsSystem graphicsSystem = nhg.entities.getEntitySystem(GraphicsSystem.class);
graphicsSystem.setClearColor(Color.GRAY);
Environment environment = graphicsSystem.getEnvironment();
GammaCorrectionAttribute gammaCorrectionAttribute = new GammaCorrectionAttribute();
gammaCorrectionAttribute.gammaCorrection = true;
environment.set(gammaCorrectionAttribute);
// Subscribe to asset events
nhg.messaging.get(Strings.Events.assetLoaded, Strings.Events.assetLoadingFinished).subscribe(new Consumer<Message>() {
@Override
public void accept(Message message) throws Exception {
if (message.is(Strings.Events.assetLoaded)) {
Asset asset = (Asset) message.data.get(Strings.Defaults.assetKey);
if (asset.is("scene")) {
scene = nhg.assets.get(asset);
world.loadScene(scene);
world.setReferenceEntity("camera");
ModelBuilder mb = new ModelBuilder();
Model planeModel = mb.createBox(2f, 0.01f, 20f, new Material(), VertexAttributes.Usage.Position | VertexAttributes.Usage.Normal | VertexAttributes.Usage.TextureCoordinates);
int plane = scene.sceneGraph.createSceneEntity("plane");
scene.sceneGraph.addSceneEntity(plane);
ModelComponent modelComponent = nhg.entities.createComponent(plane, ModelComponent.class);
modelComponent.initWithModel(planeModel);
NodeComponent nodeComponent = nhg.entities.getComponent(plane, NodeComponent.class);
nodeComponent.setTranslation(0, 0, 0, true);
Integer cameraEntity = scene.sceneGraph.getSceneEntity("camera");
cameraNode = nhg.entities.getComponent(cameraEntity, NodeComponent.class);
} else if (asset.is("inputMap")) {
nhg.input.fromJson((JsonValue) nhg.assets.get(asset));
nhg.input.setActiveContext("game", true);
nhg.input.setActiveContext("global", true);
}
}
}
});
}
Aggregations