36 if (entries.IsEmpty())
46 if (!spawnParamsLocal)
49 spawnParamsLocal.Transform[3] = entries[0].m_vPosition;
52 bool applyMesh = !material.IsEmpty();
56 FilePath.StripExtension(previewPrefab, ext);
59 bool spawnFromResource;
62 previewResource =
Resource.Load(previewPrefab);
63 spawnFromResource = previewResource.IsValid();
67 if (spawnFromResource)
75 previewType = previewPrefab.ToType();
83 Debug.Error2(
"SCR_BasePreviewEntity",
string.Format(
"Unable to create preview entity from prefab/type '%1'!", previewPrefab));
88 Math3D.MatrixCopy(spawnParamsLocal.Transform, rootTransform);
93 vector rootBoundMax = -rootBoundMin;
95 int editableEntityCount;
97 array<SCR_BasePreviewEntity> children = {};
105 entry.LoadTransform(spawnParamsLocal.Transform);
108 Math3D.MatrixScale(spawnParamsLocal.Transform, entry.GetScale());
111 if (entry.m_iParentID == -1)
114 parent = children[entry.m_iParentID];
118 editableEntityCount++;
128 if (spawnFromResource)
133 if (entity && applyMesh)
135 switch (entry.m_Shape)
156 int resolution = SCR_BaseAreaMeshComponent.PREVIEW_RESOLUTION;
157 vector dimensions = entry.m_vScale;
159 if (resolution <= 0 || dimensions[0] <= 0 || dimensions[1] <= 0 || dimensions[2] <= 0)
164 array<vector> positions = {};
168 float dirStep =
Math.PI2 / resolution;
171 for (
int v = 0; v < resolution; v++)
173 float dir = dirStep * v;
174 vector pos =
Vector(
Math.Sin(dir) * dimensions[0], -dimensions[1],
Math.Cos(dir) * dimensions[2]);
175 positions.Insert(pos);
184 float width = dimensions[0] / 2;
185 float lenght = dimensions[2] / 2;
187 array<vector> corners = {
188 Vector(-width, -dimensions[1], -lenght),
189 Vector(width, -dimensions[1], -lenght),
190 Vector(width, -dimensions[1], lenght),
191 Vector(-width, -dimensions[1], lenght)
195 for (
int p = 0; p < resolution; p++)
197 vector start = corners[p];
198 vector end = corners[(p + 1) % resolution];
200 for (
float s = 0; s < 4; s++)
203 positions.Insert(pos);
208 Resource res =
SCR_Shape.CreateAreaMesh(positions, dimensions[1] * 2, material,
true);
209 MeshObject meshObject = res.GetResource().ToMeshObject();
211 entity.SetObject(meshObject,
"");
217 children.Insert(entity);
220 vector boundMin, boundMax;
221 entity.GetBounds(boundMin, boundMax);
222 boundMin += entry.m_vPosition;
223 boundMax += entry.m_vPosition;
225 rootBoundMin[0] =
Math.Min(rootBoundMin[0], boundMin[0]);
226 rootBoundMin[1] =
Math.Min(rootBoundMin[1], boundMin[1]);
227 rootBoundMin[2] =
Math.Min(rootBoundMin[2], boundMin[2]);
229 rootBoundMax[0] =
Math.Max(rootBoundMax[0], boundMax[0]);
230 rootBoundMax[1] =
Math.Max(rootBoundMax[1], boundMax[1]);
231 rootBoundMax[2] =
Math.Max(rootBoundMax[2], boundMax[2]);
235 if (!entry.m_iPivotID.IsEmpty() && parent.GetAnimation())
236 pivot = parent.GetAnimation().GetBoneIndex(entry.m_iPivotID);
252 entity.
m_Flags |= entry.m_Flags;
265 Print(
string.Format(
"Preview entity created from %1 entries, at %2, using '%3' with material '%4'", entries.Count(), rootTransform, previewPrefab, material),
LogLevel.VERBOSE);
303 switch (verticalMode)
309 vector transform[4], surfaceBasis[4];
313 float scale = transform[0].Length();
334 Math3D.MatrixMultiply3(surfaceBasis, transform, surfaceBasis);
369 for (
int i = 0, count =
m_aChildren.Count(); i < count; i++)
371 m_aChildren[i].SetChildTransform(verticalMode, heightTerrain, isUnderwater, trace);