浏览代码

Implemented factory-based mesh loading.

woollybah 10 年之前
父节点
当前提交
ea3461910d
共有 4 个文件被更改,包括 134 次插入7 次删除
  1. 85 0
      b3d.mod/b3d.bmx
  2. 8 6
      openb3d.mod/functions.bmx
  3. 26 0
      openb3d.mod/openb3dlib.bmx
  4. 15 1
      openb3dlib.mod/openb3dlib.bmx

+ 85 - 0
b3d.mod/b3d.bmx

@@ -0,0 +1,85 @@
+' Copyright (c) 2015, Bruce A Henderson
+' All rights reserved.
+' 
+' Redistribution and use in source and binary forms, with or without
+' modification, are permitted provided that the following conditions are met:
+' 
+' * Redistributions of source code must retain the above copyright notice, this
+'   list of conditions and the following disclaimer.
+' 
+' * Redistributions in binary form must reproduce the above copyright notice,
+'   this list of conditions and the following disclaimer in the documentation
+'   and/or other materials provided with the distribution.
+' 
+' THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+' IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+' DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+' FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+' DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+' SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+' CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+' OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+' OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+'
+SuperStrict
+
+Rem
+bbdoc: 
+End Rem
+Module b3d.b3d
+
+ModuleInfo "Version: 1.00"
+ModuleInfo "License: BSD"
+ModuleInfo "Copyright: 2015 Bruce A Henderson. All rights reserved"
+
+ModuleInfo "History: 1.00"
+ModuleInfo "History: Initial Release."
+
+
+Private
+
+Global mesh_loaders:TMeshLoader
+
+Public
+
+Rem
+bbdoc: Returns a mesh loader capable of loading @extension.
+End Rem
+Function GetMeshLoader:TMeshLoader(extension:String)
+
+	Local loader:TMeshLoader = mesh_loaders
+	
+	While loader
+		If loader.CanLoadMesh(extension) Then
+			Return loader
+		End If
+		loader = loader._succ
+	Wend
+
+End Function
+
+
+Type TMeshLoader
+	Field _succ:TMeshLoader
+	
+	Method New()
+		_succ=mesh_loaders
+		mesh_loaders=Self
+	End Method
+	
+	Method CanLoadMesh:Int(extension:String) Abstract
+
+	Rem
+	bbdoc: Call mesh loader implementation.
+	about: @obj could be filename (string) or perhaps TStream, if implementation supports it.
+	End Rem
+	Method LoadMesh:Object(obj:Object, parent:Object = Null) Abstract
+
+	Rem
+	bbdoc: Call animated mesh loader implementation
+	about: @obj could be filename (string) or perhaps TStream, if implementation supports it.
+	End Rem
+	Method LoadAnimMesh:Object(obj:Object, parent:Object = Null) Abstract
+	
+End Type

+ 8 - 6
openb3d.mod/functions.bmx

@@ -1576,9 +1576,10 @@ Rem
 bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=LoadAnimMesh">Online doc</a>
 End Rem
 Function LoadAnimMesh:TMesh( file:String, parent:TEntity=Null )
-	Local instance:Byte Ptr=LoadAnimMesh_( file, TEntity.EntityExists( parent ) )
-	Local mesh:TMesh=globals.mesh.NewMesh( instance )
-	Return mesh
+	Local meshLoader:TMeshLoader = GetMeshLoader(ExtractExt(file))
+	If meshloader Then
+		Return TMesh(meshLoader.LoadAnimMesh(file, parent))
+	End If
 End Function
 
 Rem
@@ -1603,9 +1604,10 @@ Rem
 bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=LoadMesh">Online doc</a>
 End Rem
 Function LoadMesh:TMesh( file:String, parent:TEntity=Null )
-	Local instance:Byte Ptr=LoadMesh_( file, TEntity.EntityExists( parent ) )
-	Local mesh:TMesh=globals.mesh.NewMesh( instance )
-	Return mesh
+	Local meshLoader:TMeshLoader = GetMeshLoader(ExtractExt(file))
+	If meshloader Then
+		Return TMesh(meshLoader.LoadMesh(file, parent))
+	End If
 End Function
 
 Rem

+ 26 - 0
openb3d.mod/openb3dlib.bmx

@@ -24,6 +24,7 @@
 
 Strict
 
+Import b3d.b3d
 Import brl.map
 Import brl.Graphics
 Import b3d.OpenB3dLib
@@ -1014,3 +1015,28 @@ End Type
 ' -----------------
 
 Include "functions.bmx"
+
+
+
+Type TOpenB3DMeshLoader Extends TMeshLoader
+	
+	Method CanLoadMesh:Int(extension:String)
+		Select extension.ToLower()
+			Case "b3d"
+				Return True
+		End Select
+	End Method
+
+	Method LoadMesh:Object(obj:Object, parent:Object = Null)
+		Local instance:Byte Ptr = LoadMesh_(String(obj), TEntity.EntityExists( TEntity(parent) ) )
+		Return globals.mesh.NewMesh( instance )
+	End Method
+
+	Method LoadAnimMesh:Object(obj:Object, parent:Object = Null)
+		Local instance:Byte Ptr = LoadAnimMesh_(String(obj), TEntity.EntityExists(TEntity(parent) ) )
+		Return globals.mesh.NewMesh( instance )
+	End Method
+	
+End Type
+
+New TOpenB3DMeshLoader

+ 15 - 1
openb3dlib.mod/openb3dlib.bmx

@@ -34,8 +34,22 @@ ModuleInfo "Copyright: Openb3d - Angelo Rosina"
 
 ModuleInfo "History: 1.00 Initial Release"
 
-
+?win32
+Import Pub.Glew
+Import Pub.OpenGL ' order is important, glew before OpenGL
+?macos
+Import Pub.Glew
+Import Pub.OpenGL ' order is important, glew before OpenGL
+?linuxx86
+Import Pub.Glew
+Import Pub.OpenGL ' order is important, glew before OpenGL
+?linuxx64
 Import Pub.Glew
 Import Pub.OpenGL ' order is important, glew before OpenGL
+?raspberrypi
+Import Pub.OpenGLES
+?android
+Import Pub.OpenGLES
+?
 
 Import "source.bmx"