2011-04-27 11:58:34 +00:00
|
|
|
/*
|
2013-08-18 14:16:15 +00:00
|
|
|
* Copyright 2011-2013 Blender Foundation
|
2011-04-27 11:58:34 +00:00
|
|
|
*
|
2013-08-18 14:16:15 +00:00
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
2011-04-27 11:58:34 +00:00
|
|
|
*
|
2013-08-18 14:16:15 +00:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2011-04-27 11:58:34 +00:00
|
|
|
*
|
2013-08-18 14:16:15 +00:00
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
2014-12-25 01:50:24 +00:00
|
|
|
* limitations under the License.
|
2011-04-27 11:58:34 +00:00
|
|
|
*/
|
|
|
|
|
2014-03-29 12:03:48 +00:00
|
|
|
#include "image.h"
|
2011-04-27 11:58:34 +00:00
|
|
|
#include "mesh.h"
|
|
|
|
#include "attribute.h"
|
|
|
|
|
|
|
|
#include "util_debug.h"
|
|
|
|
#include "util_foreach.h"
|
2013-12-31 16:33:55 +00:00
|
|
|
#include "util_transform.h"
|
2011-04-27 11:58:34 +00:00
|
|
|
|
|
|
|
CCL_NAMESPACE_BEGIN
|
|
|
|
|
|
|
|
/* Attribute */
|
|
|
|
|
2014-03-29 12:03:48 +00:00
|
|
|
Attribute::~Attribute()
|
|
|
|
{
|
|
|
|
/* for voxel data, we need to remove the image from the image manager */
|
|
|
|
if(element == ATTR_ELEMENT_VOXEL) {
|
|
|
|
VoxelAttribute *voxel_data = data_voxel();
|
|
|
|
|
2016-02-17 10:43:03 +00:00
|
|
|
if(voxel_data && voxel_data->slot != -1) {
|
2014-03-29 12:03:48 +00:00
|
|
|
voxel_data->manager->remove_image(voxel_data->slot);
|
2016-02-17 10:43:03 +00:00
|
|
|
}
|
2014-03-29 12:03:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-03 12:08:54 +00:00
|
|
|
void Attribute::set(ustring name_, TypeDesc type_, AttributeElement element_)
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
|
|
|
name = name_;
|
|
|
|
type = type_;
|
|
|
|
element = element_;
|
2012-04-30 12:49:26 +00:00
|
|
|
std = ATTR_STD_NONE;
|
2016-07-17 02:57:06 +00:00
|
|
|
flags = 0;
|
2011-04-27 11:58:34 +00:00
|
|
|
|
|
|
|
/* string and matrix not supported! */
|
|
|
|
assert(type == TypeDesc::TypeFloat || type == TypeDesc::TypeColor ||
|
|
|
|
type == TypeDesc::TypePoint || type == TypeDesc::TypeVector ||
|
2013-12-31 16:33:55 +00:00
|
|
|
type == TypeDesc::TypeNormal || type == TypeDesc::TypeMatrix);
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
2016-07-16 23:42:28 +00:00
|
|
|
void Attribute::resize(Mesh *mesh, AttributePrimitive prim, bool reserve_only)
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
2016-05-07 22:09:08 +00:00
|
|
|
if(reserve_only) {
|
2016-07-16 23:42:28 +00:00
|
|
|
buffer.reserve(buffer_size(mesh, prim));
|
2014-03-29 12:03:46 +00:00
|
|
|
}
|
|
|
|
else {
|
2016-07-16 23:42:28 +00:00
|
|
|
buffer.resize(buffer_size(mesh, prim), 0);
|
2014-03-29 12:03:46 +00:00
|
|
|
}
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
2016-07-17 02:57:06 +00:00
|
|
|
void Attribute::resize(size_t num_elements)
|
|
|
|
{
|
|
|
|
buffer.resize(num_elements * data_sizeof(), 0);
|
|
|
|
}
|
|
|
|
|
2013-01-03 12:08:54 +00:00
|
|
|
void Attribute::add(const float& f)
|
|
|
|
{
|
|
|
|
char *data = (char*)&f;
|
|
|
|
size_t size = sizeof(f);
|
|
|
|
|
|
|
|
for(size_t i = 0; i < size; i++)
|
|
|
|
buffer.push_back(data[i]);
|
|
|
|
}
|
|
|
|
|
2014-06-13 21:40:39 +00:00
|
|
|
void Attribute::add(const uchar4& f)
|
|
|
|
{
|
|
|
|
char *data = (char*)&f;
|
|
|
|
size_t size = sizeof(f);
|
|
|
|
|
|
|
|
for(size_t i = 0; i < size; i++)
|
|
|
|
buffer.push_back(data[i]);
|
|
|
|
}
|
|
|
|
|
2013-01-03 12:08:54 +00:00
|
|
|
void Attribute::add(const float3& f)
|
|
|
|
{
|
|
|
|
char *data = (char*)&f;
|
|
|
|
size_t size = sizeof(f);
|
|
|
|
|
|
|
|
for(size_t i = 0; i < size; i++)
|
|
|
|
buffer.push_back(data[i]);
|
|
|
|
}
|
|
|
|
|
2013-12-31 16:33:55 +00:00
|
|
|
void Attribute::add(const Transform& f)
|
|
|
|
{
|
|
|
|
char *data = (char*)&f;
|
|
|
|
size_t size = sizeof(f);
|
|
|
|
|
|
|
|
for(size_t i = 0; i < size; i++)
|
|
|
|
buffer.push_back(data[i]);
|
|
|
|
}
|
|
|
|
|
2014-03-29 12:03:48 +00:00
|
|
|
void Attribute::add(const VoxelAttribute& f)
|
|
|
|
{
|
|
|
|
char *data = (char*)&f;
|
|
|
|
size_t size = sizeof(f);
|
|
|
|
|
|
|
|
for(size_t i = 0; i < size; i++)
|
|
|
|
buffer.push_back(data[i]);
|
|
|
|
}
|
|
|
|
|
2014-04-13 10:51:06 +00:00
|
|
|
void Attribute::add(const char *data)
|
|
|
|
{
|
|
|
|
size_t size = data_sizeof();
|
|
|
|
|
|
|
|
for(size_t i = 0; i < size; i++)
|
|
|
|
buffer.push_back(data[i]);
|
|
|
|
}
|
|
|
|
|
2013-01-03 12:08:54 +00:00
|
|
|
size_t Attribute::data_sizeof() const
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
2014-03-29 12:03:48 +00:00
|
|
|
if(element == ATTR_ELEMENT_VOXEL)
|
|
|
|
return sizeof(VoxelAttribute);
|
2016-07-16 23:42:28 +00:00
|
|
|
else if(element == ATTR_ELEMENT_CORNER_BYTE)
|
|
|
|
return sizeof(uchar4);
|
2014-03-29 12:03:48 +00:00
|
|
|
else if(type == TypeDesc::TypeFloat)
|
2011-05-31 11:31:00 +00:00
|
|
|
return sizeof(float);
|
2013-12-31 16:33:55 +00:00
|
|
|
else if(type == TypeDesc::TypeMatrix)
|
|
|
|
return sizeof(Transform);
|
2011-05-31 11:31:00 +00:00
|
|
|
else
|
|
|
|
return sizeof(float3);
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
2016-07-16 23:42:28 +00:00
|
|
|
size_t Attribute::element_size(Mesh *mesh, AttributePrimitive prim) const
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
2016-07-17 02:57:06 +00:00
|
|
|
if(flags & ATTR_FINAL_SIZE) {
|
|
|
|
return buffer.size() / data_sizeof();
|
|
|
|
}
|
|
|
|
|
2013-04-05 17:03:59 +00:00
|
|
|
size_t size;
|
2016-07-16 23:42:28 +00:00
|
|
|
|
2013-04-05 17:03:59 +00:00
|
|
|
switch(element) {
|
2013-12-31 16:33:55 +00:00
|
|
|
case ATTR_ELEMENT_OBJECT:
|
|
|
|
case ATTR_ELEMENT_MESH:
|
2014-03-29 12:03:48 +00:00
|
|
|
case ATTR_ELEMENT_VOXEL:
|
2013-04-05 17:03:59 +00:00
|
|
|
size = 1;
|
|
|
|
break;
|
|
|
|
case ATTR_ELEMENT_VERTEX:
|
2016-07-16 23:42:28 +00:00
|
|
|
size = mesh->verts.size() + mesh->num_ngons;
|
|
|
|
if(prim == ATTR_PRIM_SUBD) {
|
|
|
|
size -= mesh->num_subd_verts;
|
|
|
|
}
|
2013-04-05 17:03:59 +00:00
|
|
|
break;
|
2014-03-29 12:03:46 +00:00
|
|
|
case ATTR_ELEMENT_VERTEX_MOTION:
|
2016-07-16 23:42:28 +00:00
|
|
|
size = (mesh->verts.size() + mesh->num_ngons) * (mesh->motion_steps - 1);
|
|
|
|
if(prim == ATTR_PRIM_SUBD) {
|
|
|
|
size -= mesh->num_subd_verts * (mesh->motion_steps - 1);
|
|
|
|
}
|
2014-03-29 12:03:46 +00:00
|
|
|
break;
|
2013-04-05 17:03:59 +00:00
|
|
|
case ATTR_ELEMENT_FACE:
|
2016-07-16 23:42:28 +00:00
|
|
|
if(prim == ATTR_PRIM_TRIANGLE) {
|
|
|
|
size = mesh->num_triangles();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
size = mesh->subd_faces.size() + mesh->num_ngons;
|
|
|
|
}
|
2013-04-05 17:03:59 +00:00
|
|
|
break;
|
|
|
|
case ATTR_ELEMENT_CORNER:
|
2014-06-13 21:40:39 +00:00
|
|
|
case ATTR_ELEMENT_CORNER_BYTE:
|
2016-07-16 23:42:28 +00:00
|
|
|
if(prim == ATTR_PRIM_TRIANGLE) {
|
|
|
|
size = mesh->num_triangles()*3;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
size = mesh->subd_face_corners.size() + mesh->num_ngons;
|
|
|
|
}
|
2013-04-05 17:03:59 +00:00
|
|
|
break;
|
|
|
|
case ATTR_ELEMENT_CURVE:
|
2016-07-16 23:42:28 +00:00
|
|
|
size = mesh->num_curves();
|
2013-04-05 17:03:59 +00:00
|
|
|
break;
|
|
|
|
case ATTR_ELEMENT_CURVE_KEY:
|
2016-07-16 23:42:28 +00:00
|
|
|
size = mesh->curve_keys.size();
|
2013-04-05 17:03:59 +00:00
|
|
|
break;
|
2014-03-29 12:03:46 +00:00
|
|
|
case ATTR_ELEMENT_CURVE_KEY_MOTION:
|
2016-07-16 23:42:28 +00:00
|
|
|
size = mesh->curve_keys.size() * (mesh->motion_steps - 1);
|
2014-03-29 12:03:46 +00:00
|
|
|
break;
|
2013-04-05 17:03:59 +00:00
|
|
|
default:
|
|
|
|
size = 0;
|
|
|
|
break;
|
|
|
|
}
|
2016-07-16 23:42:28 +00:00
|
|
|
|
2013-04-05 17:03:59 +00:00
|
|
|
return size;
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
2016-07-16 23:42:28 +00:00
|
|
|
size_t Attribute::buffer_size(Mesh *mesh, AttributePrimitive prim) const
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
2016-07-16 23:42:28 +00:00
|
|
|
return element_size(mesh, prim)*data_sizeof();
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool Attribute::same_storage(TypeDesc a, TypeDesc b)
|
|
|
|
{
|
|
|
|
if(a == b)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
if(a == TypeDesc::TypeColor || a == TypeDesc::TypePoint ||
|
|
|
|
a == TypeDesc::TypeVector || a == TypeDesc::TypeNormal)
|
2012-06-09 18:56:12 +00:00
|
|
|
{
|
2011-04-27 11:58:34 +00:00
|
|
|
if(b == TypeDesc::TypeColor || b == TypeDesc::TypePoint ||
|
|
|
|
b == TypeDesc::TypeVector || b == TypeDesc::TypeNormal)
|
2012-06-09 18:56:12 +00:00
|
|
|
{
|
2011-04-27 11:58:34 +00:00
|
|
|
return true;
|
2012-06-09 18:56:12 +00:00
|
|
|
}
|
|
|
|
}
|
2011-04-27 11:58:34 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-07-16 23:42:28 +00:00
|
|
|
void Attribute::zero_data(void* dst)
|
|
|
|
{
|
|
|
|
memset(dst, 0, data_sizeof());
|
|
|
|
}
|
|
|
|
|
|
|
|
void Attribute::add_with_weight(void* dst, void* src, float weight)
|
|
|
|
{
|
|
|
|
if(element == ATTR_ELEMENT_CORNER_BYTE) {
|
|
|
|
for(int i = 0; i < 4; i++) {
|
|
|
|
((uchar*)dst)[i] += uchar(((uchar*)src)[i] * weight);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if(same_storage(type, TypeDesc::TypeFloat)) {
|
|
|
|
*((float*)dst) += *((float*)src) * weight;
|
|
|
|
}
|
|
|
|
else if(same_storage(type, TypeDesc::TypeVector)) {
|
|
|
|
*((float4*)dst) += *((float4*)src) * weight;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
assert(!"not implemented for this type");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-03 12:08:54 +00:00
|
|
|
const char *Attribute::standard_name(AttributeStandard std)
|
|
|
|
{
|
2014-03-29 12:03:48 +00:00
|
|
|
switch(std) {
|
|
|
|
case ATTR_STD_VERTEX_NORMAL:
|
|
|
|
return "N";
|
|
|
|
case ATTR_STD_FACE_NORMAL:
|
|
|
|
return "Ng";
|
|
|
|
case ATTR_STD_UV:
|
|
|
|
return "uv";
|
|
|
|
case ATTR_STD_GENERATED:
|
|
|
|
return "generated";
|
|
|
|
case ATTR_STD_GENERATED_TRANSFORM:
|
|
|
|
return "generated_transform";
|
|
|
|
case ATTR_STD_UV_TANGENT:
|
|
|
|
return "tangent";
|
|
|
|
case ATTR_STD_UV_TANGENT_SIGN:
|
|
|
|
return "tangent_sign";
|
|
|
|
case ATTR_STD_POSITION_UNDEFORMED:
|
|
|
|
return "undeformed";
|
|
|
|
case ATTR_STD_POSITION_UNDISPLACED:
|
|
|
|
return "undisplaced";
|
|
|
|
case ATTR_STD_MOTION_VERTEX_POSITION:
|
|
|
|
return "motion_P";
|
|
|
|
case ATTR_STD_MOTION_VERTEX_NORMAL:
|
|
|
|
return "motion_N";
|
|
|
|
case ATTR_STD_PARTICLE:
|
|
|
|
return "particle";
|
|
|
|
case ATTR_STD_CURVE_INTERCEPT:
|
|
|
|
return "curve_intercept";
|
|
|
|
case ATTR_STD_PTEX_FACE_ID:
|
|
|
|
return "ptex_face_id";
|
|
|
|
case ATTR_STD_PTEX_UV:
|
|
|
|
return "ptex_uv";
|
2014-03-29 12:03:48 +00:00
|
|
|
case ATTR_STD_VOLUME_DENSITY:
|
|
|
|
return "density";
|
|
|
|
case ATTR_STD_VOLUME_COLOR:
|
|
|
|
return "color";
|
|
|
|
case ATTR_STD_VOLUME_FLAME:
|
|
|
|
return "flame";
|
|
|
|
case ATTR_STD_VOLUME_HEAT:
|
|
|
|
return "heat";
|
|
|
|
case ATTR_STD_VOLUME_VELOCITY:
|
|
|
|
return "velocity";
|
2015-02-06 07:35:46 +00:00
|
|
|
case ATTR_STD_POINTINESS:
|
|
|
|
return "pointiness";
|
2014-03-29 12:03:48 +00:00
|
|
|
case ATTR_STD_NOT_FOUND:
|
|
|
|
case ATTR_STD_NONE:
|
|
|
|
case ATTR_STD_NUM:
|
|
|
|
return "";
|
|
|
|
}
|
2013-01-03 12:08:54 +00:00
|
|
|
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
2014-03-29 12:03:48 +00:00
|
|
|
AttributeStandard Attribute::name_standard(const char *name)
|
|
|
|
{
|
2014-03-29 14:56:29 +00:00
|
|
|
for(int std = ATTR_STD_NONE; std < ATTR_STD_NUM; std++)
|
|
|
|
if(strcmp(name, Attribute::standard_name((AttributeStandard)std)) == 0)
|
|
|
|
return (AttributeStandard)std;
|
2014-03-29 12:03:48 +00:00
|
|
|
|
|
|
|
return ATTR_STD_NONE;
|
|
|
|
}
|
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
/* Attribute Set */
|
|
|
|
|
2012-02-28 16:45:01 +00:00
|
|
|
AttributeSet::AttributeSet()
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
2013-01-03 12:08:54 +00:00
|
|
|
triangle_mesh = NULL;
|
|
|
|
curve_mesh = NULL;
|
2016-07-16 23:42:28 +00:00
|
|
|
subd_mesh = NULL;
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
AttributeSet::~AttributeSet()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2016-05-07 22:09:08 +00:00
|
|
|
Attribute *AttributeSet::add(ustring name, TypeDesc type, AttributeElement element)
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
|
|
|
Attribute *attr = find(name);
|
|
|
|
|
|
|
|
if(attr) {
|
|
|
|
/* return if same already exists */
|
|
|
|
if(attr->type == type && attr->element == element)
|
|
|
|
return attr;
|
|
|
|
|
|
|
|
/* overwrite attribute with same name but different type/element */
|
|
|
|
remove(name);
|
|
|
|
}
|
|
|
|
|
2014-05-21 05:37:18 +00:00
|
|
|
#if __cplusplus >= 201103L
|
|
|
|
attributes.emplace_back();
|
2011-04-27 11:58:34 +00:00
|
|
|
attr = &attributes.back();
|
2013-01-03 12:08:54 +00:00
|
|
|
attr->set(name, type, element);
|
2014-05-21 05:37:18 +00:00
|
|
|
#else
|
|
|
|
{
|
|
|
|
Attribute attr_temp;
|
|
|
|
attr_temp.set(name, type, element);
|
|
|
|
attributes.push_back(attr_temp);
|
|
|
|
attr = &attributes.back();
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2013-01-03 12:08:54 +00:00
|
|
|
/* this is weak .. */
|
|
|
|
if(triangle_mesh)
|
2016-07-16 23:42:28 +00:00
|
|
|
attr->resize(triangle_mesh, ATTR_PRIM_TRIANGLE, false);
|
2013-01-03 12:08:54 +00:00
|
|
|
if(curve_mesh)
|
2016-07-16 23:42:28 +00:00
|
|
|
attr->resize(curve_mesh, ATTR_PRIM_CURVE, false);
|
|
|
|
if(subd_mesh)
|
|
|
|
attr->resize(subd_mesh, ATTR_PRIM_SUBD, false);
|
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
return attr;
|
|
|
|
}
|
|
|
|
|
2013-01-03 12:08:54 +00:00
|
|
|
Attribute *AttributeSet::find(ustring name) const
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
2013-01-03 12:08:54 +00:00
|
|
|
foreach(const Attribute& attr, attributes)
|
2011-04-27 11:58:34 +00:00
|
|
|
if(attr.name == name)
|
2013-01-03 12:08:54 +00:00
|
|
|
return (Attribute*)&attr;
|
2011-04-27 11:58:34 +00:00
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void AttributeSet::remove(ustring name)
|
|
|
|
{
|
|
|
|
Attribute *attr = find(name);
|
|
|
|
|
|
|
|
if(attr) {
|
|
|
|
list<Attribute>::iterator it;
|
|
|
|
|
|
|
|
for(it = attributes.begin(); it != attributes.end(); it++) {
|
|
|
|
if(&*it == attr) {
|
|
|
|
attributes.erase(it);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-04-30 12:49:26 +00:00
|
|
|
Attribute *AttributeSet::add(AttributeStandard std, ustring name)
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
|
|
|
Attribute *attr = NULL;
|
|
|
|
|
|
|
|
if(name == ustring())
|
2013-01-03 12:08:54 +00:00
|
|
|
name = Attribute::standard_name(std);
|
|
|
|
|
2016-07-16 23:42:28 +00:00
|
|
|
if(triangle_mesh || subd_mesh) {
|
2013-04-05 17:03:59 +00:00
|
|
|
switch(std) {
|
|
|
|
case ATTR_STD_VERTEX_NORMAL:
|
|
|
|
attr = add(name, TypeDesc::TypeNormal, ATTR_ELEMENT_VERTEX);
|
|
|
|
break;
|
|
|
|
case ATTR_STD_FACE_NORMAL:
|
|
|
|
attr = add(name, TypeDesc::TypeNormal, ATTR_ELEMENT_FACE);
|
|
|
|
break;
|
|
|
|
case ATTR_STD_UV:
|
|
|
|
attr = add(name, TypeDesc::TypePoint, ATTR_ELEMENT_CORNER);
|
|
|
|
break;
|
|
|
|
case ATTR_STD_UV_TANGENT:
|
|
|
|
attr = add(name, TypeDesc::TypeVector, ATTR_ELEMENT_CORNER);
|
|
|
|
break;
|
|
|
|
case ATTR_STD_UV_TANGENT_SIGN:
|
|
|
|
attr = add(name, TypeDesc::TypeFloat, ATTR_ELEMENT_CORNER);
|
|
|
|
break;
|
|
|
|
case ATTR_STD_GENERATED:
|
|
|
|
case ATTR_STD_POSITION_UNDEFORMED:
|
|
|
|
case ATTR_STD_POSITION_UNDISPLACED:
|
|
|
|
attr = add(name, TypeDesc::TypePoint, ATTR_ELEMENT_VERTEX);
|
|
|
|
break;
|
2014-03-29 12:03:46 +00:00
|
|
|
case ATTR_STD_MOTION_VERTEX_POSITION:
|
|
|
|
attr = add(name, TypeDesc::TypePoint, ATTR_ELEMENT_VERTEX_MOTION);
|
2014-03-29 12:03:46 +00:00
|
|
|
break;
|
|
|
|
case ATTR_STD_MOTION_VERTEX_NORMAL:
|
|
|
|
attr = add(name, TypeDesc::TypeNormal, ATTR_ELEMENT_VERTEX_MOTION);
|
2014-03-29 12:03:46 +00:00
|
|
|
break;
|
2013-11-28 00:28:57 +00:00
|
|
|
case ATTR_STD_PTEX_FACE_ID:
|
|
|
|
attr = add(name, TypeDesc::TypeFloat, ATTR_ELEMENT_FACE);
|
|
|
|
break;
|
|
|
|
case ATTR_STD_PTEX_UV:
|
|
|
|
attr = add(name, TypeDesc::TypePoint, ATTR_ELEMENT_VERTEX);
|
|
|
|
break;
|
2013-12-31 16:33:55 +00:00
|
|
|
case ATTR_STD_GENERATED_TRANSFORM:
|
|
|
|
attr = add(name, TypeDesc::TypeMatrix, ATTR_ELEMENT_MESH);
|
|
|
|
break;
|
2014-03-29 12:03:48 +00:00
|
|
|
case ATTR_STD_VOLUME_DENSITY:
|
|
|
|
case ATTR_STD_VOLUME_FLAME:
|
|
|
|
case ATTR_STD_VOLUME_HEAT:
|
|
|
|
attr = add(name, TypeDesc::TypeFloat, ATTR_ELEMENT_VOXEL);
|
|
|
|
break;
|
|
|
|
case ATTR_STD_VOLUME_COLOR:
|
|
|
|
attr = add(name, TypeDesc::TypeColor, ATTR_ELEMENT_VOXEL);
|
|
|
|
break;
|
|
|
|
case ATTR_STD_VOLUME_VELOCITY:
|
|
|
|
attr = add(name, TypeDesc::TypeVector, ATTR_ELEMENT_VOXEL);
|
|
|
|
break;
|
2015-02-06 07:35:46 +00:00
|
|
|
case ATTR_STD_POINTINESS:
|
|
|
|
attr = add(name, TypeDesc::TypeFloat, ATTR_ELEMENT_VERTEX);
|
|
|
|
break;
|
2013-04-05 17:03:59 +00:00
|
|
|
default:
|
|
|
|
assert(0);
|
|
|
|
break;
|
|
|
|
}
|
2013-01-03 12:08:54 +00:00
|
|
|
}
|
|
|
|
else if(curve_mesh) {
|
2013-04-05 17:03:59 +00:00
|
|
|
switch(std) {
|
|
|
|
case ATTR_STD_UV:
|
|
|
|
case ATTR_STD_GENERATED:
|
|
|
|
attr = add(name, TypeDesc::TypePoint, ATTR_ELEMENT_CURVE);
|
|
|
|
break;
|
2014-03-29 12:03:46 +00:00
|
|
|
case ATTR_STD_MOTION_VERTEX_POSITION:
|
|
|
|
attr = add(name, TypeDesc::TypePoint, ATTR_ELEMENT_CURVE_KEY_MOTION);
|
2013-04-05 17:03:59 +00:00
|
|
|
break;
|
|
|
|
case ATTR_STD_CURVE_INTERCEPT:
|
|
|
|
attr = add(name, TypeDesc::TypeFloat, ATTR_ELEMENT_CURVE_KEY);
|
|
|
|
break;
|
2013-12-31 16:33:55 +00:00
|
|
|
case ATTR_STD_GENERATED_TRANSFORM:
|
|
|
|
attr = add(name, TypeDesc::TypeMatrix, ATTR_ELEMENT_MESH);
|
|
|
|
break;
|
2015-02-06 07:35:46 +00:00
|
|
|
case ATTR_STD_POINTINESS:
|
|
|
|
attr = add(name, TypeDesc::TypeFloat, ATTR_ELEMENT_VERTEX);
|
|
|
|
break;
|
2013-04-05 17:03:59 +00:00
|
|
|
default:
|
|
|
|
assert(0);
|
|
|
|
break;
|
|
|
|
}
|
2013-01-03 12:08:54 +00:00
|
|
|
}
|
2011-04-27 11:58:34 +00:00
|
|
|
|
|
|
|
attr->std = std;
|
|
|
|
|
|
|
|
return attr;
|
|
|
|
}
|
|
|
|
|
2013-01-03 12:08:54 +00:00
|
|
|
Attribute *AttributeSet::find(AttributeStandard std) const
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
2013-01-03 12:08:54 +00:00
|
|
|
foreach(const Attribute& attr, attributes)
|
2011-04-27 11:58:34 +00:00
|
|
|
if(attr.std == std)
|
2013-01-03 12:08:54 +00:00
|
|
|
return (Attribute*)&attr;
|
2011-04-27 11:58:34 +00:00
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2012-04-30 12:49:26 +00:00
|
|
|
void AttributeSet::remove(AttributeStandard std)
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
|
|
|
Attribute *attr = find(std);
|
|
|
|
|
|
|
|
if(attr) {
|
|
|
|
list<Attribute>::iterator it;
|
|
|
|
|
|
|
|
for(it = attributes.begin(); it != attributes.end(); it++) {
|
|
|
|
if(&*it == attr) {
|
|
|
|
attributes.erase(it);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Attribute *AttributeSet::find(AttributeRequest& req)
|
|
|
|
{
|
2012-04-30 12:49:26 +00:00
|
|
|
if(req.std == ATTR_STD_NONE)
|
2011-04-27 11:58:34 +00:00
|
|
|
return find(req.name);
|
|
|
|
else
|
|
|
|
return find(req.std);
|
|
|
|
}
|
|
|
|
|
2016-05-07 22:09:08 +00:00
|
|
|
void AttributeSet::resize(bool reserve_only)
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
2013-01-03 12:08:54 +00:00
|
|
|
foreach(Attribute& attr, attributes) {
|
|
|
|
if(triangle_mesh)
|
2016-07-16 23:42:28 +00:00
|
|
|
attr.resize(triangle_mesh, ATTR_PRIM_TRIANGLE, reserve_only);
|
2013-01-03 12:08:54 +00:00
|
|
|
if(curve_mesh)
|
2016-07-16 23:42:28 +00:00
|
|
|
attr.resize(curve_mesh, ATTR_PRIM_CURVE, reserve_only);
|
|
|
|
if(subd_mesh)
|
|
|
|
attr.resize(subd_mesh, ATTR_PRIM_SUBD, reserve_only);
|
2013-01-03 12:08:54 +00:00
|
|
|
}
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void AttributeSet::clear()
|
|
|
|
{
|
|
|
|
attributes.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
/* AttributeRequest */
|
|
|
|
|
|
|
|
AttributeRequest::AttributeRequest(ustring name_)
|
|
|
|
{
|
|
|
|
name = name_;
|
2012-04-30 12:49:26 +00:00
|
|
|
std = ATTR_STD_NONE;
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2013-01-03 12:08:54 +00:00
|
|
|
triangle_type = TypeDesc::TypeFloat;
|
2016-07-01 21:36:27 +00:00
|
|
|
triangle_desc.element = ATTR_ELEMENT_NONE;
|
|
|
|
triangle_desc.offset = 0;
|
|
|
|
triangle_desc.type = NODE_ATTR_FLOAT;
|
2013-01-03 12:08:54 +00:00
|
|
|
|
|
|
|
curve_type = TypeDesc::TypeFloat;
|
2016-07-01 21:36:27 +00:00
|
|
|
curve_desc.element = ATTR_ELEMENT_NONE;
|
|
|
|
curve_desc.offset = 0;
|
|
|
|
curve_desc.type = NODE_ATTR_FLOAT;
|
2016-07-16 23:42:28 +00:00
|
|
|
|
|
|
|
subd_type = TypeDesc::TypeFloat;
|
2016-07-01 21:36:27 +00:00
|
|
|
subd_desc.element = ATTR_ELEMENT_NONE;
|
|
|
|
subd_desc.offset = 0;
|
|
|
|
subd_desc.type = NODE_ATTR_FLOAT;
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
2012-04-30 12:49:26 +00:00
|
|
|
AttributeRequest::AttributeRequest(AttributeStandard std_)
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
|
|
|
name = ustring();
|
|
|
|
std = std_;
|
|
|
|
|
2013-01-03 12:08:54 +00:00
|
|
|
triangle_type = TypeDesc::TypeFloat;
|
2016-07-01 21:36:27 +00:00
|
|
|
triangle_desc.element = ATTR_ELEMENT_NONE;
|
|
|
|
triangle_desc.offset = 0;
|
|
|
|
triangle_desc.type = NODE_ATTR_FLOAT;
|
2013-01-03 12:08:54 +00:00
|
|
|
|
|
|
|
curve_type = TypeDesc::TypeFloat;
|
2016-07-01 21:36:27 +00:00
|
|
|
curve_desc.element = ATTR_ELEMENT_NONE;
|
|
|
|
curve_desc.offset = 0;
|
|
|
|
curve_desc.type = NODE_ATTR_FLOAT;
|
2016-07-16 23:42:28 +00:00
|
|
|
|
|
|
|
subd_type = TypeDesc::TypeFloat;
|
2016-07-01 21:36:27 +00:00
|
|
|
subd_desc.element = ATTR_ELEMENT_NONE;
|
|
|
|
subd_desc.offset = 0;
|
|
|
|
subd_desc.type = NODE_ATTR_FLOAT;
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* AttributeRequestSet */
|
|
|
|
|
|
|
|
AttributeRequestSet::AttributeRequestSet()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
AttributeRequestSet::~AttributeRequestSet()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
bool AttributeRequestSet::modified(const AttributeRequestSet& other)
|
|
|
|
{
|
|
|
|
if(requests.size() != other.requests.size())
|
|
|
|
return true;
|
|
|
|
|
|
|
|
for(size_t i = 0; i < requests.size(); i++) {
|
|
|
|
bool found = false;
|
|
|
|
|
|
|
|
for(size_t j = 0; j < requests.size() && !found; j++)
|
|
|
|
if(requests[i].name == other.requests[j].name &&
|
|
|
|
requests[i].std == other.requests[j].std)
|
2012-06-09 18:56:12 +00:00
|
|
|
{
|
2011-04-27 11:58:34 +00:00
|
|
|
found = true;
|
2012-06-09 18:56:12 +00:00
|
|
|
}
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2012-06-09 18:56:12 +00:00
|
|
|
if(!found) {
|
2011-04-27 11:58:34 +00:00
|
|
|
return true;
|
2012-06-09 18:56:12 +00:00
|
|
|
}
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void AttributeRequestSet::add(ustring name)
|
|
|
|
{
|
|
|
|
foreach(AttributeRequest& req, requests)
|
|
|
|
if(req.name == name)
|
|
|
|
return;
|
|
|
|
|
|
|
|
requests.push_back(AttributeRequest(name));
|
|
|
|
}
|
|
|
|
|
2012-04-30 12:49:26 +00:00
|
|
|
void AttributeRequestSet::add(AttributeStandard std)
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
|
|
|
foreach(AttributeRequest& req, requests)
|
|
|
|
if(req.std == std)
|
|
|
|
return;
|
|
|
|
|
|
|
|
requests.push_back(AttributeRequest(std));
|
|
|
|
}
|
|
|
|
|
|
|
|
void AttributeRequestSet::add(AttributeRequestSet& reqs)
|
|
|
|
{
|
|
|
|
foreach(AttributeRequest& req, reqs.requests) {
|
2012-04-30 12:49:26 +00:00
|
|
|
if(req.std == ATTR_STD_NONE)
|
2011-04-27 11:58:34 +00:00
|
|
|
add(req.name);
|
|
|
|
else
|
|
|
|
add(req.std);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool AttributeRequestSet::find(ustring name)
|
|
|
|
{
|
|
|
|
foreach(AttributeRequest& req, requests)
|
|
|
|
if(req.name == name)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-04-30 12:49:26 +00:00
|
|
|
bool AttributeRequestSet::find(AttributeStandard std)
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
|
|
|
foreach(AttributeRequest& req, requests)
|
|
|
|
if(req.std == std)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t AttributeRequestSet::size()
|
|
|
|
{
|
|
|
|
return requests.size();
|
|
|
|
}
|
|
|
|
|
|
|
|
void AttributeRequestSet::clear()
|
|
|
|
{
|
|
|
|
requests.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
CCL_NAMESPACE_END
|
|
|
|
|