LibreOffice Module svx (master) 1
viewcontactofe3d.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 */
19
22#include <svx/obj3d.hxx>
25#include <svx/scene3d.hxx>
30
31namespace {
32
33const sdr::contact::ViewContactOfE3dScene* tryToFindVCOfE3DScene(
34 const sdr::contact::ViewContact& rCandidate,
35 basegfx::B3DHomMatrix& o_rInBetweenObjectTransform)
36{
37 const sdr::contact::ViewContactOfE3dScene* pSceneParent =
38 dynamic_cast< const sdr::contact::ViewContactOfE3dScene* >(rCandidate.GetParentContact());
39
40 if(pSceneParent)
41 {
42 // each 3d object (including in-between scenes) should have a scene as parent
43 const sdr::contact::ViewContactOfE3dScene* pSceneParentParent =
44 dynamic_cast< const sdr::contact::ViewContactOfE3dScene* >(pSceneParent->GetParentContact());
45
46 if(pSceneParentParent)
47 {
48 // the parent scene of rCandidate is an in-between scene, call recursively and collect
49 // the in-between scene's object transformation part in o_rInBetweenObjectTransform
50 const basegfx::B3DHomMatrix& rSceneParentTransform = pSceneParent->GetE3dScene().GetTransform();
51 o_rInBetweenObjectTransform = rSceneParentTransform * o_rInBetweenObjectTransform;
52 return tryToFindVCOfE3DScene(*pSceneParent, o_rInBetweenObjectTransform);
53 }
54 else
55 {
56 // the parent scene is the outmost scene
57 return pSceneParent;
58 }
59 }
60
61 // object hierarchy structure is incorrect; no result
62 return nullptr;
63}
64
65} // end of anonymous namespace
66
67namespace sdr::contact {
68
71{
73
74 if(!rxContent3D.empty())
75 {
76 // try to get the outmost ViewObjectContactOfE3dScene for this single 3d object,
77 // the ones on the way there are grouping scenes. Collect the in-between scene's
78 // transformations to build a correct object transformation for the embedded
79 // object
80 basegfx::B3DHomMatrix aInBetweenObjectTransform;
81 const ViewContactOfE3dScene* pVCOfE3DScene = tryToFindVCOfE3DScene(*this, aInBetweenObjectTransform);
82
83 if(pVCOfE3DScene)
84 {
85 basegfx::B3DVector aLightNormal;
86 const double fShadowSlant(pVCOfE3DScene->getSdrSceneAttribute().getShadowSlant());
87 const basegfx::B3DRange& rAllContentRange = pVCOfE3DScene->getAllContentRange3D();
88 drawinglayer::geometry::ViewInformation3D aViewInformation3D(pVCOfE3DScene->getViewInformation3D());
89
90 if(!pVCOfE3DScene->getSdrLightingAttribute().getLightVector().empty())
91 {
92 // get light normal from first light and normalize
93 aLightNormal = pVCOfE3DScene->getSdrLightingAttribute().getLightVector()[0].getDirection();
94 aLightNormal.normalize();
95 }
96
97 if(!aInBetweenObjectTransform.isIdentity())
98 {
99 // if aInBetweenObjectTransform is used, create combined ViewInformation3D which
100 // contains the correct object transformation for the embedded 3d object
102 aViewInformation3D.getObjectTransformation() * aInBetweenObjectTransform,
103 aViewInformation3D.getOrientation(),
104 aViewInformation3D.getProjection(),
105 aViewInformation3D.getDeviceToView(),
106 aViewInformation3D.getViewTime(),
107 aViewInformation3D.getExtendedInformationSequence());
108 }
109
110 // create embedded 2d primitive and add. LightNormal and ShadowSlant are needed for evtl.
111 // 3D shadow extraction for correct B2DRange calculation (shadow is part of the object)
114 rxContent3D,
115 pVCOfE3DScene->getObjectTransformation(),
116 std::move(aViewInformation3D),
117 aLightNormal,
118 fShadowSlant,
119 rAllContentRange));
120
122 }
123 }
124
125 return xRetval;
126}
127
129: ViewContactOfSdrObj(rSdrObject)
130{
131}
132
134{
135}
136
138{
139 // local up-to-date checks. Create new list and compare.
141
143 {
144 // has changed, copy content
145 const_cast< ViewContactOfE3d* >(this)->mxViewIndependentPrimitive3DContainer = xNew;
146 }
147
148 // return current Primitive2DContainer
150}
151
153{
154 // get sequence without object transform
156
157 if(!xRetval.empty())
158 {
159 // add object transform if it's used
160 const basegfx::B3DHomMatrix& rObjectTransform(GetE3dObject().GetTransform());
161
162 if(!rObjectTransform.isIdentity())
163 {
166 rObjectTransform,
167 xRetval));
168
169 xRetval = { xReference };
170 }
171 }
172
173 // return current Primitive2DContainer
174 return xRetval;
175}
176
178{
179 // also need to create a 2D embedding when the view-independent part is requested,
180 // see view-dependent part in ViewObjectContactOfE3d::createPrimitive2DSequence
181 // get 3d primitive vector, isPrimitiveVisible() is done in 3d creator
183}
184
186{
187 ViewObjectContact* pRetval = new ViewObjectContactOfE3d(rObjectContact, *this);
188 DBG_ASSERT(pRetval, "ViewContactOfE3d::CreateObjectSpecificViewObjectContact() failed (!)");
189
190 return *pRetval;
191}
192
193}
194
195/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
const basegfx::B3DHomMatrix & GetTransform() const
Definition: obj3d.hxx:112
bool isIdentity() const
B3DVector & normalize()
const ::std::vector< Sdr3DLightAttribute > & getLightVector() const
const css::uno::Sequence< css::beans::PropertyValue > & getExtendedInformationSequence() const
const basegfx::B3DHomMatrix & getDeviceToView() const
const basegfx::B3DHomMatrix & getObjectTransformation() const
const basegfx::B3DHomMatrix & getProjection() const
const basegfx::B3DHomMatrix & getOrientation() const
virtual void visit(const Primitive2DReference &)=0
const drawinglayer::geometry::ViewInformation3D & getViewInformation3D(const ::basegfx::B3DRange &rContentRange) const
const drawinglayer::attribute::SdrSceneAttribute & getSdrSceneAttribute() const
const drawinglayer::attribute::SdrLightingAttribute & getSdrLightingAttribute() const
basegfx::B3DRange getAllContentRange3D() const
const basegfx::B2DHomMatrix & getObjectTransformation() const
virtual drawinglayer::primitive3d::Primitive3DContainer createViewIndependentPrimitive3DContainer() const =0
drawinglayer::primitive3d::Primitive3DContainer const & getVIP3DSWithoutObjectTransform() const
drawinglayer::primitive3d::Primitive3DContainer getViewIndependentPrimitive3DContainer() const
drawinglayer::primitive2d::Primitive2DContainer impCreateWithGivenPrimitive3DContainer(const drawinglayer::primitive3d::Primitive3DContainer &rxContent3D) const
virtual void createViewIndependentPrimitive2DSequence(drawinglayer::primitive2d::Primitive2DDecompositionVisitor &rVisitor) const override
drawinglayer::primitive3d::Primitive3DContainer mxViewIndependentPrimitive3DContainer
virtual ViewObjectContact & CreateObjectSpecificViewObjectContact(ObjectContact &rObjectContact) override
const E3dObject & GetE3dObject() const
virtual ViewContact * GetParentContact() const override
virtual ViewContact * GetParentContact() const
#define DBG_ASSERT(sCon, aError)
css::uno::Reference< css::graphic::XPrimitive3D > Primitive3DReference