Skip to content

Commit e04edf9

Browse files
Merge pull request #125 from ModiaSim/gh_FixAnimationExport
Enable AnimationExport in case of no renderer available
2 parents f4f4f0c + 776c688 commit e04edf9

File tree

5 files changed

+21
-16
lines changed

5 files changed

+21
-16
lines changed

src/AnimationExport/exportAnimation.jl

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -436,16 +436,16 @@ end
436436

437437

438438
function exportAnimation(scene)
439-
animationFile = scene.options.animationFile
440439
allVisuElements = scene.allVisuElements
441-
animation = scene.animation
442-
if length(allVisuElements) > 0 && !isnothing(animationFile)
440+
if scene.exportAnimation && length(allVisuElements) > 0
441+
animationFile = scene.options.animationFile
443442
(head,ext) = splitext(animationFile)
444443
if ext != ".json"
445444
@warn("The path of an animationFile=$animationFile must end with .json.")
446445
return nothing
447446
end
448447
print("Export animation to $animationFile ... ")
448+
animation = scene.animation
449449
elements = (; geometries=[], materials=[], shapes=[])
450450
metadata = (; generator = "Modia3D", type = "Object")
451451
name = scene.name
@@ -491,3 +491,12 @@ function exportAnimation(scene)
491491
println("done.")
492492
end
493493
end
494+
495+
496+
function Composition.isVisible(feature::Shapes.Solid{F}, exportAnimation::Bool) where F <: Modia3D.VarFloatType
497+
return exportAnimation && !isnothing(feature.shape) && !isnothing(feature.visualMaterial)
498+
end
499+
500+
function Composition.isVisible(feature::Shapes.Visual, exportAnimation::Bool)
501+
return exportAnimation && !isnothing(feature.visualMaterial) && !isnothing(feature.shape)
502+
end

src/Composition/assignObjects.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ end
3535

3636
function assignObj(scene::Scene{F}, superObjType::SuperObjVisu{F}, obj::Object3D{F}, actPos::Int64)::Nothing where F <: Modia3D.VarFloatType
3737
renderer = Modia3D.renderer[1]
38-
if ( isVisible(obj, renderer) || !isnothing(obj.visualizationFrame) ) && !hasJoint(obj) && !canCollide(obj) && !hasForceElement(obj) && !hasChildJoint(obj) #&& !hasCutJoint(obj) && !featureHasMass(obj)
39-
# if an Object3D is for visualization only it is stored in updateVisuElements
38+
if ( isVisible(obj, renderer) || isVisible(obj, scene.exportAnimation) || !isnothing(obj.visualizationFrame) ) && !hasJoint(obj) && !canCollide(obj) && !hasForceElement(obj) && !hasChildJoint(obj) #&& !hasCutJoint(obj) && !featureHasMass(obj)
39+
# if an Object3D is for visualization/animation export only it is stored in updateVisuElements
4040
if !(obj in scene.updateVisuElements)
4141
push!(scene.updateVisuElements, obj)
4242
end
@@ -72,7 +72,7 @@ function fillVisuElements!(scene::Scene{F}, obj::Object3D{F}, world::Object3D{F}
7272
push!(scene.updateVisuElements, obj)
7373
end
7474
end
75-
if isVisible(obj, Modia3D.renderer[1]) # todo: should not affect animation export; move to initializeVisualization?
75+
if isVisible(obj, Modia3D.renderer[1]) || isVisible(obj, scene.exportAnimation) # visible in visualization or animation export
7676
push!(scene.allVisuElements, obj)
7777
end
7878
end

src/Composition/object3D.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -640,9 +640,11 @@ featureHasMass(feature::Modia3D.AbstractScene) = false
640640
featureHasMass(feature::Shapes.Solid{F}) where F <: Modia3D.VarFloatType = !isnothing(feature.massProperties)
641641

642642
isVisible(obj::Object3D{F}, renderer::Modia3D.AbstractRenderer) where F <: Modia3D.VarFloatType = isVisible(obj.feature, renderer)
643+
isVisible(obj::Object3D{F}, exportAnimation::Bool) where F <: Modia3D.VarFloatType = isVisible(obj.feature, exportAnimation)
643644
isVisible(feature::Modia3D.AbstractObject3DFeature, renderer::Modia3D.AbstractRenderer) = false
644-
645+
isVisible(feature::Modia3D.AbstractObject3DFeature, exportAnimation::Bool) = false
645646
isVisible(feature::Modia3D.AbstractScene, renderer::Modia3D.AbstractRenderer) = false
647+
isVisible(feature::Modia3D.AbstractScene, exportAnimation::Bool) = false
646648

647649
canCollide(feature::Modia3D.AbstractObject3DFeature) = false
648650

src/renderer/DLR_Visualization/handler.jl

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -60,15 +60,9 @@ end
6060

6161

6262
function Composition.isVisible(feature::Shapes.Solid{F}, renderer::Modia3D.AbstractDLR_VisualizationRenderer) where F <: Modia3D.VarFloatType
63-
return !isnothing(feature.visualMaterial) && !isnothing(feature.shape)
63+
return !isnothing(feature.shape) && !isnothing(feature.visualMaterial)
6464
end
6565

6666
function Composition.isVisible(feature::Shapes.Visual, renderer::Modia3D.AbstractDLR_VisualizationRenderer)
67-
if isnothing(feature.shape)
68-
return false
69-
elseif typeof(feature.shape) == Shapes.TextShape
70-
return typeof(renderer) != CommunityEdition
71-
else
72-
return !isnothing(feature.visualMaterial)
73-
end
67+
return !isnothing(feature.shape) && !isnothing(feature.visualMaterial)
7468
end

src/renderer/DLR_Visualization/visualize.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ function visualizeObject(obj::Composition.Object3D{F}, id::Ptr{Nothing}, simVis:
123123
fileMesh.filename, Cint(fileMesh.smoothNormals), fileMesh.useMaterialColor, MVector{3,Cint}(obj.visualMaterial.color),
124124
Cint(obj.visualMaterial.shadowMask), emptyShaderName)
125125

126-
elseif shapeKind == Modia3D.TextKind
126+
elseif shapeKind == Modia3D.TextKind && simVis.isProfessionalEdition # function setTextObject is not available in community edition
127127
textShape::Modia3D.Shapes.TextShape = obj.shape
128128
SimVis_setTextObject(simVis, id, Cint(textShape.axisAlignment), textShape.text, 0.0, Cint(0), r_abs, R_abs,
129129
textShape.font.charSize, textShape.font.fontFileName, MVector{3,Cint}(textShape.font.color), textShape.font.transparency,

0 commit comments

Comments
 (0)