Quellcode durchsuchen

Merge remote branch 'remotes/upstream/master'

alteredq vor 15 Jahren
Ursprung
Commit
47a4c91ebc

+ 11 - 0
AUTHORS

@@ -0,0 +1,11 @@
+Authors ordered by first contribution.
+
+http://github.com/mrdoob
+http://github.com/supereggbert
+http://github.com/sole
+http://kile.stravaganza.org
+http://github.com/kikko
+http://github.com/philogb
+http://github.com/julianwa
+http://github.com/mindlapse
+http://github.com/alteredq

+ 1 - 1
LICENSE

@@ -1,6 +1,6 @@
 The MIT License
 
-Copyright (c) 2010 Mr.doob
+Copyright (c) 2010 Mr.doob, http://mrdoob.com
 
 Permission is hereby granted, free of charge, to any person obtaining a copy
 of this software and associated documentation files (the "Software"), to deal

+ 19 - 15
TODO

@@ -1,16 +1,20 @@
-- Core
-	- Simple hierarchy system (look at D1plo1d and tamask branches)
-	- Interaction, 2D to 3D projection.
-- Examples
-	- DOMRenderer example
-- Materials
-	- MeshBitmapSphereMappingMaterial. http://en.wikipedia.org/wiki/Sphere_mapping
-	- MeshBitmapCubeMappingMaterial. http://en.wikipedia.org/wiki/Cube_mapping
-	- MeshShaderMaterial for WebGLRenderer
-	- Add MeshBitmapUVMappingMaterial to WebGLRenderer
-- Renderers
-	- Add Lights to Renderer (CanvasRenderer and SVGRenderer)
-	- FrustrumClipping near to Renderer (CanvasRenderer and SVGRenderer)
-- Utils
-	- Blender 2.5b4 plugin system has change considerably :/
+Core
+* Simple hierarchy system (look at D1plo1d and tamask branches)
+* Interaction, 2D to 3D projection. (look at mindlapse branch)
 
