Skip to content

Commit 6411883

Browse files
Merge pull request #36 from ModiaSim/gh_enableGridAnimationExport
Enable Grid support in animation export
2 parents 13e62ce + 8e46a18 commit 6411883

File tree

2 files changed

+36
-7
lines changed

2 files changed

+36
-7
lines changed

src/AnimationExport/exportAnimation.jl

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@ function name2uuid(name::String)
44
return string(UUIDs.uuid5(u4, name))
55
end
66

7-
const coSysMaterialRed = (; name="coordinateSystem.red", uuid=name2uuid("coordinateSystem.red"), type="MeshPhongMaterial", color=((255*256 + 0)*256 + 0), opacity=1, transparent=false, shininess=0.5)
8-
const coSysMaterialGreen = (; name="coordinateSystem.green", uuid=name2uuid("coordinateSystem.green"), type="MeshPhongMaterial", color=((255*0 + 255)*256 + 0), opacity=1, transparent=false, shininess=0.5)
9-
const coSysMaterialBlue = (; name="coordinateSystem.blue", uuid=name2uuid("coordinateSystem.blue"), type="MeshPhongMaterial", color=((255*0 + 0)*256 + 255), opacity=1, transparent=false, shininess=0.5)
7+
colorNum(red, green, blue) = ((red*256 + green)*256 + blue)
8+
9+
const coSysMaterialRed = (; name="coordinateSystem.red", uuid=name2uuid("coordinateSystem.red"), type="MeshPhongMaterial", color=colorNum(255, 0, 0), opacity=1, transparent=false, shininess=0.5)
10+
const coSysMaterialGreen = (; name="coordinateSystem.green", uuid=name2uuid("coordinateSystem.green"), type="MeshPhongMaterial", color=colorNum(0, 255, 0), opacity=1, transparent=false, shininess=0.5)
11+
const coSysMaterialBlue = (; name="coordinateSystem.blue", uuid=name2uuid("coordinateSystem.blue"), type="MeshPhongMaterial", color=colorNum(0, 0, 255), opacity=1, transparent=false, shininess=0.5)
1012

1113

1214
function exportObject(object, elements, obj::Modia3D.Composition.Object3D, sphere::Modia3D.Shapes.Sphere, initPos, initRot)
@@ -197,6 +199,31 @@ function exportObject(object, elements, obj::Modia3D.Composition.Object3D, coord
197199
return (r_obj, R_obj)
198200
end
199201

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

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)
279+
function getObjectInfo(name, geometry, material, initPos, initRot; type="Mesh", r_obj=Modia3D.ZeroVector3D, R_obj=Modia3D.NullRotation, scale=ones(3))
280+
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)
254281
end
255282

256283
printVisuMaterialToJSON(obj, visuMaterial) = nothing
@@ -302,6 +329,10 @@ function printObjectToJSON(object, elements, obj; initPos=obj.r_abs, initRot=obj
302329
coordinateSystem::Modia3D.Shapes.CoordinateSystem = obj.shape
303330
(r_obj, R_obj) = exportObject(object, elements, obj, coordinateSystem, initPos, initRot)
304331

332+
elseif shapeKind == Modia3D.GridKind
333+
grid::Modia3D.Shapes.Grid = obj.shape
334+
(r_obj, R_obj) = exportObject(object, elements, obj, grid, initPos, initRot)
335+
305336
elseif shapeKind == Modia3D.FileMeshKind
306337
fileMesh::Modia3D.Shapes.FileMesh = obj.shape
307338
(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)