Dans notre précédent tutoriel, nous avons vu comment texturer un objets 3D, pour afficher des effets d’ombres sur ces derniers.
Pour aller plus loin que ce dernier qui nous permettait seulement de faire une texture avec un dégradé entre deux couleurs, nous allons voir comment afficher une ombre sur une texture image.
Pour cela nous allons utiliser un BitmapMaterial (ligne 44) dont nous avions déjà parlé dans ce tutoriel, un PhongShader (ligne 45)qui va être le material qui affichera notre ombre, comme le PhongMaterial vu dans le tutoriel précédent, il reçoit notre objet lumière, la couleur de la lumière, la couleur de l’ombre, et le specularLevel.
Après avoir créé ces deux textures, il nous reste à créer un ShadedMaterial (ligne 47) dans lequel nous passerons les deux materials précédent, et que nous utiliserons comme texture pour notre Sphere.
-
package {
-
import org.papervision3d.lights.PointLight3D;
-
import org.papervision3d.materials.BitmapMaterial;
-
import org.papervision3d.materials.shaders.PhongShader;
-
import org.papervision3d.materials.shaders.ShadedMaterial;
-
import org.papervision3d.objects.primitives.Sphere;
-
import org.papervision3d.view.BasicView;
-
-
import flash.display.BitmapData;
-
import flash.display.Loader;
-
import flash.events.Event;
-
import flash.net.URLRequest;
-
-
public class BasicScene extends BasicView {
-
-
public function BasicScene()
-
{
-
initMaterial();
-
}
-
-
private function initMaterial() : void
-
{
-
myLoader = new Loader();
-
myLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, onLoadComplete);
-
myLoader.load(new URLRequest("URL IMAGE"));
-
}
-
-
private function onLoadComplete(event : Event) : void
-
{
-
myLoader.contentLoaderInfo.removeEventListener(Event.COMPLETE, onLoadComplete);
-
-
bmpData = new BitmapData(myLoader.width, myLoader.height);
-
-
bmpData.draw(myLoader);
-
-
buildPlane();
-
}
-
-
private function buildPlane() : void
-
{
-
var light : PointLight3D = new PointLight3D();
-
scene.addChild(light);
-
-
var material : BitmapMaterial = new BitmapMaterial(bmpData);
-
var ps : PhongShader = new PhongShader(light, 0xffffff, 0×000000, 10);
-
-
var shadeMaterial : ShadedMaterial = new ShadedMaterial(material, ps);
-
shadeMaterial.doubleSided = true;
-
-
sphere = new Sphere(shadeMaterial, 200, 12, 12);
-
scene.addChild(sphere);
-
-
startRendering();
-
}
-
-
override protected function onRenderTick(event:Event=null):void
-
{
-
sphere.rotationY += 3;
-
super.onRenderTick(event);
-
}
-
-
private var sphere : Sphere;
-
private var myLoader : Loader;
-
private var bmpData : BitmapData;
-
}
-
}





oups ^^ autant pour moi !!