njin
Engine 2D gọn nhẹ để tự tay làm game theo ý mình. Vibe coding cũng ổn luôn
Loading...
Searching...
No Matches
njin_3d.h
1#pragma once
2#include "_math.h"
3#include "njin_particles.h"
4
5namespace njin {
6struct context;
7
10
15struct camera3d {
16 vec3 position{0.0f, 0.0f, 0.0f};
17 vec3 target{0.0f, 0.0f, -1.0f};
18 vec3 up{0.0f, 1.0f, 0.0f};
19 f32 fovy = 60.0f;
20 f32 near_plane = 0.05f;
21 f32 far_plane = 1000.0f;
25 bool entities = true;
26};
27
41void begin_3d(context &ctx, const camera3d &camera);
42
57void begin_3d(context &ctx, const camera3d &camera, render_texture_handle target, rgba clear);
58
64void end_3d(context &ctx);
65
72struct light3d {
73 vec3 direction{-0.4f, -1.0f, -0.3f};
74 rgba color{1.0f, 1.0f, 1.0f, 1.0f};
75 rgba ambient{0.35f, 0.35f, 0.4f, 1.0f};
78 bool shadows = false;
87 rgba fog_color{0.6f, 0.65f, 0.75f, 1.0f};
91};
92
96void light3d_set(context &ctx, const light3d &light);
97
101light3d light3d_get(const context &ctx);
102
108
116 vec3 position{0.0f, 0.0f, 0.0f};
117 vec3 direction{0.0f, -1.0f, 0.0f};
118 rgba color{1.0f, 1.0f, 1.0f, 1.0f};
119 f32 intensity = 1.0f;
120 f32 radius = 10.0f;
121 f32 cone = 60.0f;
122 f32 softness = 0.25f;
127 bool shadows = false;
128};
129
131inline constexpr i32 light3d_max = 16;
132
134inline constexpr i32 light3d_shadow_max = 4;
135
140void light3d_add(context &ctx, const light3d_source &light);
141
144 f32 specular = 0.25f;
145 f32 shininess = 32.0f;
148 rgba emission{0.0f, 0.0f, 0.0f, 0.0f};
151 rgba rim{0.0f, 0.0f, 0.0f, 0.0f};
152 bool unlit = false;
156 bool cast_shadows = true;
159 f32 clay = 0.0f;
173 f32 world_uv = 0.0f;
186 f32 reflect = 0.0f;
187};
188
194void material3d_set(context &ctx, const material3d &material);
195
213void draw_cube3d(const context &ctx, vec3 center, vec3 size, rgba color);
214
220void draw_sphere3d(const context &ctx, vec3 center, f32 radius, rgba color);
221
227void draw_plane3d(const context &ctx, vec3 center, vec2 size, rgba color);
228
235void draw_cylinder3d(const context &ctx, vec3 from, vec3 to, f32 radius, rgba color);
236
245void draw_capsule3d(const context &ctx, vec3 from, vec3 to, f32 radius, rgba color);
246
255
263struct shape3d {
265 vec3 position{0.0f, 0.0f, 0.0f};
266 vec3 rotation{0.0f, 0.0f, 0.0f};
267 vec3 size{1.0f, 1.0f, 1.0f};
268 f32 radius = 0.5f;
269 f32 height = 1.0f;
270 f32 thickness = 0.15f;
271 f32 rounding = 0.0f;
272};
273
288void draw_shape3d(const context &ctx, const shape3d &shape, rgba color);
289
293struct sdf_part {
294 vec3 a{0.0f, 0.0f, 0.0f};
295 vec3 b{0.0f, 0.0f, 0.0f};
296 f32 ra = 0.1f;
297 f32 rb = 0.1f;
302 f32 blend = -1.0f;
303};
304
306inline constexpr u32 sdf_blend_max = 32;
307
330void draw_sdf_blend(const context &ctx, const sdf_part *parts, u32 count, f32 blend, rgba color);
331
339model_handle model_load(context &ctx, const char *path);
340
347 const char *path = nullptr;
348 const char *const *skip_nodes = nullptr;
350 const char *const *only_nodes = nullptr;
355 bool merge = false;
356};
357
372model_handle model_load(context &ctx, const model_load_desc &desc);
373
377void model_unload(context &ctx, model_handle handle);
378
382 const vec3 *positions = nullptr;
385 const vec3 *normals = nullptr;
386 const rgba *colors = nullptr;
390 const vec2 *texcoords = nullptr;
395 const u32 *indices = nullptr;
397};
398
412model_handle model_create(context &ctx, const mesh3d_data &mesh);
413
419 const vec3 *positions = nullptr;
421 const vec3 *normals = nullptr;
425 const vec2 *texcoords = nullptr;
429 const u8 *joints = nullptr;
430 const f32 *weights = nullptr;
432 const u32 *indices = nullptr;
438 const u32 *part_ends = nullptr;
446};
447
467
471 f32 ratio = 0.5f;
474 f32 max_error = 0.05f;
477 f32 screen = 0.25f;
478};
479
497i32 model_lod_build(context &ctx, model_handle handle, const model_lod_desc &desc = {});
498
505 vec3 position{0.0f, 0.0f, 0.0f};
506 vec3 rotation{0.0f, 0.0f, 0.0f};
507 vec3 scale{1.0f, 1.0f, 1.0f};
508};
509
533
538i32 model_material_count(const context &ctx, model_handle handle);
539
547i32 model_material_find(const context &ctx, model_handle handle, const char *name);
548
554model_material model_material_get(const context &ctx, model_handle handle, i32 index);
555
569void model_material_set(context &ctx, model_handle handle, i32 index, const model_material &material);
570
583void draw_model(const context &ctx, model_handle handle, const transform3d &transform,
584 rgba tint = colors::white);
585
592i32 model_anim_count(const context &ctx, model_handle handle);
593
599i32 model_anim_find(const context &ctx, model_handle handle, const char *name);
600
606const char *model_anim_name(const context &ctx, model_handle handle, i32 index);
607
613f32 model_anim_duration(const context &ctx, model_handle handle, i32 index);
614
615struct bone_pose3d;
616
621 i32 anim = -1;
622 f32 time = 0.0f;
623 bool loop = true;
626 bool blend_loop = true;
627 f32 blend = 0.0f;
633 const bone_pose3d *bones = nullptr;
639 const f32 *morph_weights = nullptr;
641};
642
662void draw_model_anim(const context &ctx, model_handle handle, const transform3d &transform, const model_pose &pose,
663 rgba tint = colors::white);
664
668 rgba color{1.0f, 1.0f, 1.0f, 1.0f};
669};
670
688void draw_model_anim(const context &ctx, model_handle handle, const transform3d &transform, const model_pose &pose,
689 rgba tint, const model_recolor &recolor);
690
704void draw_model_anim(const context &ctx, model_handle handle, const transform3d &transform, const model_pose &pose,
705 rgba tint, const model_recolor *recolors, u32 count);
706
711i32 model_bone_count(const context &ctx, model_handle handle);
712
718const char *model_bone_name(const context &ctx, model_handle handle, i32 bone);
719
725i32 model_bone_find(const context &ctx, model_handle handle, const char *name);
726
733i32 model_bone_parent(const context &ctx, model_handle handle, i32 bone);
734
755bool model_bone_bounds(const context &ctx, model_handle handle, i32 bone, bool children, vec3 *min, vec3 *max);
756
767i32 model_bone_points(const context &ctx, model_handle handle, i32 bone, bool children, vec3 *out, i32 count);
768
772 vec3 position{0.0f, 0.0f, 0.0f};
773 vec3 x_axis{1.0f, 0.0f, 0.0f};
774 vec3 y_axis{0.0f, 1.0f, 0.0f};
775 vec3 z_axis{0.0f, 0.0f, 1.0f};
776};
777
794i32 model_morph_count(const context &ctx, model_handle handle);
795
802const char *model_morph_name(const context &ctx, model_handle handle, i32 morph);
803
809i32 model_morph_find(const context &ctx, model_handle handle, const char *name);
810
820i32 model_morph_weights(const context &ctx, model_handle handle, const model_pose &pose, f32 *out, i32 count);
821
837bone_pose3d model_bone_pose(const context &ctx, model_handle handle, const model_pose &pose, i32 bone);
838
841struct ray3d {
842 vec3 origin{0.0f, 0.0f, 0.0f};
843 vec3 direction{0.0f, 0.0f, -1.0f};
844};
845
847struct ray3d_hit {
848 bool hit = false;
849 f32 distance = 0.0f;
850 vec3 point{0.0f, 0.0f, 0.0f};
851 vec3 normal{0.0f, 0.0f, 0.0f};
852};
853
861ray3d camera3d_ray(const context &ctx, const camera3d &camera, vec2 screen);
862
870vec2 camera3d_to_screen(const context &ctx, const camera3d &camera, vec3 point, bool *visible = nullptr);
871
878ray3d_hit ray3d_box(const ray3d &ray, vec3 center, vec3 size);
879
885ray3d_hit ray3d_sphere(const ray3d &ray, vec3 center, f32 radius);
886
892ray3d_hit ray3d_plane(const ray3d &ray, vec3 point, vec3 normal);
893
898ray3d_hit ray3d_shape(const ray3d &ray, const shape3d &shape);
899
907ray3d_hit ray3d_model(const context &ctx, const ray3d &ray, model_handle model, const transform3d &transform);
908
919ray3d_hit ray3d_model(const context &ctx, const ray3d &ray, model_handle model, const transform3d &transform,
920 const model_pose &pose);
921
935
958void draw_instanced3d(const context &ctx, mesh3d_kind mesh, instance_buffer_handle buffer, u32 first, u32 count,
959 shader_handle shader = {});
960
973void draw_instanced3d(const context &ctx, model_handle model, instance_buffer_handle buffer, u32 first, u32 count,
974 shader_handle shader = {});
975
994void draw_instanced3d(const context &ctx, model_handle model, instance_buffer_handle buffer, u32 first, u32 count,
995 const model_pose &pose, shader_handle shader = {});
996
1003struct fx3d {
1006 rgba flash{1.0f, 1.0f, 1.0f, 0.0f};
1010 rgba edge_color{1.0f, 0.55f, 0.1f, 1.0f};
1011 f32 edge_width = 0.08f;
1012 f32 grain = 0.1f;
1013 f32 seed = 0.0f;
1021 vec3 mask_center{0.0f, 0.0f, 0.0f};
1023};
1024
1036void fx3d_set(context &ctx, const fx3d &fx);
1037
1042 vec3 direction{0.0f, 1.0f, 0.0f};
1046 f32 scale = 0.02f;
1047};
1048
1062void particles3d_spawn(context &ctx, const particle_emitter &emitter, vec3 pos, i32 count,
1063 const particles3d_desc &desc = {});
1064
1067void particles3d_clear(context &ctx);
1068
1072i32 particles3d_count(const context &ctx);
1073
1085struct model3d {
1087 rgba tint{1.0f, 1.0f, 1.0f, 1.0f};
1089 f32 speed = 1.0f;
1091 bool visible = true;
1092};
1093
1100 rgba color{1.0f, 1.0f, 1.0f, 1.0f};
1103 bool visible = true;
1104};
1105
1106} // namespace njin
ray3d camera3d_ray(const context &ctx, const camera3d &camera, vec2 screen)
Tia từ camera đi qua một điểm trên màn hình, để chọn vật dưới chuột: camera3d_ray(ctx,...
ray3d_hit ray3d_model(const context &ctx, const ray3d &ray, model_handle model, const transform3d &transform)
Tia với từng tam giác của một model đặt tại transform, như draw_model() vẽ nó.
i32 model_morph_find(const context &ctx, model_handle handle, const char *name)
Tìm morph theo tên (so đúng cả chuỗi).
i32 model_bone_find(const context &ctx, model_handle handle, const char *name)
Tìm xương theo tên (so đúng cả chuỗi).
void particles3d_clear(context &ctx)
Xóa mọi hạt 3D đang bay, ví dụ khi đổi màn.
constexpr i32 light3d_shadow_max
Số đèn điểm và đèn nón tối đa được đổ bóng trong một lần vẽ 3D.
Definition njin_3d.h:134
i32 model_material_find(const context &ctx, model_handle handle, const char *name)
Tìm vật liệu theo tên đặt trong file glTF.
model_material model_material_get(const context &ctx, model_handle handle, i32 index)
Vật liệu thứ index của model.
i32 model_morph_count(const context &ctx, model_handle handle)
Số morph target (blend shape) của model: các target của glTF (biểu cảm mặt, cơ phồng,...
void model_material_set(context &ctx, model_handle handle, i32 index, const model_material &material)
Đặt vật liệu thứ index của model, cho mọi lần vẽ sau đó.
const char * model_bone_name(const context &ctx, model_handle handle, i32 bone)
Tên một xương, như trong file glTF.
i32 model_morph_weights(const context &ctx, model_handle handle, const model_pose &pose, f32 *out, i32 count)
Trọng số của mọi morph ở tư thế pose, đúng như lần vẽ sẽ dùng (mặc định, animation,...
void draw_model(const context &ctx, model_handle handle, const transform3d &transform, rgba tint=colors::white)
Vẽ model tại transform, với vật liệu của nó (model_material_set()).
i32 model_lod_build(context &ctx, model_handle handle, const model_lod_desc &desc={})
Tạo các mức chi tiết cho model: bản giản lược, ít tam giác hơn, được vẽ thay model khi nó nhỏ trên mà...
light3d light3d_get(const context &ctx)
Ánh sáng chung đang dùng.
i32 model_bone_count(const context &ctx, model_handle handle)
Số xương của model (0 nếu không có xương hay handle không hợp lệ).
void model_unload(context &ctx, model_handle handle)
Giải phóng model cùng các texture của nó.
mesh3d_kind
Hình lưới có sẵn để vẽ nhiều bản một lúc bằng draw_instanced3d().
Definition njin_3d.h:923
void draw_model_anim(const context &ctx, model_handle handle, const transform3d &transform, const model_pose &pose, rgba tint=colors::white)
Vẽ model có xương ở tư thế pose.
light3d_kind
Loại đèn của njin::light3d_source.
Definition njin_3d.h:104
void draw_sdf_blend(const context &ctx, const sdf_part *parts, u32 count, f32 blend, rgba color)
Vẽ nhiều phần SDF hòa làm một khối liền (smooth min): chỗ hai phần gặp nhau được đắp đầy mượt thay vì...
i32 model_material_count(const context &ctx, model_handle handle)
Số vật liệu của model.
void material3d_set(context &ctx, const material3d &material)
Đặt bề mặt cho các hình 3D vẽ sau lệnh này, đến lần gọi tiếp theo hoặc end_3d().
void light3d_set(context &ctx, const light3d &light)
Đặt ánh sáng chung.
bone_pose3d model_bone_pose(const context &ctx, model_handle handle, const model_pose &pose, i32 bone)
Xương bone ở tư thế pose (cùng cách tính với draw_model_anim(), kể cả khi trộn hai animation),...
void light3d_add(context &ctx, const light3d_source &light)
Thêm một đèn cho lần vẽ 3D đang mở.
i32 model_bone_points(const context &ctx, model_handle handle, i32 bone, bool children, vec3 *out, i32 count)
Các đỉnh của phần da đó (như model_bone_bounds()), cùng hệ trục: theo các trục của model ở tư thế gốc...
constexpr i32 light3d_max
Số đèn tối đa trong một lần vẽ 3D. Đèn thêm quá số này bị bỏ qua.
Definition njin_3d.h:131
model_handle model_create(context &ctx, const mesh3d_data &mesh)
Tạo model từ một lưới tam giác trong bộ nhớ, rồi dùng như model nạp từ file: draw_model(),...
i32 particles3d_count(const context &ctx)
Số hạt 3D đang sống.
model_handle model_create_skinned(context &ctx, const skinned_mesh3d_data &mesh)
Tạo model có xương từ một lưới trong bộ nhớ, dùng bộ xương và animation của model khác (một thư viện ...
const char * model_morph_name(const context &ctx, model_handle handle, i32 morph)
Tên của morph thứ morph: tên trong extras.targetNames của file, hoặc "<tên mesh>.<số>" khi file không...
void begin_3d(context &ctx, const camera3d &camera)
Bắt đầu vẽ 3D qua camera.
ray3d_hit ray3d_box(const ray3d &ray, vec3 center, vec3 size)
Tia với hộp có các cạnh song song với trục.
void fx3d_set(context &ctx, const fx3d &fx)
Đặt hiệu ứng cho các hình 3D vẽ sau lệnh này, đến lần gọi tiếp theo hoặc end_3d().
i32 model_bone_parent(const context &ctx, model_handle handle, i32 bone)
Xương cha của bone trong bộ xương, để đi lên chuỗi xương (IK: đùi, cẳng chân, bàn chân) hay biết xươn...
f32 model_anim_duration(const context &ctx, model_handle handle, i32 index)
Độ dài của animation thứ index, giây.
vec2 camera3d_to_screen(const context &ctx, const camera3d &camera, vec3 point, bool *visible=nullptr)
Vị trí trên màn hình của một điểm 3D, để đặt nhãn hay thanh máu trên đầu nhân vật.
void draw_shape3d(const context &ctx, const shape3d &shape, rgba color)
Vẽ một hình SDF mịn.
ray3d_hit ray3d_sphere(const ray3d &ray, vec3 center, f32 radius)
Tia với hình cầu.
void draw_plane3d(const context &ctx, vec3 center, vec2 size, rgba color)
Vẽ mặt phẳng nằm ngang (song song mặt xz), mặt trên hướng +y.
shape3d_kind
Loại hình của njin::shape3d.
Definition njin_3d.h:248
constexpr u32 sdf_blend_max
Số phần tối đa của một hình ghép SDF.
Definition njin_3d.h:306
ray3d_hit ray3d_plane(const ray3d &ray, vec3 point, vec3 normal)
Tia với mặt phẳng vô hạn qua point, pháp tuyến normal.
void draw_sphere3d(const context &ctx, vec3 center, f32 radius, rgba color)
Vẽ hình cầu đặc.
model_handle model_load(context &ctx, const char *path)
Nạp model 3D từ file glTF (.glb, .gltf) hoặc OBJ.
ray3d_hit ray3d_shape(const ray3d &ray, const shape3d &shape)
Tia với một hình SDF, đúng như draw_shape3d() vẽ nó (kể cả khi xoay, bo góc).
bool model_bone_bounds(const context &ctx, model_handle handle, i32 bone, bool children, vec3 *min, vec3 *max)
Hộp bao phần da mà xương bone kéo mạnh nhất (cả các xương con nếu children), ở tư thế gốc trong file:...
void particles3d_spawn(context &ctx, const particle_emitter &emitter, vec3 pos, i32 count, const particles3d_desc &desc={})
Phát một loạt count hạt tại pos, dùng lại một emitter 2D: các mẫu njin::fx (explosion(),...
const char * model_anim_name(const context &ctx, model_handle handle, i32 index)
Tên của animation thứ index.
void draw_cylinder3d(const context &ctx, vec3 from, vec3 to, f32 radius, rgba color)
Vẽ hình trụ đặc nối hai điểm (lưới tam giác).
void draw_cube3d(const context &ctx, vec3 center, vec3 size, rgba color)
Vẽ hộp đặc, các cạnh song song với trục.
void end_3d(context &ctx)
Kết thúc vẽ 3D và quay về vẽ 2D trong không gian thế giới.
i32 model_anim_find(const context &ctx, model_handle handle, const char *name)
Tìm animation theo tên đặt trong Blender (tên action khi xuất glTF).
void draw_instanced3d(const context &ctx, mesh3d_kind mesh, instance_buffer_handle buffer, u32 first, u32 count, shader_handle shader={})
Vẽ count bản của một hình có sẵn bằng một lệnh vẽ, mỗi bản đặt theo dữ liệu của nó trong một bộ đệm i...
i32 model_anim_count(const context &ctx, model_handle handle)
Số animation xương trong file của model (glTF có skin).
void draw_capsule3d(const context &ctx, vec3 from, vec3 to, f32 radius, rgba color)
Vẽ viên nang (capsule) đặc bằng lưới tam giác: hình trụ nối hai điểm, hai đầu tròn.
@ mesh3d_cylinder
Trụ bán kính 1, đáy ở gốc, cao 1 theo +y.
Definition njin_3d.h:927
@ mesh3d_sphere
Cầu bán kính 1, tâm ở gốc.
Definition njin_3d.h:925
@ mesh3d_sphere_low
Như mesh3d_sphere nhưng ít mặt (khoảng 100 tam giác, bản thường khoảng 3000): cho hàng nghìn vật nhỏ ...
Definition njin_3d.h:931
@ mesh3d_plane
Mặt 1 x 1 trên mặt xz, hướng lên +y.
Definition njin_3d.h:926
@ mesh3d_cylinder_low
Như mesh3d_cylinder nhưng 8 cạnh thay vì 48, cùng lý do.
Definition njin_3d.h:933
@ mesh3d_cube
Hộp 1 x 1 x 1, tâm ở gốc.
Definition njin_3d.h:924
@ light3d_point
Đèn điểm: tỏa đều mọi hướng (bóng đèn, đuốc).
Definition njin_3d.h:105
@ light3d_spot
Đèn nón: chiếu theo direction trong một nón (đèn pin, đèn sân khấu).
Definition njin_3d.h:106
@ shape3d_cylinder
Hình trụ dọc trục y: radius, height, bo cạnh theo rounding.
Definition njin_3d.h:252
@ shape3d_box
Hộp: size, bo cạnh theo rounding.
Definition njin_3d.h:250
@ shape3d_torus
Hình xuyến nằm trên mặt xz: radius (tới tâm ống), thickness (bán kính ống).
Definition njin_3d.h:253
@ shape3d_capsule
Viên nang dọc trục y: radius, height (cả hai đầu tròn).
Definition njin_3d.h:251
@ shape3d_sphere
Hình cầu: radius.
Definition njin_3d.h:249
std::uint8_t u8
Số nguyên không dấu 8 bit.
Definition _types.h:20
std::int32_t i32
Số nguyên có dấu 32 bit.
Definition _types.h:14
float f32
Số thực 32 bit.
Definition _types.h:28
std::uint32_t u32
Số nguyên không dấu 32 bit.
Definition _types.h:22
constexpr rgba white
Trắng.
Definition _math.h:234
Các mẫu particle hay dùng, để truyền vào particles_spawn() hoặc gắn thẳng lên entity.
Definition njin_fx.h:147
Một xương ở một tư thế: vị trí và ba trục của nó trong không gian của model (trước transform của lần ...
Definition njin_3d.h:771
vec3 z_axis
Trục z, độ dài 1.
Definition njin_3d.h:775
vec3 x_axis
Trục x của xương, độ dài 1.
Definition njin_3d.h:773
vec3 position
Gốc của xương.
Definition njin_3d.h:772
vec3 y_axis
Trục y (dọc theo xương với rig của Blender), độ dài 1.
Definition njin_3d.h:774
Camera phối cảnh cho begin_3d().
Definition njin_3d.h:15
f32 fovy
Góc nhìn dọc, tính bằng độ.
Definition njin_3d.h:19
bool entities
Vẽ cả các entity 3D (njin::model3d, njin::shape3d_render, đèn njin::light3d_source) trong lần vẽ này.
Definition njin_3d.h:25
vec3 up
Hướng lên của camera.
Definition njin_3d.h:18
f32 far_plane
Khoảng cách xa nhất còn được vẽ.
Definition njin_3d.h:21
vec3 position
Vị trí mắt.
Definition njin_3d.h:16
vec3 target
Điểm camera nhìn vào.
Definition njin_3d.h:17
f32 near_plane
Khoảng cách gần nhất còn được vẽ.
Definition njin_3d.h:20
Hiệu ứng cho các hình 3D vẽ sau fx3d_set(): nháy màu và tan biến, như njin::flash_fx và njin::dissolv...
Definition njin_3d.h:1003
f32 mask_radius
Bán kính chỗ khoét ở mask_center, đơn vị thế giới 3D.
Definition njin_3d.h:1022
f32 dissolve
Mức tan biến, 0..1.
Definition njin_3d.h:1009
rgba flash
Màu tô lên hình, thay màu từng điểm mà vẫn giữ hình dáng (khác tint, chỉ nhân màu).
Definition njin_3d.h:1006
rgba edge_color
Màu viền cháy ở chỗ đang tan. a bằng 0 là bỏ viền.
Definition njin_3d.h:1010
vec3 mask_center
Khoét chỗ che (sphere masking), cho camera góc thứ ba: phần hình nằm giữa camera và mask_center (đơn ...
Definition njin_3d.h:1021
f32 grain
Cỡ mỗi mảng, đơn vị thế giới.
Definition njin_3d.h:1012
f32 edge_width
Độ dày viền, theo thang ngẫu nhiên 0..1.
Definition njin_3d.h:1011
f32 seed
Đổi hình mẫu tan, để hai vật không tan giống hệt nhau.
Definition njin_3d.h:1013
Định danh của một bộ đệm instance, tạo bởi instance_buffer_create().
Definition _types.h:109
Một đèn điểm hoặc đèn nón.
Definition njin_3d.h:114
light3d_kind kind
Loại đèn.
Definition njin_3d.h:115
f32 radius
Tầm với, đơn vị thế giới.
Definition njin_3d.h:120
vec3 direction
Hướng chiếu, chỉ cho đèn nón.
Definition njin_3d.h:117
bool shadows
Đổ bóng, như light3d::shadows của mặt trời, trong tầm radius.
Definition njin_3d.h:127
f32 softness
Phần mép nón mờ dần, 0..1, chỉ cho đèn nón.
Definition njin_3d.h:122
rgba color
Màu.
Definition njin_3d.h:118
f32 cone
Góc mở của nón, độ (cả hai bên), chỉ cho đèn nón.
Definition njin_3d.h:121
vec3 position
Vị trí.
Definition njin_3d.h:116
f32 intensity
Độ sáng, nhân vào màu. Có thể lớn hơn 1.
Definition njin_3d.h:119
Ánh sáng chung của cảnh 3D: mặt trời (ánh sáng hướng), ánh sáng nền, bóng đổ của mặt trời và sương mù...
Definition njin_3d.h:72
i32 shadow_size
Cạnh của ảnh bóng, pixel. Lớn thì sắc hơn, tốn bộ nhớ hơn.
Definition njin_3d.h:82
rgba fog_color
Màu sương mù, thường bằng màu nền.
Definition njin_3d.h:87
rgba color
Màu và cường độ của nắng. Đen là tắt mặt trời.
Definition njin_3d.h:74
rgba ambient
Ánh sáng nền, chiếu đều mọi mặt.
Definition njin_3d.h:75
vec3 direction
Hướng nắng chiếu tới (không cần độ dài 1).
Definition njin_3d.h:73
f32 fog_density
Mật độ sương theo khoảng cách tới camera: độ trong còn exp(-(density * d)^2).
Definition njin_3d.h:90
bool shadows
Mặt trời đổ bóng.
Definition njin_3d.h:78
i32 source_shadow_size
Cạnh ảnh bóng của đèn điểm và đèn nón có light3d_source::shadows, pixel, cho mỗi mặt (đèn điểm có 6 m...
Definition njin_3d.h:86
f32 shadow_softness
Độ mềm mép bóng, tính bằng pixel của ảnh bóng.
Definition njin_3d.h:83
f32 shadow_range
Bóng được tính trong một hình hộp cạnh 2 * shadow_range quanh chỗ camera nhìn.
Definition njin_3d.h:81
Bề mặt của các hình 3D vẽ sau material3d_set().
Definition njin_3d.h:143
rgba emission
Màu tự phát sáng, cộng vào sau khi chiếu sáng; a là độ mạnh.
Definition njin_3d.h:148
texture_handle under_normal
Normal map của lớp dưới, như normal.
Definition njin_3d.h:180
texture_handle texture
Ảnh dán lên hình khối (draw_cube3d(), draw_plane3d()...), nhân với màu vẽ.
Definition njin_3d.h:155
bool unlit
Bỏ qua ánh sáng, giữ nguyên màu (vệt đạn, tia laze, UI trong thế giới).
Definition njin_3d.h:152
f32 reflect
Độ phản chiếu, 0..1, cho phản chiếu trên màn hình (post3d::ssr): 1 là gương ở mọi góc nhìn,...
Definition njin_3d.h:186
texture_handle under
Lớp dưới, chỉ khi world_uv > 0: ảnh màu và normal map của thứ nằm dưới lớp ảnh chính (gạch dưới lớp v...
Definition njin_3d.h:179
f32 specular
Độ mạnh của điểm sáng bóng. 0 là mặt mờ (gỗ, vải).
Definition njin_3d.h:144
f32 clay
Opt-in hand-shaped clay normal/albedo variation for SDF draws only.
Definition njin_3d.h:159
bool cast_shadows
Đổ bóng khi njin::light3d bật shadows.
Definition njin_3d.h:156
rgba rim
Viền sáng ở mép hình, nơi bề mặt quay đi khỏi camera; a là độ mạnh.
Definition njin_3d.h:151
f32 world_uv
Lớn hơn 0: ảnh (texture, normal, và ảnh của vật liệu model) dán theo vị trí trong thế giới thay cho U...
Definition njin_3d.h:173
texture_handle normal
Normal map (tangent space, xanh lá hướng lên như glTF, tức OpenGL +Y) cho hình khối và draw_instanced...
Definition njin_3d.h:164
f32 clay_detail
Grain frequency relative to the largest SDF part radius.
Definition njin_3d.h:160
f32 under_amount
Phần lớp dưới lộ ra, 0 (không) đến 1 (toàn bộ, lớp trên bong hết).
Definition njin_3d.h:182
f32 shininess
Độ nhọn của điểm sáng bóng: lớn là mặt nhẵn (nhựa, kim loại).
Definition njin_3d.h:145
Một lưới tam giác do game tự dựng, cho model_create(): địa hình sinh theo seed, hình ghép lúc chạy.
Definition njin_3d.h:381
const vec3 * normals
Pháp tuyến từng đỉnh (độ dài 1).
Definition njin_3d.h:385
const vec3 * positions
Vị trí vertex_count đỉnh.
Definition njin_3d.h:382
const vec2 * texcoords
Toạ độ ảnh (UV) từng đỉnh, cho ảnh của vật liệu (model_material_set()): một mảnh cắt từ lưới đã có UV...
Definition njin_3d.h:390
u32 index_count
Số chỉ số, bội của 3.
Definition njin_3d.h:396
const rgba * colors
Màu từng đỉnh, nhân với màu vật liệu.
Definition njin_3d.h:386
u32 vertex_count
Số đỉnh.
Definition njin_3d.h:391
const u32 * indices
Ba chỉ số một tam giác, ngược chiều kim đồng hồ khi nhìn từ mặt trước.
Definition njin_3d.h:395
Component: một model vẽ tại njin::transform3d của entity, trong mọi lần vẽ 3D có camera3d::entities (...
Definition njin_3d.h:1085
model_handle model
Model từ model_load().
Definition njin_3d.h:1086
model_pose pose
Tư thế, như draw_model_anim().
Definition njin_3d.h:1088
fx3d fx
Nháy màu và tan biến, như fx3d_set().
Definition njin_3d.h:1090
bool visible
Ẩn mà không cần gỡ component.
Definition njin_3d.h:1091
f32 speed
Tốc độ chạy animation. 0 là dừng.
Definition njin_3d.h:1089
rgba tint
Màu nhân vào màu của model.
Definition njin_3d.h:1087
Định danh của một model 3D, tạo bởi model_load().
Definition _types.h:153
Cách model_load() nạp một phần của file glTF: bỏ hay chỉ giữ một số node, và gộp các mesh cùng vật li...
Definition njin_3d.h:346
u32 skip_count
Số chuỗi trong skip_nodes.
Definition njin_3d.h:349
const char * path
Đường dẫn file, như model_load().
Definition njin_3d.h:347
const char *const * only_nodes
Nếu có: chỉ giữ mesh của node có tên chứa một trong các chuỗi này.
Definition njin_3d.h:350
u32 only_count
Số chuỗi trong only_nodes.
Definition njin_3d.h:351
const char *const * skip_nodes
Bỏ mesh của node có tên chứa một trong các chuỗi này.
Definition njin_3d.h:348
bool merge
Gộp các mesh dùng cùng vật liệu thành một mesh (mỗi mesh tối đa 65535 đỉnh), để draw_instanced3d() vẽ...
Definition njin_3d.h:355
Cách model_lod_build() làm các mức chi tiết (LOD) của một model.
Definition njin_3d.h:469
f32 ratio
Phần tam giác mỗi mức giữ lại so với model gốc, lũy thừa theo mức, 0.1..0.9.
Definition njin_3d.h:471
f32 max_error
Hình được lệch tối đa bao nhiêu, tính theo cỡ của mesh (0.05 là 5%).
Definition njin_3d.h:474
i32 levels
Số mức giản lược, 1..4. Mức k giữ khoảng ratio mũ k số tam giác.
Definition njin_3d.h:470
f32 screen
Mức 1 được vẽ khi model (quả cầu bao nó) cao chưa tới phần này của chiều cao màn hình; mỗi mức sau ở ...
Definition njin_3d.h:477
Vật liệu của một phần model: mỗi file glTF/OBJ có một hay nhiều vật liệu, mỗi mesh dùng một.
Definition njin_3d.h:516
shader_handle shader
Shader riêng cho phần này, như shader_begin() với hình khối, cả khi model vẽ bằng draw_instanced3d() ...
Definition njin_3d.h:525
rgba emission_color
Màu nhân vào ảnh phát sáng (của file hay emission).
Definition njin_3d.h:521
texture_handle emission
Ảnh phát sáng, nhân với emission_color.
Definition njin_3d.h:520
texture_handle normal
Normal map (tangent space, xanh lá hướng lên như glTF).
Definition njin_3d.h:519
bool double_sided
Vẽ cả hai mặt của mỗi tam giác (không bỏ mặt sau), cho lá cây, giấy, vải mỏng một lớp.
Definition njin_3d.h:531
material3d surface
Độ bóng, phát sáng, unlit, đổ bóng, world_uv.
Definition njin_3d.h:528
rgba color
Màu gốc, nhân với ảnh albedo. Mặc định là màu trong file.
Definition njin_3d.h:517
texture_handle albedo
Ảnh màu.
Definition njin_3d.h:518
Tư thế của một model có xương khi vẽ: animation nào, ở giây thứ mấy, và (tùy chọn) trộn với animation...
Definition njin_3d.h:620
const bone_pose3d * bones
Tư thế do game đặt: model_bone_count() xương, trong không gian của model như model_bone_pose() trả về...
Definition njin_3d.h:633
i32 blend_anim
Animation thứ hai để trộn vào. -1 là không trộn.
Definition njin_3d.h:624
const f32 * morph_weights
Trọng số morph target (blend shape) do game đặt, theo chỉ số model_morph_find(): cộng thêm vào trọng ...
Definition njin_3d.h:639
i32 anim
Animation (model_anim_find()). -1 là tư thế gốc trong file.
Definition njin_3d.h:621
f32 blend_time
Thời điểm trong animation thứ hai, giây.
Definition njin_3d.h:625
f32 blend
Tỉ lệ trộn: 0 chỉ có anim, 1 chỉ có blend_anim.
Definition njin_3d.h:627
f32 time
Thời điểm trong animation, giây.
Definition njin_3d.h:622
bool loop
Lặp lại; không thì dừng ở khung cuối.
Definition njin_3d.h:623
bool blend_loop
Lặp animation thứ hai.
Definition njin_3d.h:626
i32 morph_count
Số phần tử của morph_weights.
Definition njin_3d.h:640
Màu thay cho màu gốc của một vật liệu, chỉ trong một lần vẽ.
Definition njin_3d.h:666
rgba color
Màu thay cho njin::model_material::color; độ trong suốt giữ của vật liệu.
Definition njin_3d.h:668
i32 material
Vật liệu (model_material_find()). -1 là không đổi gì.
Definition njin_3d.h:667
Nguồn phát hạt: nổ, bụi, tia lửa, khói.
Definition njin_particles.h:57
Cách đặt một loạt hạt vào thế giới 3D, dùng với particles3d_spawn().
Definition njin_3d.h:1039
f32 scale
Đổi đơn vị của emitter (pixel, như các mẫu njin::fx) sang đơn vị thế giới 3D: nhân vào tốc độ,...
Definition njin_3d.h:1046
vec3 direction
Hướng phát.
Definition njin_3d.h:1042
Kết quả khi tia chạm một vật.
Definition njin_3d.h:847
vec3 point
Điểm chạm.
Definition njin_3d.h:850
vec3 normal
Pháp tuyến của bề mặt tại điểm chạm.
Definition njin_3d.h:851
f32 distance
Khoảng cách từ gốc tia tới điểm chạm.
Definition njin_3d.h:849
bool hit
Tia có chạm không.
Definition njin_3d.h:848
Một tia trong thế giới 3D, dùng để chọn vật bằng chuột, bắn đạn, kiểm tra tầm nhìn.
Definition njin_3d.h:841
vec3 origin
Gốc.
Definition njin_3d.h:842
vec3 direction
Hướng, độ dài 1.
Definition njin_3d.h:843
Định danh của một render texture, tạo bởi render_texture_load().
Definition _types.h:307
Màu gồm đỏ, xanh lá, xanh dương và alpha.
Definition _types.h:64
Một phần của hình ghép SDF (draw_sdf_blend()): hình nón bo tròn nối a với b, bán kính ra ở a và rb ở ...
Definition njin_3d.h:293
f32 blend
Độ mềm chỗ phần này nối vào các phần đứng trước nó trong danh sách, đơn vị thế giới.
Definition njin_3d.h:302
vec3 b
Tâm đầu thứ hai.
Definition njin_3d.h:295
vec3 a
Tâm đầu thứ nhất.
Definition njin_3d.h:294
f32 ra
Bán kính ở a.
Definition njin_3d.h:296
f32 rb
Bán kính ở b.
Definition njin_3d.h:297
Định danh của một shader, tạo bởi shader_load().
Definition _types.h:101
Component: một hình SDF (như draw_shape3d()) vẽ tại njin::transform3d của entity, trong mọi lần vẽ 3D...
Definition njin_3d.h:1098
shape3d shape
Loại hình và kích thước.
Definition njin_3d.h:1099
bool visible
Ẩn mà không cần gỡ component.
Definition njin_3d.h:1103
rgba color
Màu.
Definition njin_3d.h:1100
fx3d fx
Nháy màu và tan biến, như fx3d_set().
Definition njin_3d.h:1102
material3d material
Bề mặt, như material3d_set().
Definition njin_3d.h:1101
Một hình cơ bản vẽ bằng SDF (hàm khoảng cách có dấu), dùng với draw_shape3d().
Definition njin_3d.h:263
vec3 size
Kích thước của hộp theo x, y, z.
Definition njin_3d.h:267
f32 radius
Bán kính (cầu, viên nang, trụ) hoặc bán kính vòng (xuyến).
Definition njin_3d.h:268
vec3 rotation
Góc xoay, độ, cùng thứ tự với njin::transform3d.
Definition njin_3d.h:266
f32 rounding
Bán kính bo cạnh (hộp, trụ). 0 là cạnh sắc.
Definition njin_3d.h:271
f32 height
Chiều cao cả hình theo y (viên nang, trụ).
Definition njin_3d.h:269
f32 thickness
Bán kính ống của hình xuyến.
Definition njin_3d.h:270
shape3d_kind kind
Loại hình.
Definition njin_3d.h:264
vec3 position
Tâm hình.
Definition njin_3d.h:265
Một lưới có xương do game tự ghép lúc chạy, cho model_create_skinned(): nhân vật ghép từ nhiều mảnh (...
Definition njin_3d.h:418
const u32 * part_ends
Chia tam giác thành các phần, mỗi phần một vật liệu (vật liệu k là phần k, màu trắng): chỉ số kết thú...
Definition njin_3d.h:438
const vec3 * positions
Vị trí vertex_count đỉnh, ở tư thế gốc của skeleton.
Definition njin_3d.h:419
const vec3 * normals
Pháp tuyến từng đỉnh (độ dài 1). nullptr thì engine tự tính như model_create().
Definition njin_3d.h:421
model_handle skeleton
Model có xương đã nạp bằng model_load(): model mới chép bộ xương và tư thế gốc của nó,...
Definition njin_3d.h:445
u32 index_count
Số chỉ số, bội của 3.
Definition njin_3d.h:433
u32 part_count
Số phần trong part_ends.
Definition njin_3d.h:439
const vec2 * texcoords
Toạ độ ảnh (UV) từng đỉnh, cho ảnh của vật liệu (model_material_set()): nhân vật có texture riêng vẫn...
Definition njin_3d.h:425
u32 vertex_count
Số đỉnh.
Definition njin_3d.h:426
const u8 * joints
Bốn xương mỗi đỉnh: chỉ số xương của skeleton (model_bone_find()), nên tối đa 255 xương.
Definition njin_3d.h:429
const u32 * indices
Ba chỉ số một tam giác, ngược chiều kim đồng hồ khi nhìn từ mặt trước.
Definition njin_3d.h:432
const f32 * weights
Bốn trọng số mỗi đỉnh, cùng thứ tự joints, cộng lại bằng 1.
Definition njin_3d.h:430
Định danh của một texture, tạo bởi texture_load().
Definition _types.h:146
Vị trí, hướng và tỉ lệ của một vật 3D.
Definition njin_3d.h:504
vec3 scale
Tỉ lệ theo x, y, z.
Definition njin_3d.h:507
vec3 position
Vị trí.
Definition njin_3d.h:505
vec3 rotation
Góc xoay quanh x, y, z, tính bằng độ.
Definition njin_3d.h:506
Vị trí, góc xoay và tỉ lệ của một entity trong thế giới.
Definition _comps.h:14
Vector 2 chiều. Dùng cho vị trí, kích thước, độ dời.
Definition _types.h:39
Vector 3 chiều.
Definition _types.h:47