2023-05-31 16:19:06 +02:00
|
|
|
/* SPDX-FileCopyrightText: 2012 by Nicholas Bishop. All rights reserved.
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: GPL-2.0-or-later */
|
2012-05-10 22:32:51 +02:00
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2019-02-17 22:08:12 +01:00
|
|
|
/** \file
|
|
|
|
* \ingroup bke
|
2013-09-12 05:02:50 +02:00
|
|
|
*/
|
|
|
|
|
2012-05-10 22:32:51 +02:00
|
|
|
/* defines BLI_INLINE */
|
2018-11-07 02:17:58 +01:00
|
|
|
#include "BLI_compiler_compat.h"
|
2012-05-10 22:32:51 +02:00
|
|
|
|
2012-05-11 07:27:23 +02:00
|
|
|
/* declares fprintf() and abort(), needed for BLI_assert */
|
2012-05-10 22:32:51 +02:00
|
|
|
#include <stdio.h>
|
2012-05-11 07:27:23 +02:00
|
|
|
#include <stdlib.h>
|
2012-05-10 22:32:51 +02:00
|
|
|
|
2020-03-02 15:07:49 +01:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2012-05-10 22:32:51 +02:00
|
|
|
struct CCGSubSurf;
|
|
|
|
|
|
|
|
/* Each CCGElem is CCGSubSurf's representation of a subdivided
|
2012-05-17 01:37:23 +02:00
|
|
|
* vertex. All CCGElems in a particular CCGSubSurf have the same
|
|
|
|
* layout, but the layout can vary from one CCGSubSurf to another. For
|
|
|
|
* this reason, CCGElem is presented as an opaque pointer, and
|
|
|
|
* elements should always be accompanied by a CCGKey, which provides
|
|
|
|
* the necessary offsets to access components of a CCGElem.
|
2012-05-12 22:39:39 +02:00
|
|
|
*/
|
2012-05-10 22:32:51 +02:00
|
|
|
typedef struct CCGElem CCGElem;
|
|
|
|
|
|
|
|
typedef struct CCGKey {
|
|
|
|
int level;
|
|
|
|
|
|
|
|
/* number of bytes in each element (one float per layer, plus
|
2012-05-17 01:37:23 +02:00
|
|
|
* three floats for normals if enabled) */
|
2012-05-10 22:32:51 +02:00
|
|
|
int elem_size;
|
|
|
|
|
|
|
|
/* number of elements along each side of grid */
|
|
|
|
int grid_size;
|
|
|
|
/* number of elements in the grid (grid size squared) */
|
|
|
|
int grid_area;
|
|
|
|
/* number of bytes in each grid (grid_area * elem_size) */
|
|
|
|
int grid_bytes;
|
|
|
|
|
|
|
|
/* currently always the last three floats, unless normals are
|
2012-05-17 01:37:23 +02:00
|
|
|
* disabled */
|
2012-05-10 22:32:51 +02:00
|
|
|
int normal_offset;
|
|
|
|
|
|
|
|
/* offset in bytes of mask value; only valid if 'has_mask' is
|
2012-05-17 01:37:23 +02:00
|
|
|
* true */
|
2012-05-10 22:32:51 +02:00
|
|
|
int mask_offset;
|
|
|
|
|
|
|
|
int has_normals;
|
|
|
|
int has_mask;
|
|
|
|
} CCGKey;
|
|
|
|
|
|
|
|
/* initialize 'key' at the specified level */
|
|
|
|
void CCG_key(CCGKey *key, const struct CCGSubSurf *ss, int level);
|
|
|
|
void CCG_key_top_level(CCGKey *key, const struct CCGSubSurf *ss);
|
|
|
|
|
|
|
|
/* get a pointer to the coordinate, normal, or mask components */
|
|
|
|
BLI_INLINE float *CCG_elem_co(const CCGKey *key, CCGElem *elem);
|
|
|
|
BLI_INLINE float *CCG_elem_no(const CCGKey *key, CCGElem *elem);
|
|
|
|
BLI_INLINE float *CCG_elem_mask(const CCGKey *key, CCGElem *elem);
|
|
|
|
|
|
|
|
/* get the element at 'offset' in an array */
|
|
|
|
BLI_INLINE CCGElem *CCG_elem_offset(const CCGKey *key, CCGElem *elem, int offset);
|
|
|
|
|
|
|
|
/* get the element at coordinate (x,y) in a face-grid array */
|
|
|
|
BLI_INLINE CCGElem *CCG_grid_elem(const CCGKey *key, CCGElem *elem, int x, int y);
|
|
|
|
|
|
|
|
/* combinations of above functions */
|
|
|
|
BLI_INLINE float *CCG_grid_elem_co(const CCGKey *key, CCGElem *elem, int x, int y);
|
|
|
|
BLI_INLINE float *CCG_grid_elem_no(const CCGKey *key, CCGElem *elem, int x, int y);
|
|
|
|
BLI_INLINE float *CCG_grid_elem_mask(const CCGKey *key, CCGElem *elem, int x, int y);
|
|
|
|
BLI_INLINE float *CCG_elem_offset_co(const CCGKey *key, CCGElem *elem, int offset);
|
|
|
|
BLI_INLINE float *CCG_elem_offset_no(const CCGKey *key, CCGElem *elem, int offset);
|
|
|
|
BLI_INLINE float *CCG_elem_offset_mask(const CCGKey *key, CCGElem *elem, int offset);
|
|
|
|
|
|
|
|
/* for iteration, get a pointer to the next element in an array */
|
|
|
|
BLI_INLINE CCGElem *CCG_elem_next(const CCGKey *key, CCGElem *elem);
|
|
|
|
|
|
|
|
/* inline definitions follow */
|
|
|
|
|
2022-12-20 19:51:47 +01:00
|
|
|
BLI_INLINE float *CCG_elem_co(const CCGKey *
|
|
|
|
#ifndef __cplusplus
|
|
|
|
UNUSED(key)
|
|
|
|
#endif
|
|
|
|
,
|
|
|
|
CCGElem *elem)
|
2012-05-10 22:32:51 +02:00
|
|
|
{
|
2012-05-12 22:39:39 +02:00
|
|
|
return (float *)elem;
|
2012-05-10 22:32:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
BLI_INLINE float *CCG_elem_no(const CCGKey *key, CCGElem *elem)
|
|
|
|
{
|
|
|
|
BLI_assert(key->has_normals);
|
2012-05-12 22:39:39 +02:00
|
|
|
return (float *)((char *)elem + key->normal_offset);
|
2012-05-10 22:32:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
BLI_INLINE float *CCG_elem_mask(const CCGKey *key, CCGElem *elem)
|
|
|
|
{
|
|
|
|
BLI_assert(key->has_mask);
|
2012-05-12 22:39:39 +02:00
|
|
|
return (float *)((char *)elem + (key->mask_offset));
|
2012-05-10 22:32:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
BLI_INLINE CCGElem *CCG_elem_offset(const CCGKey *key, CCGElem *elem, int offset)
|
|
|
|
{
|
2012-05-12 22:39:39 +02:00
|
|
|
return (CCGElem *)(((char *)elem) + key->elem_size * offset);
|
2012-05-10 22:32:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
BLI_INLINE CCGElem *CCG_grid_elem(const CCGKey *key, CCGElem *elem, int x, int y)
|
|
|
|
{
|
2013-03-17 11:26:23 +01:00
|
|
|
// BLI_assert(x < key->grid_size && y < key->grid_size);
|
2012-05-10 22:32:51 +02:00
|
|
|
return CCG_elem_offset(key, elem, (y * key->grid_size + x));
|
|
|
|
}
|
|
|
|
|
|
|
|
BLI_INLINE float *CCG_grid_elem_co(const CCGKey *key, CCGElem *elem, int x, int y)
|
|
|
|
{
|
|
|
|
return CCG_elem_co(key, CCG_grid_elem(key, elem, x, y));
|
|
|
|
}
|
|
|
|
|
|
|
|
BLI_INLINE float *CCG_grid_elem_no(const CCGKey *key, CCGElem *elem, int x, int y)
|
|
|
|
{
|
|
|
|
return CCG_elem_no(key, CCG_grid_elem(key, elem, x, y));
|
|
|
|
}
|
|
|
|
|
|
|
|
BLI_INLINE float *CCG_grid_elem_mask(const CCGKey *key, CCGElem *elem, int x, int y)
|
|
|
|
{
|
|
|
|
return CCG_elem_mask(key, CCG_grid_elem(key, elem, x, y));
|
|
|
|
}
|
|
|
|
|
|
|
|
BLI_INLINE float *CCG_elem_offset_co(const CCGKey *key, CCGElem *elem, int offset)
|
|
|
|
{
|
|
|
|
return CCG_elem_co(key, CCG_elem_offset(key, elem, offset));
|
|
|
|
}
|
|
|
|
|
|
|
|
BLI_INLINE float *CCG_elem_offset_no(const CCGKey *key, CCGElem *elem, int offset)
|
|
|
|
{
|
|
|
|
return CCG_elem_no(key, CCG_elem_offset(key, elem, offset));
|
|
|
|
}
|
|
|
|
|
|
|
|
BLI_INLINE float *CCG_elem_offset_mask(const CCGKey *key, CCGElem *elem, int offset)
|
|
|
|
{
|
|
|
|
return CCG_elem_mask(key, CCG_elem_offset(key, elem, offset));
|
|
|
|
}
|
|
|
|
|
|
|
|
BLI_INLINE CCGElem *CCG_elem_next(const CCGKey *key, CCGElem *elem)
|
|
|
|
{
|
|
|
|
return CCG_elem_offset(key, elem, 1);
|
|
|
|
}
|
|
|
|
|
2020-03-02 15:07:49 +01:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|