OpenSubdiv: Re-work C-API integration
Main goal is to make API simpler to follow (at least ion terms what
is defined/declared where, as opposite of handful big headers which
includes all the declarations), and also avoid a big set of long and
obscure functions.
Now C-API files are split into smaller ones, following OpenSubdiv
behavior more closely, and also function pointers in structures
used a lot more, which shortens functions names,
UV integration part in GL Mesh is mainly stripped away, it needs
to be done differently. On a related topic, UV coordinates API in
converter needs to be removed as well, we do not need coordinates,
only island connectivity information there.
Additional changes:
- Varying interpolation in evaluator API are temporarily disabled,
need to extend API somewhere (probably, evaluator's API) to inform
layout information of vertex data (whether it contains varying
data, width, stride and such).
- Evaluator now can interpolate face-varying data.
Only works for adaptive refiner, since some issues in OpenSubdiv
itself.
Planned changes:
- Remove uv coordinates from TopologyConverter.
- Support evaluation of patches (as opposite to individual coordinates
as it happens currently).
- Support more flexible layout of varying and face-varying data.
It is stupid to assume varying is 3 floats and face-varying 2 floats.
- Support of second order derivatives.
- Everything else what i'm missing in this list.
2018-07-16 09:28:05 +02:00
|
|
|
// Copyright 2018 Blender Foundation. All rights reserved.
|
|
|
|
|
//
|
|
|
|
|
// This program is free software; you can redistribute it and/or
|
|
|
|
|
// modify it under the terms of the GNU General Public License
|
|
|
|
|
// as published by the Free Software Foundation; either version 2
|
|
|
|
|
// of the License, or (at your option) any later version.
|
|
|
|
|
//
|
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
|
//
|
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
|
// along with this program; if not, write to the Free Software Foundation,
|
|
|
|
|
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
//
|
|
|
|
|
// Author: Sergey Sharybin
|
|
|
|
|
|
|
|
|
|
#include "opensubdiv_topology_refiner_capi.h"
|
|
|
|
|
|
|
|
|
|
#include "MEM_guardedalloc.h"
|
2020-05-19 10:49:41 +02:00
|
|
|
#include "internal/base/type_convert.h"
|
2020-05-18 18:47:38 +02:00
|
|
|
#include "internal/topology/topology_refiner_impl.h"
|
2019-01-15 11:08:33 +01:00
|
|
|
|
2020-05-18 17:25:07 +02:00
|
|
|
using blender::opensubdiv::vector;
|
OpenSubdiv: Re-work C-API integration
Main goal is to make API simpler to follow (at least ion terms what
is defined/declared where, as opposite of handful big headers which
includes all the declarations), and also avoid a big set of long and
obscure functions.
Now C-API files are split into smaller ones, following OpenSubdiv
behavior more closely, and also function pointers in structures
used a lot more, which shortens functions names,
UV integration part in GL Mesh is mainly stripped away, it needs
to be done differently. On a related topic, UV coordinates API in
converter needs to be removed as well, we do not need coordinates,
only island connectivity information there.
Additional changes:
- Varying interpolation in evaluator API are temporarily disabled,
need to extend API somewhere (probably, evaluator's API) to inform
layout information of vertex data (whether it contains varying
data, width, stride and such).
- Evaluator now can interpolate face-varying data.
Only works for adaptive refiner, since some issues in OpenSubdiv
itself.
Planned changes:
- Remove uv coordinates from TopologyConverter.
- Support evaluation of patches (as opposite to individual coordinates
as it happens currently).
- Support more flexible layout of varying and face-varying data.
It is stupid to assume varying is 3 floats and face-varying 2 floats.
- Support of second order derivatives.
- Everything else what i'm missing in this list.
2018-07-16 09:28:05 +02:00
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
|
|
const OpenSubdiv::Far::TopologyRefiner *getOSDTopologyRefiner(
|
|
|
|
|
const OpenSubdiv_TopologyRefiner *topology_refiner)
|
|
|
|
|
{
|
2020-05-19 10:13:16 +02:00
|
|
|
return topology_refiner->impl->topology_refiner;
|
OpenSubdiv: Re-work C-API integration
Main goal is to make API simpler to follow (at least ion terms what
is defined/declared where, as opposite of handful big headers which
includes all the declarations), and also avoid a big set of long and
obscure functions.
Now C-API files are split into smaller ones, following OpenSubdiv
behavior more closely, and also function pointers in structures
used a lot more, which shortens functions names,
UV integration part in GL Mesh is mainly stripped away, it needs
to be done differently. On a related topic, UV coordinates API in
converter needs to be removed as well, we do not need coordinates,
only island connectivity information there.
Additional changes:
- Varying interpolation in evaluator API are temporarily disabled,
need to extend API somewhere (probably, evaluator's API) to inform
layout information of vertex data (whether it contains varying
data, width, stride and such).
- Evaluator now can interpolate face-varying data.
Only works for adaptive refiner, since some issues in OpenSubdiv
itself.
Planned changes:
- Remove uv coordinates from TopologyConverter.
- Support evaluation of patches (as opposite to individual coordinates
as it happens currently).
- Support more flexible layout of varying and face-varying data.
It is stupid to assume varying is 3 floats and face-varying 2 floats.
- Support of second order derivatives.
- Everything else what i'm missing in this list.
2018-07-16 09:28:05 +02:00
|
|
|
}
|
|
|
|
|
|
2020-05-19 11:36:06 +02:00
|
|
|
const OpenSubdiv::Far::TopologyLevel &getOSDTopologyBaseLevel(
|
OpenSubdiv: Re-work C-API integration
Main goal is to make API simpler to follow (at least ion terms what
is defined/declared where, as opposite of handful big headers which
includes all the declarations), and also avoid a big set of long and
obscure functions.
Now C-API files are split into smaller ones, following OpenSubdiv
behavior more closely, and also function pointers in structures
used a lot more, which shortens functions names,
UV integration part in GL Mesh is mainly stripped away, it needs
to be done differently. On a related topic, UV coordinates API in
converter needs to be removed as well, we do not need coordinates,
only island connectivity information there.
Additional changes:
- Varying interpolation in evaluator API are temporarily disabled,
need to extend API somewhere (probably, evaluator's API) to inform
layout information of vertex data (whether it contains varying
data, width, stride and such).
- Evaluator now can interpolate face-varying data.
Only works for adaptive refiner, since some issues in OpenSubdiv
itself.
Planned changes:
- Remove uv coordinates from TopologyConverter.
- Support evaluation of patches (as opposite to individual coordinates
as it happens currently).
- Support more flexible layout of varying and face-varying data.
It is stupid to assume varying is 3 floats and face-varying 2 floats.
- Support of second order derivatives.
- Everything else what i'm missing in this list.
2018-07-16 09:28:05 +02:00
|
|
|
const OpenSubdiv_TopologyRefiner *topology_refiner)
|
|
|
|
|
{
|
2020-05-19 11:36:06 +02:00
|
|
|
return getOSDTopologyRefiner(topology_refiner)->GetLevel(0);
|
OpenSubdiv: Re-work C-API integration
Main goal is to make API simpler to follow (at least ion terms what
is defined/declared where, as opposite of handful big headers which
includes all the declarations), and also avoid a big set of long and
obscure functions.
Now C-API files are split into smaller ones, following OpenSubdiv
behavior more closely, and also function pointers in structures
used a lot more, which shortens functions names,
UV integration part in GL Mesh is mainly stripped away, it needs
to be done differently. On a related topic, UV coordinates API in
converter needs to be removed as well, we do not need coordinates,
only island connectivity information there.
Additional changes:
- Varying interpolation in evaluator API are temporarily disabled,
need to extend API somewhere (probably, evaluator's API) to inform
layout information of vertex data (whether it contains varying
data, width, stride and such).
- Evaluator now can interpolate face-varying data.
Only works for adaptive refiner, since some issues in OpenSubdiv
itself.
Planned changes:
- Remove uv coordinates from TopologyConverter.
- Support evaluation of patches (as opposite to individual coordinates
as it happens currently).
- Support more flexible layout of varying and face-varying data.
It is stupid to assume varying is 3 floats and face-varying 2 floats.
- Support of second order derivatives.
- Everything else what i'm missing in this list.
2018-07-16 09:28:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int getSubdivisionLevel(const OpenSubdiv_TopologyRefiner *topology_refiner)
|
|
|
|
|
{
|
2020-05-18 18:47:38 +02:00
|
|
|
return topology_refiner->impl->settings.level;
|
OpenSubdiv: Re-work C-API integration
Main goal is to make API simpler to follow (at least ion terms what
is defined/declared where, as opposite of handful big headers which
includes all the declarations), and also avoid a big set of long and
obscure functions.
Now C-API files are split into smaller ones, following OpenSubdiv
behavior more closely, and also function pointers in structures
used a lot more, which shortens functions names,
UV integration part in GL Mesh is mainly stripped away, it needs
to be done differently. On a related topic, UV coordinates API in
converter needs to be removed as well, we do not need coordinates,
only island connectivity information there.
Additional changes:
- Varying interpolation in evaluator API are temporarily disabled,
need to extend API somewhere (probably, evaluator's API) to inform
layout information of vertex data (whether it contains varying
data, width, stride and such).
- Evaluator now can interpolate face-varying data.
Only works for adaptive refiner, since some issues in OpenSubdiv
itself.
Planned changes:
- Remove uv coordinates from TopologyConverter.
- Support evaluation of patches (as opposite to individual coordinates
as it happens currently).
- Support more flexible layout of varying and face-varying data.
It is stupid to assume varying is 3 floats and face-varying 2 floats.
- Support of second order derivatives.
- Everything else what i'm missing in this list.
2018-07-16 09:28:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool getIsAdaptive(const OpenSubdiv_TopologyRefiner *topology_refiner)
|
|
|
|
|
{
|
2020-05-18 18:47:38 +02:00
|
|
|
return topology_refiner->impl->settings.is_adaptive;
|
OpenSubdiv: Re-work C-API integration
Main goal is to make API simpler to follow (at least ion terms what
is defined/declared where, as opposite of handful big headers which
includes all the declarations), and also avoid a big set of long and
obscure functions.
Now C-API files are split into smaller ones, following OpenSubdiv
behavior more closely, and also function pointers in structures
used a lot more, which shortens functions names,
UV integration part in GL Mesh is mainly stripped away, it needs
to be done differently. On a related topic, UV coordinates API in
converter needs to be removed as well, we do not need coordinates,
only island connectivity information there.
Additional changes:
- Varying interpolation in evaluator API are temporarily disabled,
need to extend API somewhere (probably, evaluator's API) to inform
layout information of vertex data (whether it contains varying
data, width, stride and such).
- Evaluator now can interpolate face-varying data.
Only works for adaptive refiner, since some issues in OpenSubdiv
itself.
Planned changes:
- Remove uv coordinates from TopologyConverter.
- Support evaluation of patches (as opposite to individual coordinates
as it happens currently).
- Support more flexible layout of varying and face-varying data.
It is stupid to assume varying is 3 floats and face-varying 2 floats.
- Support of second order derivatives.
- Everything else what i'm missing in this list.
2018-07-16 09:28:05 +02:00
|
|
|
}
|
|
|
|
|
|
2018-07-17 18:06:32 +02:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
// Query basic topology information from base level.
|
|
|
|
|
|
OpenSubdiv: Re-work C-API integration
Main goal is to make API simpler to follow (at least ion terms what
is defined/declared where, as opposite of handful big headers which
includes all the declarations), and also avoid a big set of long and
obscure functions.
Now C-API files are split into smaller ones, following OpenSubdiv
behavior more closely, and also function pointers in structures
used a lot more, which shortens functions names,
UV integration part in GL Mesh is mainly stripped away, it needs
to be done differently. On a related topic, UV coordinates API in
converter needs to be removed as well, we do not need coordinates,
only island connectivity information there.
Additional changes:
- Varying interpolation in evaluator API are temporarily disabled,
need to extend API somewhere (probably, evaluator's API) to inform
layout information of vertex data (whether it contains varying
data, width, stride and such).
- Evaluator now can interpolate face-varying data.
Only works for adaptive refiner, since some issues in OpenSubdiv
itself.
Planned changes:
- Remove uv coordinates from TopologyConverter.
- Support evaluation of patches (as opposite to individual coordinates
as it happens currently).
- Support more flexible layout of varying and face-varying data.
It is stupid to assume varying is 3 floats and face-varying 2 floats.
- Support of second order derivatives.
- Everything else what i'm missing in this list.
2018-07-16 09:28:05 +02:00
|
|
|
int getNumVertices(const OpenSubdiv_TopologyRefiner *topology_refiner)
|
|
|
|
|
{
|
2020-05-19 11:36:06 +02:00
|
|
|
return getOSDTopologyBaseLevel(topology_refiner).GetNumVertices();
|
OpenSubdiv: Re-work C-API integration
Main goal is to make API simpler to follow (at least ion terms what
is defined/declared where, as opposite of handful big headers which
includes all the declarations), and also avoid a big set of long and
obscure functions.
Now C-API files are split into smaller ones, following OpenSubdiv
behavior more closely, and also function pointers in structures
used a lot more, which shortens functions names,
UV integration part in GL Mesh is mainly stripped away, it needs
to be done differently. On a related topic, UV coordinates API in
converter needs to be removed as well, we do not need coordinates,
only island connectivity information there.
Additional changes:
- Varying interpolation in evaluator API are temporarily disabled,
need to extend API somewhere (probably, evaluator's API) to inform
layout information of vertex data (whether it contains varying
data, width, stride and such).
- Evaluator now can interpolate face-varying data.
Only works for adaptive refiner, since some issues in OpenSubdiv
itself.
Planned changes:
- Remove uv coordinates from TopologyConverter.
- Support evaluation of patches (as opposite to individual coordinates
as it happens currently).
- Support more flexible layout of varying and face-varying data.
It is stupid to assume varying is 3 floats and face-varying 2 floats.
- Support of second order derivatives.
- Everything else what i'm missing in this list.
2018-07-16 09:28:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int getNumEdges(const OpenSubdiv_TopologyRefiner *topology_refiner)
|
|
|
|
|
{
|
2020-05-19 11:36:06 +02:00
|
|
|
return getOSDTopologyBaseLevel(topology_refiner).GetNumEdges();
|
OpenSubdiv: Re-work C-API integration
Main goal is to make API simpler to follow (at least ion terms what
is defined/declared where, as opposite of handful big headers which
includes all the declarations), and also avoid a big set of long and
obscure functions.
Now C-API files are split into smaller ones, following OpenSubdiv
behavior more closely, and also function pointers in structures
used a lot more, which shortens functions names,
UV integration part in GL Mesh is mainly stripped away, it needs
to be done differently. On a related topic, UV coordinates API in
converter needs to be removed as well, we do not need coordinates,
only island connectivity information there.
Additional changes:
- Varying interpolation in evaluator API are temporarily disabled,
need to extend API somewhere (probably, evaluator's API) to inform
layout information of vertex data (whether it contains varying
data, width, stride and such).
- Evaluator now can interpolate face-varying data.
Only works for adaptive refiner, since some issues in OpenSubdiv
itself.
Planned changes:
- Remove uv coordinates from TopologyConverter.
- Support evaluation of patches (as opposite to individual coordinates
as it happens currently).
- Support more flexible layout of varying and face-varying data.
It is stupid to assume varying is 3 floats and face-varying 2 floats.
- Support of second order derivatives.
- Everything else what i'm missing in this list.
2018-07-16 09:28:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int getNumFaces(const OpenSubdiv_TopologyRefiner *topology_refiner)
|
|
|
|
|
{
|
2020-05-19 11:36:06 +02:00
|
|
|
return getOSDTopologyBaseLevel(topology_refiner).GetNumFaces();
|
OpenSubdiv: Re-work C-API integration
Main goal is to make API simpler to follow (at least ion terms what
is defined/declared where, as opposite of handful big headers which
includes all the declarations), and also avoid a big set of long and
obscure functions.
Now C-API files are split into smaller ones, following OpenSubdiv
behavior more closely, and also function pointers in structures
used a lot more, which shortens functions names,
UV integration part in GL Mesh is mainly stripped away, it needs
to be done differently. On a related topic, UV coordinates API in
converter needs to be removed as well, we do not need coordinates,
only island connectivity information there.
Additional changes:
- Varying interpolation in evaluator API are temporarily disabled,
need to extend API somewhere (probably, evaluator's API) to inform
layout information of vertex data (whether it contains varying
data, width, stride and such).
- Evaluator now can interpolate face-varying data.
Only works for adaptive refiner, since some issues in OpenSubdiv
itself.
Planned changes:
- Remove uv coordinates from TopologyConverter.
- Support evaluation of patches (as opposite to individual coordinates
as it happens currently).
- Support more flexible layout of varying and face-varying data.
It is stupid to assume varying is 3 floats and face-varying 2 floats.
- Support of second order derivatives.
- Everything else what i'm missing in this list.
2018-07-16 09:28:05 +02:00
|
|
|
}
|
|
|
|
|
|
2018-07-17 18:06:32 +02:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
// PTex face geometry queries.
|
|
|
|
|
|
2018-09-20 11:45:22 +02:00
|
|
|
static void convertArrayToRaw(const OpenSubdiv::Far::ConstIndexArray &array, int *raw_array)
|
|
|
|
|
{
|
|
|
|
|
for (int i = 0; i < array.size(); ++i) {
|
|
|
|
|
raw_array[i] = array[i];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
OpenSubdiv: Re-work C-API integration
Main goal is to make API simpler to follow (at least ion terms what
is defined/declared where, as opposite of handful big headers which
includes all the declarations), and also avoid a big set of long and
obscure functions.
Now C-API files are split into smaller ones, following OpenSubdiv
behavior more closely, and also function pointers in structures
used a lot more, which shortens functions names,
UV integration part in GL Mesh is mainly stripped away, it needs
to be done differently. On a related topic, UV coordinates API in
converter needs to be removed as well, we do not need coordinates,
only island connectivity information there.
Additional changes:
- Varying interpolation in evaluator API are temporarily disabled,
need to extend API somewhere (probably, evaluator's API) to inform
layout information of vertex data (whether it contains varying
data, width, stride and such).
- Evaluator now can interpolate face-varying data.
Only works for adaptive refiner, since some issues in OpenSubdiv
itself.
Planned changes:
- Remove uv coordinates from TopologyConverter.
- Support evaluation of patches (as opposite to individual coordinates
as it happens currently).
- Support more flexible layout of varying and face-varying data.
It is stupid to assume varying is 3 floats and face-varying 2 floats.
- Support of second order derivatives.
- Everything else what i'm missing in this list.
2018-07-16 09:28:05 +02:00
|
|
|
int getNumFaceVertices(const OpenSubdiv_TopologyRefiner *topology_refiner, const int face_index)
|
|
|
|
|
{
|
2020-05-19 11:36:06 +02:00
|
|
|
const OpenSubdiv::Far::TopologyLevel &base_level = getOSDTopologyBaseLevel(topology_refiner);
|
|
|
|
|
return base_level.GetFaceVertices(face_index).size();
|
OpenSubdiv: Re-work C-API integration
Main goal is to make API simpler to follow (at least ion terms what
is defined/declared where, as opposite of handful big headers which
includes all the declarations), and also avoid a big set of long and
obscure functions.
Now C-API files are split into smaller ones, following OpenSubdiv
behavior more closely, and also function pointers in structures
used a lot more, which shortens functions names,
UV integration part in GL Mesh is mainly stripped away, it needs
to be done differently. On a related topic, UV coordinates API in
converter needs to be removed as well, we do not need coordinates,
only island connectivity information there.
Additional changes:
- Varying interpolation in evaluator API are temporarily disabled,
need to extend API somewhere (probably, evaluator's API) to inform
layout information of vertex data (whether it contains varying
data, width, stride and such).
- Evaluator now can interpolate face-varying data.
Only works for adaptive refiner, since some issues in OpenSubdiv
itself.
Planned changes:
- Remove uv coordinates from TopologyConverter.
- Support evaluation of patches (as opposite to individual coordinates
as it happens currently).
- Support more flexible layout of varying and face-varying data.
It is stupid to assume varying is 3 floats and face-varying 2 floats.
- Support of second order derivatives.
- Everything else what i'm missing in this list.
2018-07-16 09:28:05 +02:00
|
|
|
}
|
|
|
|
|
|
2018-09-20 11:45:22 +02:00
|
|
|
void getFaceVertices(const OpenSubdiv_TopologyRefiner *topology_refiner,
|
|
|
|
|
const int face_index,
|
|
|
|
|
int *face_vertices_indices)
|
|
|
|
|
{
|
2020-05-19 11:36:06 +02:00
|
|
|
const OpenSubdiv::Far::TopologyLevel &base_level = getOSDTopologyBaseLevel(topology_refiner);
|
|
|
|
|
OpenSubdiv::Far::ConstIndexArray array = base_level.GetFaceVertices(face_index);
|
2018-09-20 11:45:22 +02:00
|
|
|
convertArrayToRaw(array, face_vertices_indices);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int getNumFaceEdges(const OpenSubdiv_TopologyRefiner *topology_refiner, const int face_index)
|
|
|
|
|
{
|
2020-05-19 11:36:06 +02:00
|
|
|
const OpenSubdiv::Far::TopologyLevel &base_level = getOSDTopologyBaseLevel(topology_refiner);
|
|
|
|
|
return base_level.GetFaceEdges(face_index).size();
|
2018-09-20 11:45:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void getFaceEdges(const OpenSubdiv_TopologyRefiner *topology_refiner,
|
|
|
|
|
const int face_index,
|
|
|
|
|
int *face_edges_indices)
|
|
|
|
|
{
|
2020-05-19 11:36:06 +02:00
|
|
|
const OpenSubdiv::Far::TopologyLevel &base_level = getOSDTopologyBaseLevel(topology_refiner);
|
|
|
|
|
OpenSubdiv::Far::ConstIndexArray array = base_level.GetFaceEdges(face_index);
|
2018-09-20 11:45:22 +02:00
|
|
|
convertArrayToRaw(array, face_edges_indices);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void getEdgeVertices(const OpenSubdiv_TopologyRefiner *topology_refiner,
|
|
|
|
|
const int edge_index,
|
|
|
|
|
int edge_vertices_indices[2])
|
|
|
|
|
{
|
2020-05-19 11:36:06 +02:00
|
|
|
const OpenSubdiv::Far::TopologyLevel &base_level = getOSDTopologyBaseLevel(topology_refiner);
|
|
|
|
|
OpenSubdiv::Far::ConstIndexArray array = base_level.GetEdgeVertices(edge_index);
|
2018-09-20 11:45:22 +02:00
|
|
|
assert(array.size() == 2);
|
|
|
|
|
edge_vertices_indices[0] = array[0];
|
|
|
|
|
edge_vertices_indices[1] = array[1];
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-02 12:37:44 +02:00
|
|
|
int getNumVertexEdges(const OpenSubdiv_TopologyRefiner *topology_refiner, const int vertex_index)
|
|
|
|
|
{
|
2020-05-19 11:36:06 +02:00
|
|
|
const OpenSubdiv::Far::TopologyLevel &base_level = getOSDTopologyBaseLevel(topology_refiner);
|
|
|
|
|
return base_level.GetVertexEdges(vertex_index).size();
|
2019-10-02 12:37:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void getVertexEdges(const OpenSubdiv_TopologyRefiner *topology_refiner,
|
|
|
|
|
const int vertex_index,
|
|
|
|
|
int *vertex_edges_indices)
|
|
|
|
|
{
|
2020-05-19 11:36:06 +02:00
|
|
|
const OpenSubdiv::Far::TopologyLevel &base_level = getOSDTopologyBaseLevel(topology_refiner);
|
|
|
|
|
OpenSubdiv::Far::ConstIndexArray array = base_level.GetVertexEdges(vertex_index);
|
2019-10-02 12:37:44 +02:00
|
|
|
convertArrayToRaw(array, vertex_edges_indices);
|
|
|
|
|
}
|
|
|
|
|
|
OpenSubdiv: Re-work C-API integration
Main goal is to make API simpler to follow (at least ion terms what
is defined/declared where, as opposite of handful big headers which
includes all the declarations), and also avoid a big set of long and
obscure functions.
Now C-API files are split into smaller ones, following OpenSubdiv
behavior more closely, and also function pointers in structures
used a lot more, which shortens functions names,
UV integration part in GL Mesh is mainly stripped away, it needs
to be done differently. On a related topic, UV coordinates API in
converter needs to be removed as well, we do not need coordinates,
only island connectivity information there.
Additional changes:
- Varying interpolation in evaluator API are temporarily disabled,
need to extend API somewhere (probably, evaluator's API) to inform
layout information of vertex data (whether it contains varying
data, width, stride and such).
- Evaluator now can interpolate face-varying data.
Only works for adaptive refiner, since some issues in OpenSubdiv
itself.
Planned changes:
- Remove uv coordinates from TopologyConverter.
- Support evaluation of patches (as opposite to individual coordinates
as it happens currently).
- Support more flexible layout of varying and face-varying data.
It is stupid to assume varying is 3 floats and face-varying 2 floats.
- Support of second order derivatives.
- Everything else what i'm missing in this list.
2018-07-16 09:28:05 +02:00
|
|
|
int getNumFacePtexFaces(const OpenSubdiv_TopologyRefiner *topology_refiner, const int face_index)
|
|
|
|
|
{
|
|
|
|
|
const int num_face_vertices = topology_refiner->getNumFaceVertices(topology_refiner, face_index);
|
|
|
|
|
if (num_face_vertices == 4) {
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
return num_face_vertices;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int getNumPtexFaces(const OpenSubdiv_TopologyRefiner *topology_refiner)
|
|
|
|
|
{
|
|
|
|
|
const int num_faces = topology_refiner->getNumFaces(topology_refiner);
|
|
|
|
|
int num_ptex_faces = 0;
|
|
|
|
|
for (int face_index = 0; face_index < num_faces; ++face_index) {
|
|
|
|
|
num_ptex_faces += topology_refiner->getNumFacePtexFaces(topology_refiner, face_index);
|
|
|
|
|
}
|
|
|
|
|
return num_ptex_faces;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void fillFacePtexIndexOffset(const OpenSubdiv_TopologyRefiner *topology_refiner,
|
|
|
|
|
int *face_ptex_index_offset)
|
|
|
|
|
{
|
|
|
|
|
const int num_faces = topology_refiner->getNumFaces(topology_refiner);
|
|
|
|
|
int num_ptex_faces = 0;
|
|
|
|
|
for (int face_index = 0; face_index < num_faces; ++face_index) {
|
|
|
|
|
face_ptex_index_offset[face_index] = num_ptex_faces;
|
|
|
|
|
num_ptex_faces += topology_refiner->getNumFacePtexFaces(topology_refiner, face_index);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-15 14:00:57 +01:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2018-07-17 18:06:32 +02:00
|
|
|
// Face-varying data.
|
|
|
|
|
|
|
|
|
|
int getNumFVarChannels(const struct OpenSubdiv_TopologyRefiner *topology_refiner)
|
|
|
|
|
{
|
2020-05-19 11:36:06 +02:00
|
|
|
const OpenSubdiv::Far::TopologyLevel &base_level = getOSDTopologyBaseLevel(topology_refiner);
|
|
|
|
|
return base_level.GetNumFVarChannels();
|
2018-07-17 18:06:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
OpenSubdiv_FVarLinearInterpolation getFVarLinearInterpolation(
|
|
|
|
|
const struct OpenSubdiv_TopologyRefiner *topology_refiner)
|
|
|
|
|
{
|
2020-05-18 17:25:07 +02:00
|
|
|
return blender::opensubdiv::getCAPIFVarLinearInterpolationFromOSD(
|
2018-07-17 18:06:32 +02:00
|
|
|
getOSDTopologyRefiner(topology_refiner)->GetFVarLinearInterpolation());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int getNumFVarValues(const struct OpenSubdiv_TopologyRefiner *topology_refiner, const int channel)
|
|
|
|
|
{
|
2020-05-19 11:36:06 +02:00
|
|
|
const OpenSubdiv::Far::TopologyLevel &base_level = getOSDTopologyBaseLevel(topology_refiner);
|
|
|
|
|
return base_level.GetNumFVarValues(channel);
|
2018-07-17 18:06:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const int *getFaceFVarValueIndices(const struct OpenSubdiv_TopologyRefiner *topology_refiner,
|
|
|
|
|
const int face_index,
|
|
|
|
|
const int channel)
|
|
|
|
|
{
|
2020-05-19 11:36:06 +02:00
|
|
|
const OpenSubdiv::Far::TopologyLevel &base_level = getOSDTopologyBaseLevel(topology_refiner);
|
|
|
|
|
return &base_level.GetFaceFVarValues(face_index, channel)[0];
|
2018-07-17 18:06:32 +02:00
|
|
|
}
|
|
|
|
|
|
2019-01-15 14:00:57 +01:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2018-07-17 18:06:32 +02:00
|
|
|
// Internal helpers.
|
|
|
|
|
|
OpenSubdiv: Re-work C-API integration
Main goal is to make API simpler to follow (at least ion terms what
is defined/declared where, as opposite of handful big headers which
includes all the declarations), and also avoid a big set of long and
obscure functions.
Now C-API files are split into smaller ones, following OpenSubdiv
behavior more closely, and also function pointers in structures
used a lot more, which shortens functions names,
UV integration part in GL Mesh is mainly stripped away, it needs
to be done differently. On a related topic, UV coordinates API in
converter needs to be removed as well, we do not need coordinates,
only island connectivity information there.
Additional changes:
- Varying interpolation in evaluator API are temporarily disabled,
need to extend API somewhere (probably, evaluator's API) to inform
layout information of vertex data (whether it contains varying
data, width, stride and such).
- Evaluator now can interpolate face-varying data.
Only works for adaptive refiner, since some issues in OpenSubdiv
itself.
Planned changes:
- Remove uv coordinates from TopologyConverter.
- Support evaluation of patches (as opposite to individual coordinates
as it happens currently).
- Support more flexible layout of varying and face-varying data.
It is stupid to assume varying is 3 floats and face-varying 2 floats.
- Support of second order derivatives.
- Everything else what i'm missing in this list.
2018-07-16 09:28:05 +02:00
|
|
|
void assignFunctionPointers(OpenSubdiv_TopologyRefiner *topology_refiner)
|
|
|
|
|
{
|
|
|
|
|
topology_refiner->getSubdivisionLevel = getSubdivisionLevel;
|
|
|
|
|
topology_refiner->getIsAdaptive = getIsAdaptive;
|
2018-07-17 18:06:32 +02:00
|
|
|
// Basic topology information.
|
OpenSubdiv: Re-work C-API integration
Main goal is to make API simpler to follow (at least ion terms what
is defined/declared where, as opposite of handful big headers which
includes all the declarations), and also avoid a big set of long and
obscure functions.
Now C-API files are split into smaller ones, following OpenSubdiv
behavior more closely, and also function pointers in structures
used a lot more, which shortens functions names,
UV integration part in GL Mesh is mainly stripped away, it needs
to be done differently. On a related topic, UV coordinates API in
converter needs to be removed as well, we do not need coordinates,
only island connectivity information there.
Additional changes:
- Varying interpolation in evaluator API are temporarily disabled,
need to extend API somewhere (probably, evaluator's API) to inform
layout information of vertex data (whether it contains varying
data, width, stride and such).
- Evaluator now can interpolate face-varying data.
Only works for adaptive refiner, since some issues in OpenSubdiv
itself.
Planned changes:
- Remove uv coordinates from TopologyConverter.
- Support evaluation of patches (as opposite to individual coordinates
as it happens currently).
- Support more flexible layout of varying and face-varying data.
It is stupid to assume varying is 3 floats and face-varying 2 floats.
- Support of second order derivatives.
- Everything else what i'm missing in this list.
2018-07-16 09:28:05 +02:00
|
|
|
topology_refiner->getNumVertices = getNumVertices;
|
|
|
|
|
topology_refiner->getNumEdges = getNumEdges;
|
|
|
|
|
topology_refiner->getNumFaces = getNumFaces;
|
|
|
|
|
topology_refiner->getNumFaceVertices = getNumFaceVertices;
|
2018-09-20 11:45:22 +02:00
|
|
|
topology_refiner->getFaceVertices = getFaceVertices;
|
|
|
|
|
topology_refiner->getNumFaceEdges = getNumFaceEdges;
|
|
|
|
|
topology_refiner->getFaceEdges = getFaceEdges;
|
|
|
|
|
topology_refiner->getEdgeVertices = getEdgeVertices;
|
2019-10-02 12:37:44 +02:00
|
|
|
topology_refiner->getNumVertexEdges = getNumVertexEdges;
|
|
|
|
|
topology_refiner->getVertexEdges = getVertexEdges;
|
2018-07-17 18:06:32 +02:00
|
|
|
// PTex face geometry.
|
OpenSubdiv: Re-work C-API integration
Main goal is to make API simpler to follow (at least ion terms what
is defined/declared where, as opposite of handful big headers which
includes all the declarations), and also avoid a big set of long and
obscure functions.
Now C-API files are split into smaller ones, following OpenSubdiv
behavior more closely, and also function pointers in structures
used a lot more, which shortens functions names,
UV integration part in GL Mesh is mainly stripped away, it needs
to be done differently. On a related topic, UV coordinates API in
converter needs to be removed as well, we do not need coordinates,
only island connectivity information there.
Additional changes:
- Varying interpolation in evaluator API are temporarily disabled,
need to extend API somewhere (probably, evaluator's API) to inform
layout information of vertex data (whether it contains varying
data, width, stride and such).
- Evaluator now can interpolate face-varying data.
Only works for adaptive refiner, since some issues in OpenSubdiv
itself.
Planned changes:
- Remove uv coordinates from TopologyConverter.
- Support evaluation of patches (as opposite to individual coordinates
as it happens currently).
- Support more flexible layout of varying and face-varying data.
It is stupid to assume varying is 3 floats and face-varying 2 floats.
- Support of second order derivatives.
- Everything else what i'm missing in this list.
2018-07-16 09:28:05 +02:00
|
|
|
topology_refiner->getNumFacePtexFaces = getNumFacePtexFaces;
|
|
|
|
|
topology_refiner->getNumPtexFaces = getNumPtexFaces;
|
|
|
|
|
topology_refiner->fillFacePtexIndexOffset = fillFacePtexIndexOffset;
|
2018-07-17 18:06:32 +02:00
|
|
|
// Face-varying data.
|
|
|
|
|
topology_refiner->getNumFVarChannels = getNumFVarChannels;
|
|
|
|
|
topology_refiner->getFVarLinearInterpolation = getFVarLinearInterpolation;
|
|
|
|
|
topology_refiner->getNumFVarValues = getNumFVarValues;
|
|
|
|
|
topology_refiner->getFaceFVarValueIndices = getFaceFVarValueIndices;
|
OpenSubdiv: Re-work C-API integration
Main goal is to make API simpler to follow (at least ion terms what
is defined/declared where, as opposite of handful big headers which
includes all the declarations), and also avoid a big set of long and
obscure functions.
Now C-API files are split into smaller ones, following OpenSubdiv
behavior more closely, and also function pointers in structures
used a lot more, which shortens functions names,
UV integration part in GL Mesh is mainly stripped away, it needs
to be done differently. On a related topic, UV coordinates API in
converter needs to be removed as well, we do not need coordinates,
only island connectivity information there.
Additional changes:
- Varying interpolation in evaluator API are temporarily disabled,
need to extend API somewhere (probably, evaluator's API) to inform
layout information of vertex data (whether it contains varying
data, width, stride and such).
- Evaluator now can interpolate face-varying data.
Only works for adaptive refiner, since some issues in OpenSubdiv
itself.
Planned changes:
- Remove uv coordinates from TopologyConverter.
- Support evaluation of patches (as opposite to individual coordinates
as it happens currently).
- Support more flexible layout of varying and face-varying data.
It is stupid to assume varying is 3 floats and face-varying 2 floats.
- Support of second order derivatives.
- Everything else what i'm missing in this list.
2018-07-16 09:28:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
OpenSubdiv_TopologyRefiner *allocateTopologyRefiner()
|
|
|
|
|
{
|
|
|
|
|
OpenSubdiv_TopologyRefiner *topology_refiner = OBJECT_GUARDED_NEW(OpenSubdiv_TopologyRefiner);
|
|
|
|
|
assignFunctionPointers(topology_refiner);
|
|
|
|
|
return topology_refiner;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
|
|
OpenSubdiv_TopologyRefiner *openSubdiv_createTopologyRefinerFromConverter(
|
|
|
|
|
OpenSubdiv_Converter *converter, const OpenSubdiv_TopologyRefinerSettings *settings)
|
|
|
|
|
{
|
2020-05-19 10:13:16 +02:00
|
|
|
using blender::opensubdiv::TopologyRefinerImpl;
|
|
|
|
|
|
|
|
|
|
TopologyRefinerImpl *topology_refiner_impl = TopologyRefinerImpl::createFromConverter(converter,
|
|
|
|
|
*settings);
|
|
|
|
|
if (topology_refiner_impl == nullptr) {
|
|
|
|
|
return nullptr;
|
2018-07-17 18:06:32 +02:00
|
|
|
}
|
2020-05-19 10:13:16 +02:00
|
|
|
|
2018-07-17 18:06:32 +02:00
|
|
|
OpenSubdiv_TopologyRefiner *topology_refiner = allocateTopologyRefiner();
|
2020-05-19 10:13:16 +02:00
|
|
|
topology_refiner->impl = static_cast<OpenSubdiv_TopologyRefinerImpl *>(topology_refiner_impl);
|
|
|
|
|
|
OpenSubdiv: Re-work C-API integration
Main goal is to make API simpler to follow (at least ion terms what
is defined/declared where, as opposite of handful big headers which
includes all the declarations), and also avoid a big set of long and
obscure functions.
Now C-API files are split into smaller ones, following OpenSubdiv
behavior more closely, and also function pointers in structures
used a lot more, which shortens functions names,
UV integration part in GL Mesh is mainly stripped away, it needs
to be done differently. On a related topic, UV coordinates API in
converter needs to be removed as well, we do not need coordinates,
only island connectivity information there.
Additional changes:
- Varying interpolation in evaluator API are temporarily disabled,
need to extend API somewhere (probably, evaluator's API) to inform
layout information of vertex data (whether it contains varying
data, width, stride and such).
- Evaluator now can interpolate face-varying data.
Only works for adaptive refiner, since some issues in OpenSubdiv
itself.
Planned changes:
- Remove uv coordinates from TopologyConverter.
- Support evaluation of patches (as opposite to individual coordinates
as it happens currently).
- Support more flexible layout of varying and face-varying data.
It is stupid to assume varying is 3 floats and face-varying 2 floats.
- Support of second order derivatives.
- Everything else what i'm missing in this list.
2018-07-16 09:28:05 +02:00
|
|
|
return topology_refiner;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void openSubdiv_deleteTopologyRefiner(OpenSubdiv_TopologyRefiner *topology_refiner)
|
|
|
|
|
{
|
2020-05-19 09:42:05 +02:00
|
|
|
delete topology_refiner->impl;
|
OpenSubdiv: Re-work C-API integration
Main goal is to make API simpler to follow (at least ion terms what
is defined/declared where, as opposite of handful big headers which
includes all the declarations), and also avoid a big set of long and
obscure functions.
Now C-API files are split into smaller ones, following OpenSubdiv
behavior more closely, and also function pointers in structures
used a lot more, which shortens functions names,
UV integration part in GL Mesh is mainly stripped away, it needs
to be done differently. On a related topic, UV coordinates API in
converter needs to be removed as well, we do not need coordinates,
only island connectivity information there.
Additional changes:
- Varying interpolation in evaluator API are temporarily disabled,
need to extend API somewhere (probably, evaluator's API) to inform
layout information of vertex data (whether it contains varying
data, width, stride and such).
- Evaluator now can interpolate face-varying data.
Only works for adaptive refiner, since some issues in OpenSubdiv
itself.
Planned changes:
- Remove uv coordinates from TopologyConverter.
- Support evaluation of patches (as opposite to individual coordinates
as it happens currently).
- Support more flexible layout of varying and face-varying data.
It is stupid to assume varying is 3 floats and face-varying 2 floats.
- Support of second order derivatives.
- Everything else what i'm missing in this list.
2018-07-16 09:28:05 +02:00
|
|
|
OBJECT_GUARDED_DELETE(topology_refiner, OpenSubdiv_TopologyRefiner);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool openSubdiv_topologyRefinerCompareWithConverter(
|
|
|
|
|
const OpenSubdiv_TopologyRefiner *topology_refiner, const OpenSubdiv_Converter *converter)
|
|
|
|
|
{
|
2020-05-19 12:02:54 +02:00
|
|
|
return topology_refiner->impl->isEqualToConverter(converter);
|
OpenSubdiv: Re-work C-API integration
Main goal is to make API simpler to follow (at least ion terms what
is defined/declared where, as opposite of handful big headers which
includes all the declarations), and also avoid a big set of long and
obscure functions.
Now C-API files are split into smaller ones, following OpenSubdiv
behavior more closely, and also function pointers in structures
used a lot more, which shortens functions names,
UV integration part in GL Mesh is mainly stripped away, it needs
to be done differently. On a related topic, UV coordinates API in
converter needs to be removed as well, we do not need coordinates,
only island connectivity information there.
Additional changes:
- Varying interpolation in evaluator API are temporarily disabled,
need to extend API somewhere (probably, evaluator's API) to inform
layout information of vertex data (whether it contains varying
data, width, stride and such).
- Evaluator now can interpolate face-varying data.
Only works for adaptive refiner, since some issues in OpenSubdiv
itself.
Planned changes:
- Remove uv coordinates from TopologyConverter.
- Support evaluation of patches (as opposite to individual coordinates
as it happens currently).
- Support more flexible layout of varying and face-varying data.
It is stupid to assume varying is 3 floats and face-varying 2 floats.
- Support of second order derivatives.
- Everything else what i'm missing in this list.
2018-07-16 09:28:05 +02:00
|
|
|
}
|