1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
|
// Shave and a Haircut
// (c) 2019 Epic Games
// US Patent 6720962
/**********************************************************************
*<
FILE: shaveVrayInstanceBase.cpp
DESCRIPTION: VRay base class for regular and insted hair VRay instance classes
CREATED BY: Vladimir Dubovoy <[email protected]>
HISTORY: created 12-05-2010
*>
**********************************************************************/
#include "shaveVrayInstanceBase.h"
//IHairStack* shaveVrayInstanceBase::stack = NULL;
IHairStack* stack = NULL;
void shaveVrayInstanceBase::loadHair()
{
if(!stack)
{
//we can not do it in standalone case
//shaveVrayIntListParam* dataParam = plugin->GetDataParam();
//shaveVrayIntParam* dataSizeParam = plugin->GetDataSizeParam();
bool dra_as_param = false;
bool dra_as_file = false;
VR::VRayPluginParameter *dataParam=plugin->paramList->getParam("draData");
VR::VRayPluginParameter *dataSizeParam=plugin->paramList->getParam("draSize");
if(dataSizeParam && dataParam /*&& dataParam->getCount(0) > 0*/)
{
LOGMSG("SHAVE", "shaveVrayInstance: importing DRA from memory");
VR::IntList L = dataParam->getIntList(0);
//int N = dataParam->getCount(0);
int N = L.count();
int size = dataSizeParam->getInt(0,0);
if(N > 0 && size > 0)
{
dra_as_param = true;
LOGMSGI("SHAVE", "shaveVrayInstance: DRA data size ", size);
LOGMSGI("SHAVE", "shaveVrayInstance: DRA intlist count ", N);
int extra = 0;
int n = size/sizeof(int);
if(size > n*sizeof(int))
{
extra = size - n*sizeof(int);
}
LOGMSGI("SHAVE", "shaveVrayInstance: (debug) exta bytes ", extra);
char* data = (char*)malloc(size);
int* idata = (int*)data;
int chpos = 0;
long intsum = 0;
for(int oo = 0; oo < N; oo++)
{
if(oo < n)
{
//int v = dataParam->getInt(oo,0.0);
int v = L[oo];
idata[oo] = v;
chpos += sizeof(int);
intsum += v;
}
else
{
//int A = dataParam->getInt(oo,0.0);
int A = L[oo];
char* AA = (char*)(&A);
for(int j = 0; j < extra; j++)
{
data[chpos+j] = AA[j];
}
intsum += A;
}
}
///// checksum //
int sum = 0;
for(int oo = 0; oo < size; oo++)
{
sum += (unsigned char)data[oo];
}
LOGMSGI("SHAVE", "shaveVrayInstance: (debug) checksum ", (int)sum);
LOGMSGI("SHAVE", "shaveVrayInstance: (debug) intsum ", (int)intsum);
stack = LoadHair((void*)data,(long)size);
}
}
if(!dra_as_param && !shaveVrayPlugin::draFile.empty())
{
dra_as_file = true;
LOGMSG("SHAVE", "shaveVrayInstance: importing DRA from file.");
stack = LoadHair((char*)shaveVrayPlugin::draFile.ptr());
}
if(!dra_as_param && !dra_as_file)
{
LOGMSG("SHAVE", "shaveVrayInstance: no DRA source specified.");
}
}
if(!hair() && stack)
{
if(stack)
{
try
{
_hair() = stack->GetHairNodeByID(stackid(),GetSquirrel());
}
catch(...)
{
LOGMSG("SHAVE", "shaveVrayInstance: an exception occured when accessing DRA.");
}
if(!hair())
LOGMSGI("SHAVE", "shaveVrayInstance: can not create Hair node (id)",stackid());
}
else
LOGMSG("SHAVE", "shaveVrayInstance::compileGeometry NULL stack.");
}
}
void shaveVrayInstanceBase::freeMem()
{
//free primitieves here
for(unsigned int i = 0; i < (unsigned int)voxprims().size(); i++)
if(voxprim(i))
{
delete voxprim(i);
_voxprim(i) = NULL;
}
_voxprims().clear();
if(stack)
{
delete stack;
stack = NULL;
}
}
|