浏览代码

Added scenedocument.monkey2

Mark Sibly 8 年之前
父节点
当前提交
914241ede5
共有 2 个文件被更改,包括 43 次插入17 次删除
  1. 42 15
      src/ted2/scenedocument.monkey2
  2. 1 2
      src/ted2/ted2.monkey2

+ 42 - 15
src/ted2/scenedocument.monkey2

@@ -2,7 +2,7 @@
 Namespace ted2
 
 #Import "<mojo3d>"
-#Import "<mojo3d-assimp>"
+#Import "<mojo3d-loaders>"
 
 Using mojo3d..
 
@@ -34,15 +34,15 @@ Class SceneDocumentView Extends View
 		RequestRender()
 		
 		If Keyboard.KeyDown( Key.Up )
-			model.RotateX( .1 )
+			model.RotateX( 3 )
 		Else If Keyboard.KeyDown( Key.Down )
-			model.RotateX( -.1 )
+			model.RotateX( -3 )
 		Endif
 		
 		If Keyboard.KeyDown( Key.Left )
-			model.RotateY( .1,True )
+			model.RotateY( 3,True )
 		Else If Keyboard.KeyDown( Key.Right )
-			model.RotateY( -.1,True )
+			model.RotateY( -3,True )
 		Endif
 
 		If Keyboard.KeyDown( Key.A )
@@ -57,6 +57,20 @@ Class SceneDocumentView Extends View
 	Method OnMouseEvent( event:MouseEvent ) Override
 	End
 	
+	Method OnKeyEvent( event:KeyEvent ) Override
+		
+		If event.Type=EventType.KeyDown
+			Select event.Key
+			Case Key.R
+				_doc.Camera.Position=New Vec3f(0,0,-2.5)
+				_doc.Model.Rotation=New Vec3f(0,0,0)
+			Case Key.S
+				_doc.Light.ShadowsEnabled=Not _doc.Light.ShadowsEnabled
+			End
+		Endif
+		
+	End
+	
 	Private
 
 	Field _doc:SceneDocument
@@ -81,14 +95,11 @@ Class SceneDocument Extends Ted2Document
 		_light=New Light
 		_light.RotateX( Pi/2 )
 		
+		_model=null
+		
 		Scene.SetCurrent( Null )
 	End
 	
-	Property Model:Model()
-	
-		Return _model
-	End
-	
 	Property Scene:Scene()
 		
 		Return _scene
@@ -99,21 +110,35 @@ Class SceneDocument Extends Ted2Document
 		Return _camera
 	End
 	
+	Property Light:Light()
+		
+		Return _light
+	End
+	
+	Property Model:Model()
+	
+		Return _model
+	End
+	
 	Protected
 	
 	Method OnLoad:Bool() Override
-
-		Scene.SetCurrent( _scene )
+		
+		If _model _model.Destroy()
 		
 		Print "Loading model:"+Path
 
+		Scene.SetCurrent( _scene )
+		
 		_model=Model.Load( Path )
+		
+		Scene.SetCurrent( Null )
 
 		If _model
+			
 			_model.Mesh.FitVertices( New Boxf( -1,1 ) )
+			
 		Endif
-		
-		Scene.SetCurrent( Null )
 	
 		Return True
 	End
@@ -125,6 +150,8 @@ Class SceneDocument Extends Ted2Document
 	
 	Method OnClose() Override
 		
+		_scene.DestroyAllEntities()
+		
 	End
 	
 	Method OnCreateView:SceneDocumentView() Override
@@ -152,7 +179,7 @@ Class SceneDocumentType Extends Ted2DocumentType
 	Method New()
 		AddPlugin( Self )
 		
-		Extensions=New String[]( ".b3d",".3ds",".dae" )
+		Extensions=New String[]( ".b3d",".3ds",".obj",".dae",".fbx",".blend",".x" )
 	End
 	
 	Method OnCreateDocument:Ted2Document( path:String ) Override

+ 1 - 2
src/ted2/ted2.monkey2

@@ -34,8 +34,7 @@
 #import "audiodocument"
 #import "jsondocument"
 #import "xmldocument"
-
-'#Import "scenedocument"
+#Import "scenedocument"
 
 #import "textviewkeyeventfilter"