+Examples
+* DOMRenderer example
+
+Materials
+* MeshFaceMaterial? (Renderer would use face materials instead, MeshFaceColorFillFaceMaterial/MeshFaceColorStrokeMaterial wouldn't be needed?)
+* MeshBitmapSphereMappingMaterial. http://en.wikipedia.org/wiki/Sphere_mapping
+* MeshBitmapCubeMappingMaterial. http://en.wikipedia.org/wiki/Cube_mapping
+* MeshBitmapMaterial? (Merge all MeshBitmap*Materials and have a mode parameter like... MeshBitmapMaterial.UV_MAPPING)
+* MeshShaderMaterial for WebGLRenderer
+* Add MeshBitmapUVMappingMaterial to WebGLRenderer
+
+Renderers
+* Add PointLight to WebGLRenderer
+* WebGLRenderer support MeshBitmapUVMappingMaterial (look at alteredq branch)
+* Double check DirectionalLight WebGLRenderer code (doesn't seem correct)
+* FrustrumClipping near to Renderer (CanvasRenderer and SVGRenderer)

+ 80 - 0
utils/exporters/blender/2.54/scripts/op/io_mesh_threejs/__init__.py

@@ -0,0 +1,80 @@
+# ##### BEGIN GPL LICENSE BLOCK #####
+#
+#  This program is free software; you can redistribute it and/or
+#  modify it under the terms of the GNU General Public License
+#  as published by the Free Software Foundation; either version 2
+#  of the License, or (at your option) any later version.
+#
+#  This program is distributed in the hope that it will be useful,
+#  but WITHOUT ANY WARRANTY; without even the implied warranty of
+#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#  GNU General Public License for more details.
+#
+#  You should have received a copy of the GNU General Public License
+#  along with this program; if not, write to the Free Software Foundation,
+#  Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+# ##### END GPL LICENSE BLOCK #####
+
+# To support reload properly, try to access a package var, if it's there, reload everything
+if "bpy" in locals():
+    import sys
+    reload(sys.modules.get("io_mesh_threejs.export_threejs", sys))
+
+
+import bpy
+from bpy.props import *
+from io_utils import ExportHelper
+
+
+class ExportTHREEJS(bpy.types.Operator, ExportHelper):
+    '''This script exports the selected object for the three.js engine.'''
+    bl_idname = "export.threejs"
+    bl_label = "Export Three.js"
+    
+    filename_ext = ".js"
+
+    use_modifiers = BoolProperty(name="Apply Modifiers", description="Apply Modifiers to the exported mesh", default=True)
+    use_normals = BoolProperty(name="Normals", description="Export Normals for smooth and hard shaded faces", default=True)
+    use_uv_coords = BoolProperty(name="UVs", description="Exort the active UV layer", default=True)
+    use_colors = BoolProperty(name="Vertex Colors", description="Exort the active vertex color layer", default=True)
+
+    @classmethod
+    def poll(cls, context):
+        return context.active_object != None
+
+    def execute(self, context):
+        print("Selected: " + context.active_object.name)
+
+        if not self.properties.filepath:
+            raise Exception("filename not set")
+
+        filepath = self.filepath
+        import io_mesh_threejs.export_threejs
+        return io_mesh_threejs.export_threejs.save(self, context, **self.properties)
+
+    def draw(self, context):
+        layout = self.layout
+
+        row = layout.row()
+        row.prop(self.properties, "use_modifiers")
+        row.prop(self.properties, "use_normals")
+        row = layout.row()
+        row.prop(self.properties, "use_uv_coords")
+        row.prop(self.properties, "use_colors")
+
+
+def menu_func(self, context):
+    default_path = bpy.data.filepath.replace(".blend", ".js")
+    self.layout.operator(ExportTHREEJS.bl_idname, text="Three.js (.js)").filepath = default_path
+
+
+def register():
+    bpy.types.INFO_MT_file_export.append(menu_func)
+
+
+def unregister():
+    bpy.types.INFO_MT_file_export.remove(menu_func)
+
+if __name__ == "__main__":
+    register()

+ 175 - 0
utils/exporters/blender/2.54/scripts/op/io_mesh_threejs/export_threejs.py

@@ -0,0 +1,175 @@
+# ##### BEGIN GPL LICENSE BLOCK #####
+#
+#  This program is free software; you can redistribute it and/or
+#  modify it under the terms of the GNU General Public License
+#  as published by the Free Software Foundation; either version 2
+#  of the License, or (at your option) any later version.
+#
+#  This program is distributed in the hope that it will be useful,
+#  but WITHOUT ANY WARRANTY; without even the implied warranty of
+#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#  GNU General Public License for more details.
+#
+#  You should have received a copy of the GNU General Public License
+#  along with this program; if not, write to the Free Software Foundation,
+#  Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+# ##### END GPL LICENSE BLOCK #####
+
+# Based on export_ply.py
+# Contributors: Mr.doob, Kikko
+
+"""
+This script exports the selected object for the three.js engine.
+"""
+
+import bpy
+import os
+
+def save(operator, context, filepath="", use_modifiers=True, use_normals=True, use_uv_coords=True, use_colors=True):
+    
+    def rvec3d(v):
+        return round(v[0], 6), round(v[1], 6), round(v[2], 6)
+
+    def rvec2d(v):
+        return round(v[0], 6), round(v[1], 6)
+    
+    scene = context.scene
+    obj = context.object
+
+    if not filepath.lower().endswith('.js'):
+        filepath += '.js'
+
+    classname = filepath.split('/')[-1].replace('.js','')
+
+    if not obj:
+        raise Exception("Error, Select 1 active object")
+
+    file = open(filepath, 'w')
+
+    if scene.objects.active:
+        bpy.ops.object.mode_set(mode='OBJECT')
+
+    if use_modifiers:
+        mesh = obj.create_mesh(scene, True, 'PREVIEW')
+    else:
+        mesh = obj.data
+
+    if not mesh:
+        raise Exception("Error, could not get mesh data from active object")
+
+    # mesh.transform(obj.matrix_world) # XXX
+
+    faceUV = (len(mesh.uv_textures) > 0)
+    vertexUV = (len(mesh.sticky) > 0)
+    vertexColors = len(mesh.vertex_colors) > 0
+
+    if (not faceUV) and (not vertexUV):
+        use_uv_coords = False
+    if not vertexColors:
+        use_colors = False
+
+    if not use_uv_coords:
+        faceUV = vertexUV = False
+    if not use_colors:
+        vertexColors = False
+
+    if faceUV:
+        active_uv_layer = mesh.uv_textures.active
+        if not active_uv_layer:
+            use_uv_coords = False
+            faceUV = None
+        else:
+            active_uv_layer = active_uv_layer.data
+
+    if vertexColors:
+        active_col_layer = mesh.vertex_colors.active
+        if not active_col_layer:
+            use_colors = False
+            vertexColors = None
+        else:
+            active_col_layer = active_col_layer.data
+
+    # incase
+    color = uvcoord = uvcoord_key = normal = normal_key = None
+
+    file.write('// Generated with Blender 2.54 exporter\n')
+    file.write('// http://github.com/mrdoob/three.js/tree/master/utils/exporters/blender\n\n')
+
+    file.write('var %s = function () {\n\n' % classname)
+
+    file.write('\tvar scope = this;\n\n')
+
+    file.write('\tTHREE.Geometry.call( this );\n\n')
+
+    for v in mesh.vertices:
+        file.write('\tv( %.6f, %.6f, %.6f );\n' % (v.co.x, v.co.z, -v.co.y)) # co
+
+    file.write('\n')
+
+    if use_normals:
+        for f in mesh.faces:
+            if len(f.vertices) == 3:
+                file.write('\tf3( %d, %d, %d, %.6f, %.6f, %.6f );\n' % (f.vertices[0], f.vertices[1], f.vertices[2], f.normal[0], f.normal[1], f.normal[2]))
+            else:
+                file.write('\tf4( %d, %d, %d, %d, %.6f, %.6f, %.6f );\n' % (f.vertices[0], f.vertices[1], f.vertices[2], f.vertices[3], f.normal[0], f.normal[1], f.normal[2]))
+
+    else:
+        for f in mesh.faces:
+            if len(f.vertices) == 3:
+                file.write('\tf3( %d, %d, %d );\n' % (f.vertices[0], f.vertices[1], f.vertices[2]))
+            else:
+                file.write('\tf4( %d, %d, %d, %d );\n' % (f.vertices[0], f.vertices[1], f.vertices[2], f.vertices[3]))
+
+    face_index_pairs = [ (face, index) for index, face in enumerate(mesh.faces)]
+
+    if use_uv_coords:
+        file.write('\n')
+        for f, f_index in face_index_pairs:
+            tface = mesh.uv_textures[0].data[f_index]
+            if len(f.vertices) == 3:
+                file.write('\tuv( %.6f, %.6f, %.6f, %.6f, %.6f, %.6f );\n' % (tface.uv1[0], 1.0-tface.uv1[1], tface.uv2[0], 1.0-tface.uv2[1], tface.uv3[0], 1.0-tface.uv3[1]))
+            else:
+                file.write('\tuv( %.6f, %.6f, %.6f, %.6f, %.6f, %.6f, %.6f, %.6f );\n' % (tface.uv1[0], 1.0-tface.uv1[1], tface.uv2[0], 1.0-tface.uv2[1], tface.uv3[0], 1.0-tface.uv3[1], tface.uv4[0], 1.0-tface.uv4[1]))
+
+    file.write('\n')
+
+    file.write('\tfunction v( x, y, z ) {\n\n')
+    file.write('\t\tscope.vertices.push( new THREE.Vertex( new THREE.Vector3( x, y, z ) ) );\n\n')
+    file.write('\t}\n\n')
+
+    file.write('\tfunction f3( a, b, c, nx, ny, nz ) {\n\n')
+    file.write('\t\tscope.faces.push( new THREE.Face3( a, b, c, nx && ny && nz ? new THREE.Vector3( nx, ny, nz ) : null ) );\n\n')
+    file.write('\t}\n\n')
+
+    file.write('\tfunction f4( a, b, c, d, nx, ny, nz ) {\n\n')
+    file.write('\t\tscope.faces.push( new THREE.Face4( a, b, c, d, nx && ny && nz ? new THREE.Vector3( nx, ny, nz ) : null ) );\n\n')
+    file.write('\t}\n\n')
+
+    file.write('\tfunction uv( u1, v1, u2, v2, u3, v3, u4, v4 ) {\n\n')
+    file.write('\t\tvar uv = [];\n')
+    file.write('\t\tuv.push( new THREE.UV( u1, v1 ) );\n')
+    file.write('\t\tuv.push( new THREE.UV( u2, v2 ) );\n')
+    file.write('\t\tuv.push( new THREE.UV( u3, v3 ) );\n')
+    file.write('\t\tif ( u4 && v4 ) uv.push( new THREE.UV( u4, v4 ) );\n')
+    file.write('\t\tscope.uvs.push( uv );\n')
+    file.write('\t}\n\n')
+
+    file.write('\tthis.computeCentroids();\n')
+
+    if not use_normals:
+        file.write('\tthis.computeNormals();\n')
+
+    file.write('\n}\n\n')
+
+    file.write('%s.prototype = new THREE.Geometry();\n' % classname)
+    file.write('%s.prototype.constructor = %s;' % (classname, classname))
+
+    file.close()
+
+    print("writing", filepath, "done")
+
+    if use_modifiers:
+        bpy.data.meshes.remove(mesh)
+
+    return {'FINISHED'}

+ 0 - 0
utils/exporters/export_threejs_2.53b.py → utils/exporters/blender/export_threejs_2.53b.py


+ 0 - 0
utils/exporters/export_threejs_2.5a2.py → utils/exporters/blender/export_threejs_2.5a2.py