Skip to content

Commit 207a6d7

Browse files
Enable Grid support in animation export
- Enable support for shape kind Grid. - Update docu.
1 parent c14e61c commit 207a6d7

File tree

2 files changed

+31
-4
lines changed

2 files changed

+31
-4
lines changed

src/AnimationExport/exportAnimation.jl

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,31 @@ function exportObject(object, elements, obj::Modia3D.Composition.Object3D, coord
197197
return (r_obj, R_obj)
198198
end
199199

200+
function exportObject(object, elements, obj::Modia3D.Composition.Object3D, grid::Modia3D.Shapes.Grid, initPos, initRot)
201+
r_obj = Modia3D.ZeroVector3D
202+
R_obj = Shapes.rotateAxis2z(grid.axis, Modia3D.NullRotation)
203+
name = Modia3D.fullName(obj)
204+
geometryName = name * ".geometry"
205+
array = []
206+
for i in 0:div(grid.length+1e-12, grid.distance)
207+
x = i * grid.distance - grid.length/2
208+
push!(array, x, -grid.width/2, 0)
209+
push!(array, x, grid.width/2, 0)
210+
end
211+
for i in 0:div(grid.width+1e-12, grid.distance)
212+
y = i * grid.distance - grid.width/2
213+
push!(array, -grid.length/2, y, 0)
214+
push!(array, grid.length/2, y, 0)
215+
end
216+
position = (; itemSize=3, type="Float32Array", array=array)
217+
geometry = (; name=geometryName, uuid=name2uuid(geometryName), type="BufferGeometry", data=(; attributes=(; position=position)))
218+
materialName = name * ".material"
219+
material = (; name=materialName, uuid=name2uuid(materialName), type="LineBasicMaterial", color=((255*0 + 0)*256 + 255), linewidth=grid.lineWidth)
220+
objectInfo = getObjectInfo(name, geometry, material, initPos, initRot, type="LineSegments", R_obj=R_obj)
221+
printInfoToFile(object, elements, geometry, material, nothing, objectInfo)
222+
return (r_obj, R_obj)
223+
end
224+
200225
function printInfoToFile(object, elements, geometry, material, shape, objectInfo)
201226
push!(elements.geometries, geometry)
202227
if !isnothing(material)
@@ -249,8 +274,8 @@ function getObjectInfoMesh(obj, initPos, initRot, scale, R_obj, meshInfo)
249274
return meshInfo
250275
end
251276

252-
function getObjectInfo(name, geometry, material, initPos, initRot; r_obj=Modia3D.ZeroVector3D, R_obj=Modia3D.NullRotation, scale=ones(3))
253-
return (; name=name, uuid=name2uuid(name), type=:Mesh, geometry=get(geometry, :uuid, nothing), material=get(material, :uuid, ""), position=initPos+initRot'*r_obj, rotation=Modia3D.rot123fromR(R_obj*initRot), scale=scale)
277+
function getObjectInfo(name, geometry, material, initPos, initRot; type="Mesh", r_obj=Modia3D.ZeroVector3D, R_obj=Modia3D.NullRotation, scale=ones(3))
278+
return (; name=name, uuid=name2uuid(name), type=type, geometry=get(geometry, :uuid, nothing), material=get(material, :uuid, ""), position=initPos+initRot'*r_obj, rotation=Modia3D.rot123fromR(R_obj*initRot), scale=scale)
254279
end
255280

256281
printVisuMaterialToJSON(obj, visuMaterial) = nothing
@@ -302,6 +327,10 @@ function printObjectToJSON(object, elements, obj; initPos=obj.r_abs, initRot=obj
302327
coordinateSystem::Modia3D.Shapes.CoordinateSystem = obj.shape
303328
(r_obj, R_obj) = exportObject(object, elements, obj, coordinateSystem, initPos, initRot)
304329

330+
elseif shapeKind == Modia3D.GridKind
331+
grid::Modia3D.Shapes.Grid = obj.shape
332+
(r_obj, R_obj) = exportObject(object, elements, obj, grid, initPos, initRot)
333+
305334
elseif shapeKind == Modia3D.FileMeshKind
306335
fileMesh::Modia3D.Shapes.FileMesh = obj.shape
307336
(r_obj, R_obj) = exportObject(object, elements, obj, fileMesh, initPos, initRot)

src/Shapes/shape.jl

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,6 @@ The dimension directions depend on `axis` by circularly shift:
3737
| 2 | z | x |
3838
| 3 | x | y |
3939
40-
# Notes
41-
- Grid is [not supported by animation export](https://github.com/ModiaSim/PrivateModia3D.jl/issues/77).
4240
"""
4341
mutable struct Grid <: Modia3D.AbstractShape
4442
axis::Int

0 commit comments

Comments
 (0)