forked from bartvdbraak/blender
Cycles Hair: add Generated texture coordinates for curves, so that procedural
textures now work without having to add a UV map. Also made UV and intercept attributes only export when needed by the shader.
This commit is contained in:
parent
bf25f1ea96
commit
b3f21a2254
@ -16,6 +16,7 @@
|
||||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include "attribute.h"
|
||||
#include "mesh.h"
|
||||
#include "object.h"
|
||||
#include "scene.h"
|
||||
@ -24,16 +25,8 @@
|
||||
#include "blender_sync.h"
|
||||
#include "blender_util.h"
|
||||
|
||||
#include "subd_mesh.h"
|
||||
#include "subd_patch.h"
|
||||
#include "subd_split.h"
|
||||
|
||||
#include "util_foreach.h"
|
||||
|
||||
#include "DNA_modifier_types.h"
|
||||
#include "DNA_particle_types.h"
|
||||
#include "DNA_meshdata_types.h"
|
||||
|
||||
CCL_NAMESPACE_BEGIN
|
||||
|
||||
/* Utilities */
|
||||
@ -650,7 +643,7 @@ void ExportCurveTriangleGeometry(Mesh *mesh, ParticleCurveData *CData, int inter
|
||||
/* texture coords still needed */
|
||||
}
|
||||
|
||||
void ExportCurveSegments(Mesh *mesh, ParticleCurveData *CData, int interpolation, int segments)
|
||||
void ExportCurveSegments(Scene *scene, Mesh *mesh, ParticleCurveData *CData, int interpolation, int segments)
|
||||
{
|
||||
int num_keys = 0;
|
||||
int num_curves = 0;
|
||||
@ -658,8 +651,12 @@ void ExportCurveSegments(Mesh *mesh, ParticleCurveData *CData, int interpolation
|
||||
if(!(mesh->curves.empty() && mesh->curve_keys.empty()))
|
||||
return;
|
||||
|
||||
Attribute *attr_uv = mesh->curve_attributes.add(ATTR_STD_UV);
|
||||
Attribute *attr_intercept = mesh->curve_attributes.add(ATTR_STD_CURVE_INTERCEPT);
|
||||
Attribute *attr_uv = NULL, *attr_intercept = NULL;
|
||||
|
||||
if(mesh->need_attribute(scene, ATTR_STD_UV))
|
||||
attr_uv = mesh->curve_attributes.add(ATTR_STD_UV);
|
||||
if(mesh->need_attribute(scene, ATTR_STD_CURVE_INTERCEPT))
|
||||
attr_intercept = mesh->curve_attributes.add(ATTR_STD_CURVE_INTERCEPT);
|
||||
|
||||
for( int sys = 0; sys < CData->psys_firstcurve.size() ; sys++) {
|
||||
|
||||
@ -695,6 +692,7 @@ void ExportCurveSegments(Mesh *mesh, ParticleCurveData *CData, int interpolation
|
||||
radius =0.0f;
|
||||
|
||||
mesh->add_curve_key(ickey_loc, radius);
|
||||
if(attr_intercept)
|
||||
attr_intercept->add(time);
|
||||
|
||||
num_curve_keys++;
|
||||
@ -702,6 +700,7 @@ void ExportCurveSegments(Mesh *mesh, ParticleCurveData *CData, int interpolation
|
||||
}
|
||||
|
||||
mesh->add_curve(num_keys, num_curve_keys, CData->psys_shader[sys]);
|
||||
if(attr_uv)
|
||||
attr_uv->add(CData->curve_uv[curve]);
|
||||
|
||||
num_keys += num_curve_keys;
|
||||
@ -871,7 +870,7 @@ void BlenderSync::sync_curves(Mesh *mesh, BL::Mesh b_mesh, BL::Object b_ob, bool
|
||||
ExportCurveTriangleGeometry(mesh, &CData, interpolation, use_smooth, resolution, segments);
|
||||
}
|
||||
else {
|
||||
ExportCurveSegments(mesh, &CData, interpolation, segments);
|
||||
ExportCurveSegments(scene, mesh, &CData, interpolation, segments);
|
||||
int ckey_num = mesh->curve_keys.size();
|
||||
|
||||
/*export tangents or curve data? - not functional yet*/
|
||||
@ -886,6 +885,22 @@ void BlenderSync::sync_curves(Mesh *mesh, BL::Mesh b_mesh, BL::Object b_ob, bool
|
||||
data_tangent[ck] = tg;
|
||||
}
|
||||
}
|
||||
|
||||
/* generated coordinates from first key. we should ideally get this from
|
||||
* blender to handle deforming objects */
|
||||
if(mesh->need_attribute(scene, ATTR_STD_GENERATED)) {
|
||||
float3 loc, size;
|
||||
mesh_texture_space(b_mesh, loc, size);
|
||||
|
||||
Attribute *attr_generated = mesh->curve_attributes.add(ATTR_STD_GENERATED);
|
||||
float3 *generated = attr_generated->data_float3();
|
||||
size_t i = 0;
|
||||
|
||||
foreach(Mesh::Curve& curve, mesh->curves) {
|
||||
float3 co = mesh->curve_keys[curve.first_key].co;
|
||||
generated[i++] = co*size - loc;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
mesh->compute_bounds();
|
||||
|
@ -328,14 +328,9 @@ static void create_mesh(Scene *scene, Mesh *mesh, BL::Mesh b_mesh, const vector<
|
||||
* is available in the api. */
|
||||
if(mesh->need_attribute(scene, ATTR_STD_GENERATED)) {
|
||||
Attribute *attr = mesh->attributes.add(ATTR_STD_GENERATED);
|
||||
float3 loc = get_float3(b_mesh.texspace_location());
|
||||
float3 size = get_float3(b_mesh.texspace_size());
|
||||
|
||||
if(size.x != 0.0f) size.x = 0.5f/size.x;
|
||||
if(size.y != 0.0f) size.y = 0.5f/size.y;
|
||||
if(size.z != 0.0f) size.z = 0.5f/size.z;
|
||||
|
||||
loc = loc*size - make_float3(0.5f, 0.5f, 0.5f);
|
||||
float3 loc, size;
|
||||
mesh_texture_space(b_mesh, loc, size);
|
||||
|
||||
float3 *generated = attr->data_float3();
|
||||
size_t i = 0;
|
||||
|
@ -242,6 +242,20 @@ static inline string blender_absolute_path(BL::BlendData b_data, BL::ID b_id, co
|
||||
return path;
|
||||
}
|
||||
|
||||
/* Texture Space */
|
||||
|
||||
static inline void mesh_texture_space(BL::Mesh b_mesh, float3& loc, float3& size)
|
||||
{
|
||||
loc = get_float3(b_mesh.texspace_location());
|
||||
size = get_float3(b_mesh.texspace_size());
|
||||
|
||||
if(size.x != 0.0f) size.x = 0.5f/size.x;
|
||||
if(size.y != 0.0f) size.y = 0.5f/size.y;
|
||||
if(size.z != 0.0f) size.z = 0.5f/size.z;
|
||||
|
||||
loc = loc*size - make_float3(0.5f, 0.5f, 0.5f);
|
||||
}
|
||||
|
||||
/* ID Map
|
||||
*
|
||||
* Utility class to keep in sync with blender data.
|
||||
|
Loading…
Reference in New Issue
Block a user