added mesh_create_derived_view(ob) to DerivedMesh.c
authorCampbell Barton <ideasman42@gmail.com>
Sun, 17 Sep 2006 05:15:56 +0000 (05:15 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Sun, 17 Sep 2006 05:15:56 +0000 (05:15 +0000)
exactly the same as mesh_create_derived_render(ob) except it uses the view modifier settings.

Added an optional arg to getFromObject to 'render' so you can choose to get the mesh displayed in the 3d view or generate one with render settings.
Solved bug 4612 getFromObject now works with soft body meshes (error was caused by getting the derived mesh from a copy of the object)

removed workaround for softbody bug in object_apply_def.py

release/scripts/object_apply_def.py
source/blender/blenkernel/BKE_DerivedMesh.h
source/blender/blenkernel/intern/DerivedMesh.c
source/blender/python/api2_2x/Mesh.c
source/blender/python/api2_2x/doc/Mesh.py

index 6b8d07bc51aee66d049bbb9e639ff86a8260709c..6417fe9ec8cb462dc94768e31be400066379c04b 100644 (file)
@@ -65,29 +65,6 @@ This script will work with object types: Mesh, Metaballs, Text3d, Curves and Nur
 import Blender
 import BPyMesh
 
-
-def mesh_from_ob(ob):
-       '''
-       This wraps 
-       BPyMesh.getMeshFromObject
-       and NMesh.GetRawFromObject()
-       
-       Because BPyMesh.getMeshFromObject dosent do softbody meshes at the moment - a problem with Mesh
-       
-       WARNING Returns a Mesh or NMesh, should be ok- but take care
-       '''
-       if ob.isSB():
-               # NMesh for softbody
-               try:
-                       return Blender.NMesh.GetRawFromObject(ob.name)
-               except:
-                       return None
-       else:
-               # Mesh for no softbody
-               return BPyMesh.getMeshFromObject(ob, vgroups=False)
-
-
-
 def apply_deform():
        scn= Blender.Scene.GetCurrent()
        ADD= Blender.Mesh.AssignModes.ADD
@@ -143,7 +120,8 @@ def apply_deform():
        for ob in ob_list:
                
                # Get the mesh data
-               new_me= mesh_from_ob(ob)
+               new_me= BPyMesh.getMeshFromObject(ob, vgroups=False)
+               
                if not new_me:
                        continue # Object has no display list
                
index fdba213ce6e25220a4c3eb8ed81164062dbb360f..d09cb458ba4ddca14da284b0bcfa4fea4a40b10e 100644 (file)
@@ -395,6 +395,7 @@ DerivedMesh *mesh_get_derived_deform(struct Object *ob, int *needsFree_r);
 DerivedMesh *mesh_create_derived_for_modifier(struct Object *ob, struct ModifierData *md);
 
 DerivedMesh *mesh_create_derived_render(struct Object *ob);
+DerivedMesh *mesh_create_derived_view(struct Object *ob); /* same as above but wont use render settings */
 DerivedMesh *mesh_create_derived_no_deform(struct Object *ob, float (*vertCos)[3]);
 DerivedMesh *mesh_create_derived_no_deform_render(struct Object *ob, float (*vertCos)[3]);
 
index 79cac1b4657a5811913797f8355c327debc60c37..339958e2041c3d6e5fce829b1aa3a5578ff37357 100644 (file)
@@ -3345,6 +3345,15 @@ DerivedMesh *mesh_create_derived_render(Object *ob)
        return final;
 }
 
+DerivedMesh *mesh_create_derived_view(Object *ob)
+{
+       DerivedMesh *final;
+
+       mesh_calc_modifiers(ob, NULL, NULL, &final, 0, 1, 0);
+
+       return final;
+}
+
 DerivedMesh *mesh_create_derived_no_deform(Object *ob, float (*vertCos)[3])
 {
        DerivedMesh *final;
index 7aed521c504c6f25c54dcfeeeddf766f5676c31c..abb32ab85fb6aa186e04084cafca8dad70a83db4 100644 (file)
@@ -5591,9 +5591,9 @@ static PyObject *Mesh_getFromObject( BPy_Mesh * self, PyObject * args )
        DispListMesh *dlm;
        DerivedMesh *dm;
        Object *tmpobj = NULL;
-       int cage = 0, i;
+       int cage = 0, render = 0, i;
 
-       if( !PyArg_ParseTuple( args, "s|i", &name, &cage ) )
+       if( !PyArg_ParseTuple( args, "s|i", &name, &cage, &render ) )
                return EXPP_ReturnPyObjError( PyExc_TypeError,
                                "expected string and optional integer arguments" );
 
@@ -5664,34 +5664,25 @@ static PyObject *Mesh_getFromObject( BPy_Mesh * self, PyObject * args )
                break;
        case OB_MESH:
                /* copies object and modifiers (but not the data) */
-               tmpobj= copy_object( ob );
-               tmpmesh = tmpobj->data;
-               tmpmesh->id.us--;
-               
                if (cage) {
                        /* copies the data */
-                       tmpobj->data = copy_mesh( tmpmesh );
-                       G.totmesh++;
-                       tmpmesh = tmpobj->data;
-               
+                       tmpmesh = copy_mesh( ob->data );
                /* if not getting the original caged mesh, get final derived mesh */
                } else {
-                       
                        /* Make a dummy mesh, saves copying */
                        
-                       tmpmesh = add_mesh(  );
-                       G.totmesh++;
-                       
                        /* Write the display mesh into the dummy mesh */
-                       dm = mesh_create_derived_render( tmpobj );
+                       if (render)
+                               dm = mesh_create_derived_render( ob );
+                       else
+                               dm = mesh_create_derived_view( ob );
+                       
                        dlm = dm->convertToDispListMesh( dm, 0 );
+                       tmpmesh = add_mesh(  );
                        displistmesh_to_mesh( dlm, tmpmesh );
                        dm->release( dm );
                }
                
-               /* take control of mesh before object is freed */
-               tmpobj->data = NULL;
-               free_libblock_us( &G.main->object, tmpobj );
                break;
        default:
                return EXPP_ReturnPyObjError( PyExc_AttributeError,
index a2e8f1e66ece760d3f3a3d92d39ef0a72c77fcbd..584b9c32ab887991f3486d3ca99f0c67db5d229b 100644 (file)
@@ -746,7 +746,7 @@ class Mesh:
   @type texMesh: Mesh or None
   """
 
-  def getFromObject(name,cage=0):
+  def getFromObject(name,cage=0, render=0):
     """
     Replace the mesh's existing data with the raw mesh data from a Blender
     Object.  This method supports all the geometry based objects (mesh, text,
@@ -762,6 +762,8 @@ class Mesh:
     @param name: name of the Blender object which contains the geometry data.
     @type cage: int
     @param cage: determines whether the original vertices or derived vertices
+    @type render: int
+    @param render: determines whether the render setting for modifiers will be used or not.
     (for objects with modifiers) are used.  The default is derived vertices.
     """