提交 c85a5b5b 编写于 作者: Z zz85

Merge remote-tracking branch 'mrdoob/dev'

因为 它太大了无法显示 source diff 。你可以改为 查看blob
此差异已折叠。
此差异已折叠。
因为 它太大了无法显示 source diff 。你可以改为 查看blob
...@@ -5,13 +5,14 @@ ...@@ -5,13 +5,14 @@
* http://webglsamples.googlecode.com/hg/blob/blob.html * http://webglsamples.googlecode.com/hg/blob/blob.html
*/ */
THREE.MarchingCubes = function ( resolution, material, enableUvs ) { THREE.MarchingCubes = function ( resolution, material, enableUvs, enableColors ) {
THREE.ImmediateRenderObject.call( this ); THREE.ImmediateRenderObject.call( this );
this.material = material; this.material = material;
this.enableUvs = enableUvs !== undefined ? enableUvs : false; this.enableUvs = enableUvs !== undefined ? enableUvs : false;
this.enableColors = enableColors !== undefined ? enableColors : false;
// functions have to be object properties // functions have to be object properties
// prototype functions kill performance // prototype functions kill performance
...@@ -55,6 +56,7 @@ THREE.MarchingCubes = function ( resolution, material, enableUvs ) { ...@@ -55,6 +56,7 @@ THREE.MarchingCubes = function ( resolution, material, enableUvs ) {
this.hasPositions = false; this.hasPositions = false;
this.hasNormals = false; this.hasNormals = false;
this.hasColors = false;
this.hasUvs = false; this.hasUvs = false;
this.positionArray = new Float32Array( this.maxCount * 3 ); this.positionArray = new Float32Array( this.maxCount * 3 );
...@@ -66,6 +68,12 @@ THREE.MarchingCubes = function ( resolution, material, enableUvs ) { ...@@ -66,6 +68,12 @@ THREE.MarchingCubes = function ( resolution, material, enableUvs ) {
} }
if ( this.enableColors ) {
this.colorArray = new Float32Array( this.maxCount * 3 );
}
}; };
/////////////////////// ///////////////////////
...@@ -317,6 +325,8 @@ THREE.MarchingCubes = function ( resolution, material, enableUvs ) { ...@@ -317,6 +325,8 @@ THREE.MarchingCubes = function ( resolution, material, enableUvs ) {
var c = this.count * 3; var c = this.count * 3;
// positions
this.positionArray[ c ] = pos[ o1 ]; this.positionArray[ c ] = pos[ o1 ];
this.positionArray[ c + 1 ] = pos[ o1 + 1 ]; this.positionArray[ c + 1 ] = pos[ o1 + 1 ];
this.positionArray[ c + 2 ] = pos[ o1 + 2 ]; this.positionArray[ c + 2 ] = pos[ o1 + 2 ];
...@@ -329,7 +339,7 @@ THREE.MarchingCubes = function ( resolution, material, enableUvs ) { ...@@ -329,7 +339,7 @@ THREE.MarchingCubes = function ( resolution, material, enableUvs ) {
this.positionArray[ c + 7 ] = pos[ o3 + 1 ]; this.positionArray[ c + 7 ] = pos[ o3 + 1 ];
this.positionArray[ c + 8 ] = pos[ o3 + 2 ]; this.positionArray[ c + 8 ] = pos[ o3 + 2 ];
// // normals
this.normalArray[ c ] = norm[ o1 ]; this.normalArray[ c ] = norm[ o1 ];
this.normalArray[ c + 1 ] = norm[ o1 + 1 ]; this.normalArray[ c + 1 ] = norm[ o1 + 1 ];
...@@ -343,6 +353,8 @@ THREE.MarchingCubes = function ( resolution, material, enableUvs ) { ...@@ -343,6 +353,8 @@ THREE.MarchingCubes = function ( resolution, material, enableUvs ) {
this.normalArray[ c + 7 ] = norm[ o3 + 1 ]; this.normalArray[ c + 7 ] = norm[ o3 + 1 ];
this.normalArray[ c + 8 ] = norm[ o3 + 2 ]; this.normalArray[ c + 8 ] = norm[ o3 + 2 ];
// uvs
if ( this.enableUvs ) { if ( this.enableUvs ) {
var d = this.count * 2; var d = this.count * 2;
...@@ -358,6 +370,24 @@ THREE.MarchingCubes = function ( resolution, material, enableUvs ) { ...@@ -358,6 +370,24 @@ THREE.MarchingCubes = function ( resolution, material, enableUvs ) {
} }
// colors
if ( this.enableColors ) {
this.colorArray[ c ] = pos[ o1 ];
this.colorArray[ c + 1 ] = pos[ o1 + 1 ];
this.colorArray[ c + 2 ] = pos[ o1 + 2 ];
this.colorArray[ c + 3 ] = pos[ o2 ];
this.colorArray[ c + 4 ] = pos[ o2 + 1 ];
this.colorArray[ c + 5 ] = pos[ o2 + 2 ];
this.colorArray[ c + 6 ] = pos[ o3 ];
this.colorArray[ c + 7 ] = pos[ o3 + 1 ];
this.colorArray[ c + 8 ] = pos[ o3 + 2 ];
}
this.count += 3; this.count += 3;
if ( this.count >= this.maxCount - 3 ) { if ( this.count >= this.maxCount - 3 ) {
...@@ -371,6 +401,12 @@ THREE.MarchingCubes = function ( resolution, material, enableUvs ) { ...@@ -371,6 +401,12 @@ THREE.MarchingCubes = function ( resolution, material, enableUvs ) {
} }
if ( this.enableColors ) {
this.hasColors = true;
}
renderCallback( this ); renderCallback( this );
} }
...@@ -384,6 +420,7 @@ THREE.MarchingCubes = function ( resolution, material, enableUvs ) { ...@@ -384,6 +420,7 @@ THREE.MarchingCubes = function ( resolution, material, enableUvs ) {
this.hasPositions = false; this.hasPositions = false;
this.hasNormals = false; this.hasNormals = false;
this.hasUvs = false; this.hasUvs = false;
this.hasColors = false;
}; };
...@@ -404,6 +441,12 @@ THREE.MarchingCubes = function ( resolution, material, enableUvs ) { ...@@ -404,6 +441,12 @@ THREE.MarchingCubes = function ( resolution, material, enableUvs ) {
} }
if ( this.enableColors ) {
this.hasColors = true;
}
renderCallback( this ); renderCallback( this );
}; };
......
...@@ -146,11 +146,12 @@ ...@@ -146,11 +146,12 @@
resolution = 28; resolution = 28;
numBlobs = 10; numBlobs = 10;
effect = new THREE.MarchingCubes( resolution, materials[ current_material ].m, true ); effect = new THREE.MarchingCubes( resolution, materials[ current_material ].m, true, true );
effect.position.set( 0, 0, 0 ); effect.position.set( 0, 0, 0 );
effect.scale.set( 700, 700, 700 ); effect.scale.set( 700, 700, 700 );
effect.enableUvs = false; effect.enableUvs = false;
effect.enableColors = false;
scene.add( effect ); scene.add( effect );
...@@ -328,6 +329,12 @@ ...@@ -328,6 +329,12 @@
h: 0, s: 0, v: 1 h: 0, s: 0, v: 1
}, },
"colors" :
{
m: new THREE.MeshPhongMaterial( { color: 0xffffff, specular: 0xffffff, shininess: 2, vertexColors: THREE.VertexColors, perPixel: true } ),
h: 0, s: 0, v: 1
},
"plastic" : "plastic" :
{ {
m: new THREE.MeshPhongMaterial( { color: 0x000000, specular: 0x888888, ambient: 0x000000, shininess: 250, perPixel: true } ), m: new THREE.MeshPhongMaterial( { color: 0x000000, specular: 0x888888, ambient: 0x000000, shininess: 250, perPixel: true } ),
...@@ -420,13 +427,23 @@ ...@@ -420,13 +427,23 @@
mm.setValue( current_material ); mm.setValue( current_material );
if ( current_material !== "textured" ) { if ( current_material === "textured" ) {
effect.enableUvs = true;
} else {
effect.enableUvs = false; effect.enableUvs = false;
}
if ( current_material === "colors" ) {
effect.enableColors = true;
} else { } else {
effect.enableUvs = true; effect.enableColors = false;
} }
...@@ -436,11 +453,16 @@ ...@@ -436,11 +453,16 @@
function toggle( e ) { function toggle( e ) {
if ( e.style.display === "block" ) if ( e.style.display === "block" ) {
e.style.display = "none"; e.style.display = "none";
else
} else {
e.style.display = "block"; e.style.display = "block";
}
} }
effectController = { effectController = {
......
...@@ -259,7 +259,7 @@ ...@@ -259,7 +259,7 @@
controls.screen.width = width; controls.screen.width = width;
controls.screen.height = height; controls.screen.height = height;
camera.radius = ( width + height ) / 4; controls.radius = ( width + height ) / 4;
}; };
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* @author mr.doob / http://mrdoob.com/ * @author mr.doob / http://mrdoob.com/
*/ */
var THREE = THREE || { REVISION: '49' }; var THREE = THREE || { REVISION: '50dev' };
if ( ! self.Int32Array ) { if ( ! self.Int32Array ) {
......
...@@ -263,6 +263,20 @@ THREE.Object3D.prototype = { ...@@ -263,6 +263,20 @@ THREE.Object3D.prototype = {
} }
},
worldToLocal: function ( vector ) {
if ( !this.__inverseMatrixWorld ) this.__inverseMatrixWorld = new THREE.Matrix4();
return this.__inverseMatrixWorld.getInverse( this.matrixWorld ).multiplyVector3( vector );
},
localToWorld: function ( vector ) {
return this.matrixWorld.multiplyVector3( vector );
} }
}; };
......
...@@ -26,6 +26,12 @@ THREE.Ray = function ( origin, direction ) { ...@@ -26,6 +26,12 @@ THREE.Ray = function ( origin, direction ) {
var vector = new THREE.Vector3(); var vector = new THREE.Vector3();
var normal = new THREE.Vector3(); var normal = new THREE.Vector3();
var intersectPoint = new THREE.Vector3() var intersectPoint = new THREE.Vector3()
var descSort = function ( a, b ) {
return a.distance - b.distance;
};
this.intersectObject = function ( object ) { this.intersectObject = function ( object ) {
...@@ -157,6 +163,8 @@ THREE.Ray = function ( origin, direction ) { ...@@ -157,6 +163,8 @@ THREE.Ray = function ( origin, direction ) {
} }
intersects.sort( descSort );
return intersects; return intersects;
} }
...@@ -171,7 +179,7 @@ THREE.Ray = function ( origin, direction ) { ...@@ -171,7 +179,7 @@ THREE.Ray = function ( origin, direction ) {
} }
intersects.sort( function ( a, b ) { return a.distance - b.distance; } ); intersects.sort( descSort );
return intersects; return intersects;
......
...@@ -1053,6 +1053,12 @@ THREE.CanvasRenderer = function ( parameters ) { ...@@ -1053,6 +1053,12 @@ THREE.CanvasRenderer = function ( parameters ) {
break; break;
case THREE.SubtractiveBlending:
_context.globalCompositeOperation = 'darker';
break;
} }
_contextGlobalCompositeOperation = value; _contextGlobalCompositeOperation = value;
......
...@@ -2880,11 +2880,12 @@ THREE.WebGLRenderer = function ( parameters ) { ...@@ -2880,11 +2880,12 @@ THREE.WebGLRenderer = function ( parameters ) {
// Buffer rendering // Buffer rendering
this.renderBufferImmediate = function ( object, program, shading ) { this.renderBufferImmediate = function ( object, program, material ) {
if ( object.hasPositions && ! object.__webglVertexBuffer ) object.__webglVertexBuffer = _gl.createBuffer(); if ( object.hasPositions && ! object.__webglVertexBuffer ) object.__webglVertexBuffer = _gl.createBuffer();
if ( object.hasNormals && ! object.__webglNormalBuffer ) object.__webglNormalBuffer = _gl.createBuffer(); if ( object.hasNormals && ! object.__webglNormalBuffer ) object.__webglNormalBuffer = _gl.createBuffer();
if ( object.hasUvs && ! object.__webglUvBuffer ) object.__webglUvBuffer = _gl.createBuffer(); if ( object.hasUvs && ! object.__webglUvBuffer ) object.__webglUvBuffer = _gl.createBuffer();
if ( object.hasColors && ! object.__webglColorBuffer ) object.__webglColorBuffer = _gl.createBuffer();
if ( object.hasPositions ) { if ( object.hasPositions ) {
...@@ -2899,7 +2900,7 @@ THREE.WebGLRenderer = function ( parameters ) { ...@@ -2899,7 +2900,7 @@ THREE.WebGLRenderer = function ( parameters ) {
_gl.bindBuffer( _gl.ARRAY_BUFFER, object.__webglNormalBuffer ); _gl.bindBuffer( _gl.ARRAY_BUFFER, object.__webglNormalBuffer );
if ( shading === THREE.FlatShading ) { if ( material.shading === THREE.FlatShading ) {
var nx, ny, nz, var nx, ny, nz,
nax, nbx, ncx, nay, nby, ncy, naz, nbz, ncz, nax, nbx, ncx, nay, nby, ncy, naz, nbz, ncz,
...@@ -2948,7 +2949,7 @@ THREE.WebGLRenderer = function ( parameters ) { ...@@ -2948,7 +2949,7 @@ THREE.WebGLRenderer = function ( parameters ) {
} }
if ( object.hasUvs ) { if ( object.hasUvs && material.map ) {
_gl.bindBuffer( _gl.ARRAY_BUFFER, object.__webglUvBuffer ); _gl.bindBuffer( _gl.ARRAY_BUFFER, object.__webglUvBuffer );
_gl.bufferData( _gl.ARRAY_BUFFER, object.uvArray, _gl.DYNAMIC_DRAW ); _gl.bufferData( _gl.ARRAY_BUFFER, object.uvArray, _gl.DYNAMIC_DRAW );
...@@ -2957,6 +2958,15 @@ THREE.WebGLRenderer = function ( parameters ) { ...@@ -2957,6 +2958,15 @@ THREE.WebGLRenderer = function ( parameters ) {
} }
if ( object.hasColors && material.vertexColors !== THREE.NoColors ) {
_gl.bindBuffer( _gl.ARRAY_BUFFER, object.__webglColorBuffer );
_gl.bufferData( _gl.ARRAY_BUFFER, object.colorArray, _gl.DYNAMIC_DRAW );
_gl.enableVertexAttribArray( program.attributes.color );
_gl.vertexAttribPointer( program.attributes.color, 3, _gl.FLOAT, false, 0, 0 );
}
_gl.drawArrays( _gl.TRIANGLES, 0, object.count ); _gl.drawArrays( _gl.TRIANGLES, 0, object.count );
object.count = 0; object.count = 0;
...@@ -3756,7 +3766,7 @@ THREE.WebGLRenderer = function ( parameters ) { ...@@ -3756,7 +3766,7 @@ THREE.WebGLRenderer = function ( parameters ) {
} else { } else {
object.render( function( object ) { _this.renderBufferImmediate( object, program, material.shading ); } ); object.render( function( object ) { _this.renderBufferImmediate( object, program, material ); } );
} }
......
...@@ -296,7 +296,7 @@ def get_normal_indices(v, normals, mesh): ...@@ -296,7 +296,7 @@ def get_normal_indices(v, normals, mesh):
def get_uv_indices(face_index, uvs, mesh): def get_uv_indices(face_index, uvs, mesh):
uv = [] uv = []
uv_layer = mesh.uv_textures.active.data uv_layer = mesh.tessface_uv_textures.active.data
for i in uv_layer[face_index].uv: for i in uv_layer[face_index].uv:
uv.append( uvs[veckey2d(i)] ) uv.append( uvs[veckey2d(i)] )
return uv return uv
...@@ -637,7 +637,7 @@ def generate_vertex_colors(colors, option_colors): ...@@ -637,7 +637,7 @@ def generate_vertex_colors(colors, option_colors):
# ##################################################### # #####################################################
def extract_uvs(mesh, uvs, count): def extract_uvs(mesh, uvs, count):
uv_layer = mesh.uv_textures.active.data uv_layer = mesh.tessface_uv_textures.active.data
for face_index, face in enumerate(get_faces(mesh)): for face_index, face in enumerate(get_faces(mesh)):
...@@ -1760,20 +1760,20 @@ def generate_ascii_scene(data): ...@@ -1760,20 +1760,20 @@ def generate_ascii_scene(data):
def export_scene(scene, filepath, flipyz, option_colors, option_lights, option_cameras, option_embed_meshes, embeds, option_url_base_html, option_copy_textures): def export_scene(scene, filepath, flipyz, option_colors, option_lights, option_cameras, option_embed_meshes, embeds, option_url_base_html, option_copy_textures):
source_file = os.path.basename(bpy.data.filepath) source_file = os.path.basename(bpy.data.filepath)
# objects are contained in scene and linked groups # objects are contained in scene and linked groups
objects = [] objects = []
# get scene objects # get scene objects
sceneobjects = scene.objects sceneobjects = scene.objects
for obj in sceneobjects: for obj in sceneobjects:
objects.append(obj) objects.append(obj)
# get linked group objcts # get linked group objcts
for group in bpy.data.groups: for group in bpy.data.groups:
for object in group.objects: for object in group.objects:
objects.append(object) objects.append(object)
scene_text = "" scene_text = ""
data = { data = {
"scene" : scene, "scene" : scene,
...@@ -1834,15 +1834,15 @@ def save(operator, context, filepath = "", ...@@ -1834,15 +1834,15 @@ def save(operator, context, filepath = "",
# objects are contained in scene and linked groups # objects are contained in scene and linked groups
objects = [] objects = []
# get scene objects # get scene objects
for obj in sceneobjects: for obj in sceneobjects:
objects.append(obj) objects.append(obj)
# get objects in linked groups # get objects in linked groups
for group in bpy.data.groups: for group in bpy.data.groups:
for object in group.objects: for object in group.objects:
objects.append(object) objects.append(object)
if option_export_scene: if option_export_scene:
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册