Merged revision(s) 58226-58240 from trunk/blender into soc-2013-dingto.

This commit is contained in:
Thomas Dinges
2013-07-14 16:54:20 +00:00
17 changed files with 150 additions and 71 deletions

View File

@@ -212,13 +212,27 @@ static void mikk_compute_tangents(BL::Mesh b_mesh, BL::MeshTextureFaceLayer b_la
static void create_mesh(Scene *scene, Mesh *mesh, BL::Mesh b_mesh, const vector<uint>& used_shaders)
{
/* create vertices */
/* count vertices and faces */
int numverts = b_mesh.vertices.length();
int numfaces = b_mesh.tessfaces.length();
int numtris = 0;
BL::Mesh::vertices_iterator v;
BL::Mesh::tessfaces_iterator f;
for(b_mesh.vertices.begin(v); v != b_mesh.vertices.end(); ++v)
mesh->verts.push_back(get_float3(v->co()));
for(b_mesh.tessfaces.begin(f); f != b_mesh.tessfaces.end(); ++f) {
int4 vi = get_int4(f->vertices_raw());
numtris += (vi[3] == 0)? 1: 2;
}
/* reserve memory */
mesh->reserve(numverts, numtris, 0, 0);
/* create vertex coordinates and normals */
int i = 0;
for(b_mesh.vertices.begin(v); v != b_mesh.vertices.end(); ++v, ++i)
mesh->verts[i] = get_float3(v->co());
/* create vertex normals */
Attribute *attr_N = mesh->attributes.add(ATTR_STD_VERTEX_NORMAL);
float3 *N = attr_N->data_float3();
@@ -226,10 +240,10 @@ static void create_mesh(Scene *scene, Mesh *mesh, BL::Mesh b_mesh, const vector<
*N = get_float3(v->normal());
/* create faces */
BL::Mesh::tessfaces_iterator f;
vector<int> nverts;
vector<int> nverts(numfaces);
int fi = 0, ti = 0;
for(b_mesh.tessfaces.begin(f); f != b_mesh.tessfaces.end(); ++f) {
for(b_mesh.tessfaces.begin(f); f != b_mesh.tessfaces.end(); ++f, ++fi) {
int4 vi = get_int4(f->vertices_raw());
int n = (vi[3] == 0)? 3: 4;
int mi = clamp(f->material_index(), 0, used_shaders.size()-1);
@@ -239,18 +253,18 @@ static void create_mesh(Scene *scene, Mesh *mesh, BL::Mesh b_mesh, const vector<
if(n == 4) {
if(len_squared(cross(mesh->verts[vi[1]] - mesh->verts[vi[0]], mesh->verts[vi[2]] - mesh->verts[vi[0]])) == 0.0f ||
len_squared(cross(mesh->verts[vi[2]] - mesh->verts[vi[0]], mesh->verts[vi[3]] - mesh->verts[vi[0]])) == 0.0f) {
mesh->add_triangle(vi[0], vi[1], vi[3], shader, smooth);
mesh->add_triangle(vi[2], vi[3], vi[1], shader, smooth);
mesh->set_triangle(ti++, vi[0], vi[1], vi[3], shader, smooth);
mesh->set_triangle(ti++, vi[2], vi[3], vi[1], shader, smooth);
}
else {
mesh->add_triangle(vi[0], vi[1], vi[2], shader, smooth);
mesh->add_triangle(vi[0], vi[2], vi[3], shader, smooth);
mesh->set_triangle(ti++, vi[0], vi[1], vi[2], shader, smooth);
mesh->set_triangle(ti++, vi[0], vi[2], vi[3], shader, smooth);
}
}
else
mesh->add_triangle(vi[0], vi[1], vi[2], shader, smooth);
mesh->set_triangle(ti++, vi[0], vi[1], vi[2], shader, smooth);
nverts.push_back(n);
nverts[fi] = n;
}
/* create vertex color attributes */

View File

@@ -127,6 +127,7 @@ private:
use_surfaces(true),
use_hair(true),
use_viewport_visibility(false),
use_localview(false),
samples(0), bound_samples(false)
{}

View File

@@ -359,12 +359,15 @@ void Film::device_update(Device *device, DeviceScene *dscene, Scene *scene)
case PASS_BACKGROUND:
kfilm->pass_background = kfilm->pass_stride;
kfilm->use_light_pass = 1;
break;
case PASS_AO:
kfilm->pass_ao = kfilm->pass_stride;
kfilm->use_light_pass = 1;
break;
case PASS_SHADOW:
kfilm->pass_shadow = kfilm->pass_stride;
kfilm->use_light_pass = 1;
break;
case PASS_NONE:
break;
}

View File

@@ -53,7 +53,7 @@ static void shade_background_pixels(Device *device, DeviceScene *dscene, int res
}
/* compute on device */
float4 *d_output_data = d_output.resize(width*height);
d_output.resize(width*height);
memset((void*)d_output.data_pointer, 0, d_output.memory_size());
device->const_copy_to("__data", &dscene->data, sizeof(dscene->data));
@@ -82,7 +82,7 @@ static void shade_background_pixels(Device *device, DeviceScene *dscene, int res
device->mem_free(d_input);
device->mem_free(d_output);
d_output_data = reinterpret_cast<float4*>(d_output.data_pointer);
float4 *d_output_data = reinterpret_cast<float4*>(d_output.data_pointer);
pixels.resize(width*height);

View File

@@ -98,6 +98,18 @@ void Mesh::clear()
transform_normal = transform_identity();
}
void Mesh::set_triangle(int i, int v0, int v1, int v2, int shader_, bool smooth_)
{
Triangle tri;
tri.v[0] = v0;
tri.v[1] = v1;
tri.v[2] = v2;
triangles[i] = tri;
shader[i] = shader_;
smooth[i] = smooth_;
}
void Mesh::add_triangle(int v0, int v1, int v2, int shader_, bool smooth_)
{
Triangle tri;

View File

@@ -110,6 +110,7 @@ public:
void reserve(int numverts, int numfaces, int numcurves, int numcurvekeys);
void clear();
void set_triangle(int i, int v0, int v1, int v2, int shader, bool smooth);
void add_triangle(int v0, int v1, int v2, int shader, bool smooth);
void add_curve_key(float3 loc, float radius);
void add_curve(int first_key, int num_keys, int shader);

View File

@@ -99,7 +99,7 @@ void LookupTables::remove_table(size_t offset)
for(table = lookup_tables.begin(); table != lookup_tables.end(); table++) {
if(table->offset == offset) {
lookup_tables.erase(table);
break;
return;
}
}

View File

@@ -4510,7 +4510,7 @@ void psys_get_dupli_texture(ParticleSystem *psys, ParticleSettings *part,
num = DMCACHE_NOTFOUND;
}
if (mtface && num != DMCACHE_NOTFOUND) {
if (mtface && !ELEM(num, DMCACHE_NOTFOUND, DMCACHE_ISCHILD)) {
mface = psmd->dm->getTessFaceData(psmd->dm, num, CD_MFACE);
mtface += num;
psys_interpolate_uvs(mtface, mface->v4, pa->fuv, uv);

View File

@@ -1660,17 +1660,22 @@ void psys_get_birth_coordinates(ParticleSimulationData *sim, ParticleData *pa, P
{
Object *ob = sim->ob;
ParticleSystem *psys = sim->psys;
ParticleSettings *part;
ParticleSettings *part = psys->part;
ParticleTexture ptex;
float fac, phasefac, nor[3] = {0,0,0},loc[3],vel[3] = {0.0,0.0,0.0},rot[4],q2[4];
float r_vel[3],r_ave[3],r_rot[4],vec[3],p_vel[3] = {0.0,0.0,0.0};
float x_vec[3] = {1.0,0.0,0.0}, utan[3] = {0.0,1.0,0.0}, vtan[3] = {0.0,0.0,1.0}, rot_vec[3] = {0.0,0.0,0.0};
float q_phase[4];
const bool use_boids = ((part->phystype == PART_PHYS_BOIDS) &&
(pa->boid != NULL));
const bool use_tangents = ((use_boids == false) &&
((part->tanfac != 0.0f) || (part->rotmode == PART_ROT_NOR_TAN)));
int p = pa - psys->particles;
part=psys->part;
/* get birth location from object */
if (part->tanfac != 0.f)
if (use_tangents)
psys_particle_on_emitter(sim->psmd, part->from,pa->num, pa->num_dmcache, pa->fuv,pa->foffset,loc,nor,utan,vtan,0,0);
else
psys_particle_on_emitter(sim->psmd, part->from,pa->num, pa->num_dmcache, pa->fuv,pa->foffset,loc,nor,0,0,0,0);
@@ -1688,7 +1693,7 @@ void psys_get_birth_coordinates(ParticleSimulationData *sim, ParticleData *pa, P
normalize_v3(nor);
/* -tangent */
if (part->tanfac!=0.0f) {
if (use_tangents) {
//float phase=vg_rot?2.0f*(psys_particle_value_from_verts(sim->psmd->dm,part->from,pa,vg_rot)-0.5f):0.0f;
float phase=0.0f;
mul_v3_fl(vtan,-cosf((float)M_PI*(part->tanphase+phase)));
@@ -1737,7 +1742,7 @@ void psys_get_birth_coordinates(ParticleSimulationData *sim, ParticleData *pa, P
mul_qt_qtqt(r_rot,r_rot,rot);
}
if (part->phystype==PART_PHYS_BOIDS && pa->boid) {
if (use_boids) {
float dvec[3], q[4], mat[3][3];
copy_v3_v3(state->co,loc);
@@ -1828,6 +1833,7 @@ void psys_get_birth_coordinates(ParticleSimulationData *sim, ParticleData *pa, P
/* create vector into which rotation is aligned */
switch (part->rotmode) {
case PART_ROT_NOR:
case PART_ROT_NOR_TAN:
copy_v3_v3(rot_vec, nor);
use_global_space = false;
break;
@@ -1853,10 +1859,10 @@ void psys_get_birth_coordinates(ParticleSimulationData *sim, ParticleData *pa, P
}
/* create rotation quat */
negate_v3(rot_vec);
if (use_global_space) {
/* calculate rotation in global-space */
negate_v3(rot_vec);
vec_to_quat(q2, rot_vec, OB_POSX, OB_POSZ);
/* randomize rotation quat */
@@ -1871,15 +1877,51 @@ void psys_get_birth_coordinates(ParticleSimulationData *sim, ParticleData *pa, P
/* calculate rotation in local-space */
float q_obmat[4];
float q_imat[4];
float tvec[3];
mat4_to_quat(q_obmat, ob->obmat);
invert_qt_qt(q_imat, q_obmat);
copy_v3_v3(tvec, rot_vec);
mul_qt_v3(q_imat, tvec);
normalize_v3(tvec);
vec_to_quat(q2, tvec, OB_POSX, OB_POSZ);
if (part->rotmode != PART_ROT_NOR_TAN) {
float rot_vec_local[3];
/* rot_vec */
negate_v3(rot_vec);
copy_v3_v3(rot_vec_local, rot_vec);
mul_qt_v3(q_imat, rot_vec_local);
normalize_v3(rot_vec_local);
vec_to_quat(q2, rot_vec_local, OB_POSX, OB_POSZ);
}
else {
/* (part->rotmode == PART_ROT_NOR_TAN) */
float tmat[3][3];
/* note: utan_local is not taken from 'utan', we calculate from rot_vec/vtan */
/* note: it looks like rotation phase may be applied twice (once with vtan, again below)
* however this isn't the case - campbell */
float *rot_vec_local = tmat[0];
float *vtan_local = tmat[1];
float *utan_local = tmat[2];
/* use tangents */
BLI_assert(use_tangents == true);
/* rot_vec */
copy_v3_v3(rot_vec_local, rot_vec);
mul_qt_v3(q_imat, rot_vec_local);
/* vtan_local */
copy_v3_v3(vtan_local, vtan); /* flips, cant use */
mul_qt_v3(q_imat, vtan_local);
/* ensure orthogonal matrix (rot_vec aligned) */
cross_v3_v3v3(utan_local, vtan_local, rot_vec_local);
cross_v3_v3v3(vtan_local, utan_local, rot_vec_local);
/* note: no need to normalize */
mat3_to_quat(q2, tmat);
}
/* randomize rotation quat */
if (part->randrotfac != 0.0f) {

View File

@@ -517,7 +517,7 @@ void ArmatureImporter::set_pose(Object *ob_arm, COLLADAFW::Node *root_node, con
// root - if this joint is the top joint in hierarchy, if a joint
// is a child of a node (not joint), root should be true since
// this is where we build armature bones from
void ArmatureImporter::add_joint(COLLADAFW::Node *node, bool root, Object *parent, Scene *sce)
void ArmatureImporter::add_joint(COLLADAFW::Node *node, bool root, Object *parent)
{
joint_by_uid[node->getUniqueId()] = node;
if (root) {

View File

@@ -140,7 +140,7 @@ public:
ArmatureImporter(UnitConverter *conv, MeshImporterBase *mesh, Scene *sce);
~ArmatureImporter();
void add_joint(COLLADAFW::Node *node, bool root, Object *parent, Scene *sce);
void add_joint(COLLADAFW::Node *node, bool root, Object *parent);
#if 0
void add_root_joint(COLLADAFW::Node *node);

View File

@@ -480,7 +480,7 @@ std::vector<Object *> *DocumentImporter::write_node(COLLADAFW::Node *node, COLLA
object_map.insert(std::pair<COLLADAFW::UniqueId, Object *>(node->getUniqueId(), par));
node_map[node->getUniqueId()] = node;
}
armature_importer.add_joint(node, parent_node == NULL || parent_node->getType() != COLLADAFW::Node::JOINT, par, sce);
armature_importer.add_joint(node, parent_node == NULL || parent_node->getType() != COLLADAFW::Node::JOINT, par);
if (parent_node == NULL) {
// for skeletons without root node all has been done above.
@@ -601,11 +601,16 @@ std::vector<Object *> *DocumentImporter::write_node(COLLADAFW::Node *node, COLLA
anim_importer.read_node_transform(node, ob); // overwrites location set earlier
if (!is_joint) {
// if par was given make this object child of the previous
if (par && ob)
bc_set_parent(ob, par, mContext);
if (par && ob) {
ob->parent = par;
ob->partype = PAROBJECT;
ob->parsubstr[0] = 0;
//bc_set_parent(ob, par, mContext, false);
}
}
}
// if node has child nodes write them
COLLADAFW::NodePointerArray &child_nodes = node->getChildNodes();
@@ -624,7 +629,7 @@ std::vector<Object *> *DocumentImporter::write_node(COLLADAFW::Node *node, COLLA
}
/** When this method is called, the writer must write the entire visual scene.
* \return The writer should return true, if writing succeeded, false otherwise.*/
* Return The writer should return true, if writing succeeded, false otherwise. */
bool DocumentImporter::writeVisualScene(const COLLADAFW::VisualScene *visualScene)
{
if (mImportStage != General)

View File

@@ -97,40 +97,28 @@ void TransformWriter::add_node_transform_ob(COLLADASW::Node& node, Object *ob, B
add_transform(node, loc, rot, scale);
#endif
UnitConverter converter;
/* Using parentinv should allow use of existing curves */
if (ob->parent) {
// If parentinv is identity don't add it.
bool add_parinv = false;
double d_obmat[4][4];
float f_obmat[4][4];
for (int i = 0; i < 16; ++i) {
float f = (i % 4 == i / 4) ? 1.0f : 0.0f;
add_parinv |= (ob->parentinv[i % 4][i / 4] != f);
}
if (add_parinv) {
double dmat[4][4];
converter.mat4_to_dae_double(dmat, ob->parentinv);
node.addMatrix("parentinverse", dmat);
}
}
double d_obmat[4][4];
converter.mat4_to_dae_double(d_obmat, ob->obmat);
/* Export the local Matrix (relative to the object parent) */
BKE_object_matrix_local_get(ob, f_obmat);
converter.mat4_to_dae_double(d_obmat, f_obmat);
switch (transformation_type) {
case BC_TRANSFORMATION_TYPE_MATRIX : {
node.addMatrix("transform",d_obmat);
break;
}
case BC_TRANSFORMATION_TYPE_TRANSROTLOC: {
add_transform(node, ob->loc, ob->rot, ob->size);
break;
}
case BC_TRANSFORMATION_TYPE_BOTH : {
node.addMatrix("transform",d_obmat);
add_transform(node, ob->loc, ob->rot, ob->size);
/* intentional fall-through */
}
case BC_TRANSFORMATION_TYPE_TRANSROTLOC: {
float loc[3], rot[3], scale[3];
TransformBase::decompose(f_obmat, loc, rot, NULL, scale);
add_transform(node, loc, rot, scale);
break;
}
}

View File

@@ -1204,7 +1204,8 @@ static char imtype_best_depth(ImBuf *ibuf, const char imtype)
}
}
static int save_image_options_init(SaveImageOptions *simopts, SpaceImage *sima, Scene *scene, const short guess_path)
static int save_image_options_init(SaveImageOptions *simopts, SpaceImage *sima, Scene *scene,
const bool guess_path, const bool save_as_render)
{
void *lock;
ImBuf *ibuf = ED_space_image_acquire_buffer(sima, &lock);
@@ -1253,8 +1254,20 @@ static int save_image_options_init(SaveImageOptions *simopts, SpaceImage *sima,
/* check for empty path */
if (guess_path && simopts->filepath[0] == 0) {
BLI_snprintf(simopts->filepath, sizeof(simopts->filepath), "//%s", ima->id.name + 2);
BLI_path_abs(simopts->filepath, STREQ(G.ima, "//") ? G.main->name : G.ima);
const bool is_prev_save = !STREQ(G.ima, "//");
if (save_as_render) {
if (is_prev_save) {
BLI_strncpy(simopts->filepath, G.ima, sizeof(simopts->filepath));
}
else {
BLI_strncpy(simopts->filepath, "//untitled", sizeof(simopts->filepath));
BLI_path_abs(simopts->filepath, G.main->name);
}
}
else {
BLI_snprintf(simopts->filepath, sizeof(simopts->filepath), "//%s", ima->id.name + 2);
BLI_path_abs(simopts->filepath, is_prev_save ? G.ima : G.main->name);
}
}
/* color management */
@@ -1425,7 +1438,7 @@ static int image_save_as_exec(bContext *C, wmOperator *op)
/* just in case to initialize values,
* these should be set on invoke or by the caller. */
save_image_options_init(&simopts, sima, CTX_data_scene(C), 0);
save_image_options_init(&simopts, sima, CTX_data_scene(C), false, false);
save_image_options_from_op(&simopts, op);
@@ -1448,13 +1461,14 @@ static int image_save_as_invoke(bContext *C, wmOperator *op, const wmEvent *UNUS
Image *ima = ED_space_image(sima);
Scene *scene = CTX_data_scene(C);
SaveImageOptions simopts;
const bool save_as_render = ((ima->source == IMA_SRC_VIEWER) || (ima->flag & IMA_VIEW_AS_RENDER));
if (RNA_struct_property_is_set(op->ptr, "filepath"))
return image_save_as_exec(C, op);
save_image_options_defaults(&simopts);
if (save_image_options_init(&simopts, sima, scene, TRUE) == 0)
if (save_image_options_init(&simopts, sima, scene, true, save_as_render) == 0)
return OPERATOR_CANCELLED;
save_image_options_to_op(&simopts, op);
@@ -1463,10 +1477,7 @@ static int image_save_as_invoke(bContext *C, wmOperator *op, const wmEvent *UNUS
RNA_boolean_set(op->ptr, "copy", TRUE);
}
if (ima->source == IMA_SRC_VIEWER || (ima->flag & IMA_VIEW_AS_RENDER))
RNA_boolean_set(op->ptr, "save_as_render", TRUE);
else
RNA_boolean_set(op->ptr, "save_as_render", FALSE);
RNA_boolean_set(op->ptr, "save_as_render", save_as_render);
op->customdata = MEM_mallocN(sizeof(simopts.im_format), __func__);
memcpy(op->customdata, &simopts.im_format, sizeof(simopts.im_format));
@@ -1565,7 +1576,7 @@ static int image_save_exec(bContext *C, wmOperator *op)
SaveImageOptions simopts;
save_image_options_defaults(&simopts);
if (save_image_options_init(&simopts, sima, scene, FALSE) == 0)
if (save_image_options_init(&simopts, sima, scene, false, false) == 0)
return OPERATOR_CANCELLED;
save_image_options_from_op(&simopts, op);

View File

@@ -473,6 +473,7 @@ typedef struct ParticleSystem {
#define PART_ROT_OB_X 6
#define PART_ROT_OB_Y 7
#define PART_ROT_OB_Z 8
#define PART_ROT_NOR_TAN 9
/* part->avemode */
#define PART_AVE_VELOCITY 1

View File

@@ -1887,6 +1887,7 @@ static void rna_def_particle_settings(BlenderRNA *brna)
static EnumPropertyItem rot_mode_items[] = {
{0, "NONE", 0, "None", ""},
{PART_ROT_NOR, "NOR", 0, "Normal", ""},
{PART_ROT_NOR_TAN, "NOR_TAN", 0, "Normal-Tangent", ""},
{PART_ROT_VEL, "VEL", 0, "Velocity / Hair", ""},
{PART_ROT_GLOB_X, "GLOB_X", 0, "Global X", ""},
{PART_ROT_GLOB_Y, "GLOB_Y", 0, "Global Y", ""},

View File

@@ -646,7 +646,7 @@ static DerivedMesh *applyModifier(ModifierData *md, Object *ob,
else {
/* only 1 edge connected - same as above except
* don't need to average edge direction */
if (vc->e && vc->e[0]->v2 == i) {
if (vc->e[0]->v2 == i) {
sub_v3_v3v3(tmp_vec1, mvert_new[i].co, mvert_new[vc->v[0]].co);
}
else {