2012-10-05 61 views

回答

0

好像我是使用了錯誤的lib :)

這是一個更好的抽象:

https://github.com/labe-me/haxe-three.js

要加載3D模型,你會去這樣理解:

package co.za.anber; 
import js.three.Three; 
import js.Lib; 

class Main 
{ 
    static private var scene:Scene; 

    static function main() 
    { 
     //Get the dimensions of the scene 
     var w = Lib.window.innerWidth; 
     var h = Lib.window.innerHeight; 

     scene = new Scene(); 

     //add some light 
     var pointLight = new PointLight(0xffffff, 1, 0); 
     pointLight.position.set(10, 50, 130); 
     scene.add(pointLight); 
     //add a camera 
     var camera = new PerspectiveCamera(70, w/h, 1, 1000); 
     camera.position.z = 500; 
     scene.add(camera); 

     //setup renderer in the document 
     var renderer = new WebGLRenderer(null); 
     renderer.setSize(w, h); 
     Lib.document.body.appendChild(renderer.domElement); 


     //Load the Blender exported Mesh. 
     //This is where we load the Mesh and setup the onload handler. This was the part I wasn't so sure about. 
     var loader:JSONLoader = new JSONLoader(true); 
     //I don't like in-line functions. You need to make the returning function into a Dynamic type. 
     var callbackModel:Dynamic = function(geometry:Dynamic){createScene(geometry); }; 
     loader.load("Suzanne.js", callbackModel); 


     //Listen for mouse move. In-line function from somewhere else. 
     var mouseX = 0, mouseY = 0; 
     untyped Lib.document.addEventListener('mousemove', function(event){ 
      mouseX = (event.clientX - Lib.window.innerWidth/2); 
      mouseY = (event.clientY - Lib.window.innerHeight/2); 
     }, false); 

     //Render the scene @60 frames per second. Inline function from somewhere else. 
     var timer = new haxe.Timer(Math.round(1000/60)); 
     timer.run = function(){ 
      camera.position.x += (mouseX - camera.position.x) * 0.05; 
      camera.position.y += (-mouseY - camera.position.y) * 0.05; 
      camera.lookAt(scene.position); 
      renderer.render(scene, camera); 
     } 
    } 

    /** 
    * Onload complete handler. Here we can add our Mesh. 
    * @param geometry 
    */ 
    static function createScene(geometry:Dynamic):Void{ 
     var mesh:Mesh = new Mesh(geometry, new MeshLambertMaterial({ color: 0x00FF00 })); 
     //We scale it up to be visible! 
     mesh.scale.set(150.15, 150.5, 150.5); 
     scene.add(mesh); 
    } 


} 

希望這可以幫助某人。

0

看看this,它應該幫助你。

+0

感謝您的回覆。我應該更清楚。我已經使用該腳本將3D網格導出爲json對象。這部分不是問題。我的問題是如何使用Haxe將該文件加載到Three.js中。 – anber

+0

你應該使用插件,你可以通過我發佈的鏈接找到。寫一個簡單的extern,它應該像5行代碼。 – stroncium

相關問題