com.badlogic.gdx.graphics.g3d.environment.SpotLight Java Examples

The following examples show how to use com.badlogic.gdx.graphics.g3d.environment.SpotLight. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: LightUtils.java    From gdx-gltf with Apache License 2.0 5 votes vote down vote up
public static LightsInfo getLightsInfo(LightsInfo info, Iterable<BaseLight> lights){
	info.reset();
	for(BaseLight light : lights){
		if(light instanceof DirectionalLight){
			info.dirLights++;
		}else if(light instanceof PointLight){
			info.pointLights++;
		}else if(light instanceof SpotLight){
			info.spotLights++;
		}else{
			info.miscLights++;
		}
	}
	return info;
}
 
Example #2
Source File: Scene.java    From gdx-gltf with Apache License 2.0 5 votes vote down vote up
protected BaseLight createLight(BaseLight from) {
	if(from instanceof DirectionalLight){
		return new DirectionalLightEx().set((DirectionalLight)from);
	}
	if(from instanceof PointLight){
		return new PointLightEx().set((PointLight)from);
	}
	if(from instanceof SpotLight){
		return new SpotLightEx().set((SpotLight)from);
	}
	throw new GdxRuntimeException("unknown light type " + from.getClass().getName());
}
 
Example #3
Source File: Scene.java    From gdx-gltf with Apache License 2.0 5 votes vote down vote up
private void syncLights(){
	for(Entry<Node, BaseLight> e : lights){
		Node node = e.key;
		BaseLight light = e.value;
		transform.set(node.globalTransform).mul(modelInstance.transform);
		if(light instanceof DirectionalLight){
			((DirectionalLight)light).direction.set(0,0,-1).rot(transform);
		}else if(light instanceof PointLight){
			((PointLight)light).position.setZero().mul(transform);
		}else if(light instanceof SpotLight){
			((SpotLight)light).position.setZero().mul(transform);
			((SpotLight)light).direction.set(0,0,-1).rot(transform);
		}
	}
}
 
Example #4
Source File: SpotLightEx.java    From gdx-gltf with Apache License 2.0 5 votes vote down vote up
@Override
public SpotLight set (final SpotLight copyFrom) {
	if(copyFrom instanceof SpotLightEx){
		return set(copyFrom.color, copyFrom.position, copyFrom.direction, copyFrom.intensity, copyFrom.cutoffAngle, copyFrom.exponent, ((SpotLightEx)copyFrom).range);
	}else{
		return set(copyFrom.color, copyFrom.position, copyFrom.direction, copyFrom.intensity, copyFrom.cutoffAngle, copyFrom.exponent);
	}
}
 
Example #5
Source File: GLTFLightExporter.java    From gdx-gltf with Apache License 2.0 4 votes vote down vote up
public static GLTFLight map(GLTFLight glLight, BaseLight light) {
	float intensityScale;
	if(light instanceof DirectionalLight){
		glLight.type = GLTFLight.TYPE_DIRECTIONAL;
		if(light instanceof DirectionalLightEx){
			glLight.intensity = ((DirectionalLightEx) light).intensity;
		}else{
			glLight.intensity = 1;
		}
		intensityScale = 1;
	}
	else if(light instanceof PointLight){
		glLight.type = GLTFLight.TYPE_POINT;
		if(light instanceof PointLightEx){
			glLight.intensity = ((PointLightEx) light).intensity;
			glLight.range = ((PointLightEx) light).range;
		}else{
			glLight.intensity = 1;
		}
		intensityScale = 10;
	}
	else if(light instanceof SpotLight){
		glLight.type = GLTFLight.TYPE_SPOT;
		glLight.spot = new GLTFSpotLight();
		if(light instanceof SpotLightEx){
			glLight.intensity = ((SpotLightEx) light).intensity;
			glLight.range = ((SpotLightEx) light).range;
		}else{
			glLight.intensity = 1;
		}
		intensityScale = 10;
		// https://github.com/KhronosGroup/glTF/blob/master/extensions/2.0/Khronos/KHR_lights_punctual/README.md#inner-and-outer-cone-angles
		// inverse formula
		float cosDeltaAngle = 1f / ((SpotLight)light).exponent;
		float cosOuterAngle = -((SpotLight)light).cutoffAngle / ((SpotLight)light).exponent;
		glLight.spot.outerConeAngle = (float)Math.acos(cosOuterAngle);
		glLight.spot.innerConeAngle = (float)Math.acos(cosOuterAngle + cosDeltaAngle);
	}
	else{
		throw new GdxRuntimeException("unsupported light type " + light.getClass());
	}
	
	// rescale color based on intensity
	glLight.color = GLTFExportTypes.rgb(light.color.cpy().mul(1f / glLight.intensity));
	glLight.intensity *= intensityScale;
	
	return glLight;
}