Blender  V2.93
hair.h
Go to the documentation of this file.
1 /*
2  * Copyright 2011-2020 Blender Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef __HAIR_H__
18 #define __HAIR_H__
19 
20 #include "render/geometry.h"
21 
23 
24 class Hair : public Geometry {
25  public:
27 
28  /* Hair Curve */
29  struct Curve {
30  int first_key;
31  int num_keys;
32 
33  int num_segments() const
34  {
35  return num_keys - 1;
36  }
37 
38  void bounds_grow(const int k,
39  const float3 *curve_keys,
40  const float *curve_radius,
41  BoundBox &bounds) const;
42  void bounds_grow(float4 keys[4], BoundBox &bounds) const;
43  void bounds_grow(const int k,
44  const float3 *curve_keys,
45  const float *curve_radius,
46  const Transform &aligned_space,
47  BoundBox &bounds) const;
48 
49  void motion_keys(const float3 *curve_keys,
50  const float *curve_radius,
51  const float3 *key_steps,
52  size_t num_curve_keys,
53  size_t num_steps,
54  float time,
55  size_t k0,
56  size_t k1,
57  float4 r_keys[2]) const;
58  void cardinal_motion_keys(const float3 *curve_keys,
59  const float *curve_radius,
60  const float3 *key_steps,
61  size_t num_curve_keys,
62  size_t num_steps,
63  float time,
64  size_t k0,
65  size_t k1,
66  size_t k2,
67  size_t k3,
68  float4 r_keys[4]) const;
69 
70  void keys_for_step(const float3 *curve_keys,
71  const float *curve_radius,
72  const float3 *key_steps,
73  size_t num_curve_keys,
74  size_t num_steps,
75  size_t step,
76  size_t k0,
77  size_t k1,
78  float4 r_keys[2]) const;
79  void cardinal_keys_for_step(const float3 *curve_keys,
80  const float *curve_radius,
81  const float3 *key_steps,
82  size_t num_curve_keys,
83  size_t num_steps,
84  size_t step,
85  size_t k0,
86  size_t k1,
87  size_t k2,
88  size_t k3,
89  float4 r_keys[4]) const;
90  };
91 
92  NODE_SOCKET_API(array<float3>, curve_keys)
93  NODE_SOCKET_API(array<float>, curve_radius)
94  NODE_SOCKET_API(array<int>, curve_first_key)
95  NODE_SOCKET_API(array<int>, curve_shader)
96 
97  /* BVH */
100 
101  /* Constructor/Destructor */
102  Hair();
103  ~Hair();
104 
105  /* Geometry */
106  void clear(bool preserve_shaders = false) override;
107 
108  void resize_curves(int numcurves, int numkeys);
109  void reserve_curves(int numcurves, int numkeys);
110  void add_curve_key(float3 loc, float radius);
111  void add_curve(int first_key, int shader);
112 
113  void copy_center_to_motion_step(const int motion_step);
114 
115  void compute_bounds() override;
116  void apply_transform(const Transform &tfm, const bool apply_to_motion) override;
117 
118  /* Curves */
119  Curve get_curve(size_t i) const
120  {
121  int first = curve_first_key[i];
122  int next_first = (i + 1 < curve_first_key.size()) ? curve_first_key[i + 1] : curve_keys.size();
123 
124  Curve curve = {first, next_first - first};
125  return curve;
126  }
127 
128  size_t num_keys() const
129  {
130  return curve_keys.size();
131  }
132 
133  size_t num_curves() const
134  {
135  return curve_first_key.size();
136  }
137 
138  size_t num_segments() const
139  {
140  return curve_keys.size() - curve_first_key.size();
141  }
142 
143  /* UDIM */
144  void get_uv_tiles(ustring map, unordered_set<int> &tiles) override;
145 
146  /* BVH */
147  void pack_curves(Scene *scene, float4 *curve_key_co, float4 *curve_data, size_t curvekey_offset);
148 
149  void pack_primitives(PackedBVH *pack,
150  int object,
151  uint visibility,
152  PackFlags pack_flags) override;
153 };
154 
156 
157 #endif /* __HAIR_H__ */
unsigned int uint
Definition: BLI_sys_types.h:83
BoundBox bounds
Definition: geometry.h:87
int motion_step(float time) const
Definition: geometry.cpp:150
double time
Scene scene
Curve curve
PackFlags
Definition: geometry.h:47
#define CCL_NAMESPACE_END
void KERNEL_FUNCTION_FULL_NAME() shader(KernelGlobals *kg, uint4 *input, float4 *output, int type, int filter, int i, int offset, int sample)
CurveShapeType
Definition: kernel_types.h:713
#define NODE_SOCKET_API(type_, name)
Definition: node.h:63
#define NODE_DECLARE
Definition: node_type.h:148
int first_key
Definition: hair.h:30
void keys_for_step(const float3 *curve_keys, const float *curve_radius, const float3 *key_steps, size_t num_curve_keys, size_t num_steps, size_t step, size_t k0, size_t k1, float4 r_keys[2]) const
Definition: hair.cpp:179
void cardinal_motion_keys(const float3 *curve_keys, const float *curve_radius, const float3 *key_steps, size_t num_curve_keys, size_t num_steps, float time, size_t k0, size_t k1, size_t k2, size_t k3, float4 r_keys[4]) const
Definition: hair.cpp:131
int num_segments() const
Definition: hair.h:33
void cardinal_keys_for_step(const float3 *curve_keys, const float *curve_radius, const float3 *key_steps, size_t num_curve_keys, size_t num_steps, size_t step, size_t k0, size_t k1, size_t k2, size_t k3, float4 r_keys[4]) const
Definition: hair.cpp:223
int num_keys
Definition: hair.h:31
void motion_keys(const float3 *curve_keys, const float *curve_radius, const float3 *key_steps, size_t num_curve_keys, size_t num_steps, float time, size_t k0, size_t k1, float4 r_keys[2]) const
Definition: hair.cpp:105
void bounds_grow(const int k, const float3 *curve_keys, const float *curve_radius, BoundBox &bounds) const
Definition: hair.cpp:27
void resize_curves(int numcurves, int numkeys)
Definition: hair.cpp:306
size_t curvekey_offset
Definition: hair.h:98
void pack_curves(Scene *scene, float4 *curve_key_co, float4 *curve_data, size_t curvekey_offset)
Definition: hair.cpp:463
void add_curve(int first_key, int shader)
Definition: hair.cpp:347
float * radius
Curve get_curve(size_t i) const
Definition: hair.h:119
void compute_bounds() override
Definition: hair.cpp:382
void reserve_curves(int numcurves, int numkeys)
Definition: hair.cpp:316
size_t num_curves() const
Definition: hair.h:133
void get_uv_tiles(ustring map, unordered_set< int > &tiles) override
Definition: hair.cpp:366
void copy_center_to_motion_step(const int motion_step)
Definition: hair.cpp:356
size_t num_segments() const
Definition: hair.h:138
CurveShapeType curve_shape
Definition: hair.h:99
void clear(bool preserve_shaders=false) override
Definition: hair.cpp:326
void pack_primitives(PackedBVH *pack, int object, uint visibility, PackFlags pack_flags) override
Definition: hair.cpp:497
size_t num_keys() const
Definition: hair.h:128
void apply_transform(const Transform &tfm, const bool apply_to_motion) override
Definition: hair.cpp:425
void add_curve_key(float3 loc, float radius)
Definition: hair.cpp:338
bool override
Definition: wm_files.c:854