PeriDyno 1.0.0
Loading...
Searching...
No Matches
MaterialFunc.h
Go to the documentation of this file.
1//#define STB_IMAGE_IMPLEMENTATION
2//#define STB_IMAGE_WRITE_IMPLEMENTATION
3#include "Node.h"
4#include "stb/stb_image.h"
5
6
7namespace dyno
8{
9 bool loadTexture(const char* path, dyno::CArray2D<dyno::Vec4f>& img)
10 {
11 int x, y, comp;
12 stbi_set_flip_vertically_on_load(true);
13
14 float* data = stbi_loadf(path, &x, &y, &comp, STBI_default);
15
16 if (data) {
17 img.resize(x, y);
18 for (int x0 = 0; x0 < x; x0++)
19 {
20 for (int y0 = 0; y0 < y; y0++)
21 {
22 int idx = (y0 * x + x0) * comp;
23 for (int c0 = 0; c0 < comp; c0++) {
24 img(x0, y0)[c0] = data[idx + c0];
25 }
26 }
27 }
28 delete[] data;
29 }
30
31 return data != 0;
32 }
33
34}
This is an implementation of AdditiveCCD based on peridyno.
Definition Array.h:25
Array2D< T, DeviceType::CPU > CArray2D
Definition Array2D.h:131
bool loadTexture(const char *path, dyno::CArray2D< dyno::Vec4f > &img)
Definition MaterialFunc.h:9