add lighting to the minecraft character

David Jones

If you haven’t seen my last blog post about the minecraft character i created using alternativa3d then you should check it out here. This post is a follow up from this changing the existing code to include lighting in the scene. I’ve decided that I’m going to do several follow on posts starting with this one so stay tuned for more! Anyway in this example I changed the minecraft player/character we created and added a lighting effect which is now available in alternativa3d 7.7.0. In order to do this there are a few things we need to do, first off we need to add in the extra libraries.

import alternativa.engine3d.lights.DirectionalLight;
import alternativa.engine3d.materials.VertexLightMaterial;

The directional light is going to be our light source, the vertex light material is the new material which we will apply to the model to make sure it interacts with the light source. Next up we need to add a variable for our light source and then initiate it and direct it on the scene. I had to do some playing around using the debug features of alternativa to get the light source in the position I wanted. So you may have to do some trial and error depending on what you are doing.

private var directionalLight:DirectionalLight;
// Lighting
directionalLight = new DirectionalLight(0xFFFFFF);
directionalLight.x = 0;
directionalLight.z = 20;
directionalLight.y = 20;
directionalLight.rotationX = -90*Math.PI/180;
directionalLight.rotationZ = 180*Math.PI/180;

Once we have our light source we need to make sure that our character actually also calculates the normals for the 3d objects. To do this each of the parts of the body you need to add a one line as follows.

bodypart.calculateVerticesNormals(true, 0.01);

The last thing we need to do is apply a texture material that uses our texture as well as taking into consideration any lighting. To do this we can use the VertexLightMaterial, so we need to replace any TextureMaterial with VertexLightMaterial like so

// HEAD texture materials
var front_head:VertexLightMaterial = new VertexLightMaterial(cropBitmapData(src, new Point(8, 8), 8, 8),repeat,smooth,mipMapping,resolution);
var back_head:VertexLightMaterial = new VertexLightMaterial(cropBitmapData(src, new Point(24, 8), 8, 8),repeat,smooth,mipMapping,resolution);
var left_head:VertexLightMaterial = new VertexLightMaterial(cropBitmapData(src, new Point(16, 8), 8, 8),repeat,smooth,mipMapping,resolution);
var right_head:VertexLightMaterial = new VertexLightMaterial(cropBitmapData(src, new Point(0, 8), 8, 8),repeat,smooth,mipMapping,resolution);
var top_head:VertexLightMaterial = new VertexLightMaterial(cropBitmapData(src, new Point(8, 0), 8, 8),repeat,smooth,mipMapping,resolution);
var bottom_head:VertexLightMaterial = new VertexLightMaterial(cropBitmapData(src, new Point(16, 0), 8, 8),repeat,smooth,mipMapping,resolution);

Note that it still takes the same parameters as the regular texture material but it will now also work with the directional light. Once that is all done you should have something that looks like this minecraft lighting Download the demo files here for flash and flex



  • avatar-minecraft-crafting
    # Minecraft crafting
    Can you play minecraft online if you didnt pay for it?
    • avatar-davidejones
      # davidejones
      Its probably possible but that is not what this post is about.
  • avatar-minecraft
    # Minecraft
    Can you give me a list with the servers to play?
  • avatar-uv-scrolling-material-for-alternativa3d
    # UV Scrolling Material for Alternativa3D |
    […] How to Change Minecraft SkinsMinecraft Character in 3d Using Alternativa3dEvil Psychic Minecraft SkinRailCraft Mod for Minecraft 1.0.0Minecraft BlogAwesome Minecraft FunMinecraft alternativa3d character with lighting setup […]
  • avatar-matt
    # Matt
    Nice post. Do you know if the vertex light material can be applied to geospheres?
  • avatar-davidejones
    # davidejones
    you should be able to apply the vertexlightmaterial to any mesh so it should work with geospheres. Note that this blog post is using alternativa3d 7

Comments are currently closed