forked from blender/blender
Export curves #46
@ -575,6 +575,10 @@ void BlenderSceneDelegate::remove_unused_objects()
|
||||
if (m_data) {
|
||||
m_data->available_materials(available_materials);
|
||||
}
|
||||
CurvesData *c_data = dynamic_cast<CurvesData *>(it.second.get());
|
||||
if (c_data) {
|
||||
c_data->available_materials(available_materials);
|
||||
}
|
||||
}
|
||||
for (auto &it : instancers_) {
|
||||
it.second->available_materials(available_materials);
|
||||
|
@ -26,6 +26,7 @@ class Engine;
|
||||
|
||||
class BlenderSceneDelegate : public pxr::HdSceneDelegate {
|
||||
friend ObjectData; /* has access to instances */
|
||||
friend CurvesData; /* has access to curves */
|
||||
friend MeshData; /* has access to materials */
|
||||
friend MaterialData; /* has access to objects and instancers */
|
||||
|
||||
|
@ -51,7 +51,6 @@ void CurvesData::update()
|
||||
init();
|
||||
bits = pxr::HdChangeTracker::AllDirty;
|
||||
}
|
||||
|
||||
if (id->recalc & ID_RECALC_SHADING) {
|
||||
write_material();
|
||||
bits |= pxr::HdChangeTracker::DirtyMaterialId | pxr::HdChangeTracker::DirtyDoubleSided;
|
||||
@ -75,9 +74,6 @@ pxr::VtValue CurvesData::get_data(pxr::SdfPath const &id, pxr::TfToken const &ke
|
||||
if (key == pxr::HdTokens->points) {
|
||||
ret = vertices_;
|
||||
}
|
||||
else if (key == pxr::HdTokens->normals) {
|
||||
ret = normals_;
|
||||
}
|
||||
else if (key == pxr::HdPrimvarRoleTokens->textureCoordinate) {
|
||||
ret = uvs_;
|
||||
}
|
||||
@ -117,10 +113,6 @@ pxr::HdPrimvarDescriptorVector CurvesData::primvar_descriptors(
|
||||
}
|
||||
}
|
||||
else if (interpolation == pxr::HdInterpolationFaceVarying) {
|
||||
if (!normals_.empty()) {
|
||||
primvars.emplace_back(
|
||||
pxr::HdTokens->normals, interpolation, pxr::HdPrimvarRoleTokens->normal);
|
||||
}
|
||||
if (!uvs_.empty()) {
|
||||
primvars.emplace_back(pxr::HdPrimvarRoleTokens->textureCoordinate,
|
||||
interpolation,
|
||||
@ -158,19 +150,23 @@ void CurvesData::update_double_sided(MaterialData *mat_data)
|
||||
}
|
||||
}
|
||||
|
||||
void CurvesData::available_materials(std::set<pxr::SdfPath> &paths) const
|
||||
{
|
||||
if (mat_data_ && !mat_data_->prim_id.IsEmpty()) {
|
||||
paths.insert(mat_data_->prim_id);
|
||||
}
|
||||
}
|
||||
|
||||
void CurvesData::write_curves(Curves *curves)
|
||||
{
|
||||
curve_vertex_counts_.clear();
|
||||
width_.clear();
|
||||
vertices_.clear();
|
||||
uvs_.clear();
|
||||
|
||||
const float *radii = (const float *)CustomData_get_layer_named(
|
||||
&curves->geometry.point_data, CD_PROP_FLOAT, "radius");
|
||||
const float(*positions)[3] = (const float(*)[3])CustomData_get_layer_named(
|
||||
&curves->geometry.point_data, CD_PROP_FLOAT3, "position");
|
||||
const float(*uvs)[2] = (const float(*)[2])CustomData_get_layer_named(
|
||||
&curves->geometry.curve_data, CD_PROP_FLOAT2, "surface_uv_coordinate");
|
||||
|
||||
vertices_.reserve(curves->geometry.curve_num);
|
||||
|
||||
@ -179,36 +175,53 @@ void CurvesData::write_curves(Curves *curves)
|
||||
const int num_points = *(curves->geometry.curve_offsets + i + 1) -
|
||||
*(curves->geometry.curve_offsets + i);
|
||||
curve_vertex_counts_.push_back(num_points);
|
||||
width_.push_back(0.005f);
|
||||
|
||||
/* Set radius similar to Cycles if isn't set */
|
||||
float radius = radii ? radii[i] : 0.01f;
|
||||
width_.push_back(radius);
|
||||
|
||||
for (int j = 0; j < num_points; j++) {
|
||||
const int index = first_point_index + j;
|
||||
vertices_.push_back(
|
||||
pxr::GfVec3f(positions[index][0], positions[index][1], positions[index][2]));
|
||||
uvs_.push_back(pxr::GfVec2f(uvs[index][0], uvs[index][1]));
|
||||
}
|
||||
}
|
||||
|
||||
write_uv_maps(curves);
|
||||
}
|
||||
|
||||
void CurvesData::write_uv_maps(Curves *curves)
|
||||
{
|
||||
uvs_.clear();
|
||||
|
||||
const float(*uvs)[2] = (const float(*)[2])CustomData_get_layer_named(
|
||||
&curves->geometry.curve_data, CD_PROP_FLOAT2, "surface_uv_coordinate");
|
||||
|
||||
for (int i = 0; i < curves->geometry.curve_num; i++) {
|
||||
uvs_.push_back(pxr::GfVec2f(uvs[i][0], uvs[i][1]));
|
||||
}
|
||||
}
|
||||
|
||||
void CurvesData::write_material()
|
||||
{
|
||||
//Object *object = (Object *)id;
|
||||
//for (int i = 0; i < submeshes_.size(); ++i) {
|
||||
// SubMesh &m = submeshes_[i];
|
||||
// Material *mat = BKE_object_material_get_eval(object, m.mat_index + 1);
|
||||
// if (!mat) {
|
||||
// m.mat_data = nullptr;
|
||||
// continue;
|
||||
// }
|
||||
// pxr::SdfPath p_id = scene_delegate_->material_prim_id(mat);
|
||||
// m.mat_data = scene_delegate_->material_data(p_id);
|
||||
// if (!m.mat_data) {
|
||||
// scene_delegate_->materials_[p_id] = std::make_unique<MaterialData>(
|
||||
// scene_delegate_, mat, p_id);
|
||||
// m.mat_data = scene_delegate_->material_data(p_id);
|
||||
// m.mat_data->init();
|
||||
// m.mat_data->insert();
|
||||
// }
|
||||
//}
|
||||
Object *object = (Object *)id;
|
||||
Material *mat = nullptr;
|
||||
if (BKE_object_material_count_eval(object) > 0) {
|
||||
mat = BKE_object_material_get_eval(object, object->actcol);
|
||||
}
|
||||
|
||||
if (!mat) {
|
||||
mat_data_ = nullptr;
|
||||
return;
|
||||
}
|
||||
pxr::SdfPath p_id = scene_delegate_->material_prim_id(mat);
|
||||
mat_data_ = scene_delegate_->material_data(p_id);
|
||||
if (!mat_data_) {
|
||||
scene_delegate_->materials_[p_id] = std::make_unique<MaterialData>(scene_delegate_, mat, p_id);
|
||||
mat_data_ = scene_delegate_->material_data(p_id);
|
||||
mat_data_->init();
|
||||
mat_data_->insert();
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace blender::render::hydra
|
||||
|
@ -31,21 +31,18 @@ class CurvesData : public ObjectData {
|
||||
pxr::SdfPath material_id() const;
|
||||
bool double_sided(pxr::SdfPath const &id) const;
|
||||
void update_double_sided(MaterialData *mat_data);
|
||||
void available_materials(std::set<pxr::SdfPath> &paths) const;
|
||||
|
||||
pxr::HdCullStyle cull_style = pxr::HdCullStyleBackUnlessDoubleSided;
|
||||
|
||||
private:
|
||||
void write_curves(Curves *curves);
|
||||
void write_material();
|
||||
void write_uv_maps(Curves *curves);
|
||||
void write_normals(Curves *curves);
|
||||
void write_material();
|
||||
|
||||
pxr::VtIntArray curve_vertex_counts_;
|
||||
pxr::VtIntArray face_vertex_indices_;
|
||||
pxr::VtVec3fArray vertices_;
|
||||
pxr::VtVec3fArray positions_;
|
||||
pxr::VtVec2fArray uvs_;
|
||||
pxr::VtVec3fArray normals_;
|
||||
pxr::VtFloatArray width_;
|
||||
|
||||
MaterialData *mat_data_ = nullptr;
|
||||
|
@ -65,6 +65,10 @@ void MaterialData::update()
|
||||
if (m_data) {
|
||||
m_data->update_double_sided(this);
|
||||
}
|
||||
CurvesData *c_data = dynamic_cast<CurvesData *>(it.second.get());
|
||||
if (c_data) {
|
||||
c_data->update_double_sided(this);
|
||||
}
|
||||
}
|
||||
for (auto &it : scene_delegate_->instancers_) {
|
||||
it.second->update_double_sided(this);
|
||||
|
Loading…
Reference in New Issue
Block a user