@@ -4,9 +4,11 @@ function name2uuid(name::String)
44 return string (UUIDs. uuid5 (u4, name))
55end
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
1214function 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)
198200end
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+
200227function 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
250277end
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)
254281end
255282
256283printVisuMaterialToJSON (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)
0 commit comments