Line data Source code
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 :
20 :
21 : #include <svx/sdr/contact/viewcontactofe3d.hxx>
22 : #include <svx/sdr/contact/viewobjectcontactofe3d.hxx>
23 : #include <svx/obj3d.hxx>
24 : #include <drawinglayer/primitive2d/embedded3dprimitive2d.hxx>
25 : #include <svx/sdr/contact/viewcontactofe3dscene.hxx>
26 : #include <svx/scene3d.hxx>
27 : #include <drawinglayer/primitive3d/transformprimitive3d.hxx>
28 : #include <drawinglayer/attribute/sdrsceneattribute3d.hxx>
29 : #include <drawinglayer/attribute/sdrlightingattribute3d.hxx>
30 : #include <drawinglayer/attribute/sdrlightattribute3d.hxx>
31 : #include <drawinglayer/attribute/sdrlineattribute.hxx>
32 :
33 :
34 :
35 : namespace
36 : {
37 0 : const sdr::contact::ViewContactOfE3dScene* tryToFindVCOfE3DScene(
38 : const sdr::contact::ViewContact& rCandidate,
39 : basegfx::B3DHomMatrix& o_rInBetweenObjectTransform)
40 : {
41 : const sdr::contact::ViewContactOfE3dScene* pSceneParent =
42 0 : dynamic_cast< const sdr::contact::ViewContactOfE3dScene* >(rCandidate.GetParentContact());
43 :
44 0 : if(pSceneParent)
45 : {
46 : // each 3d object (including in-between scenes) should have a scene as parent
47 : const sdr::contact::ViewContactOfE3dScene* pSceneParentParent =
48 0 : dynamic_cast< const sdr::contact::ViewContactOfE3dScene* >(pSceneParent->GetParentContact());
49 :
50 0 : if(pSceneParentParent)
51 : {
52 : // the parent scene of rCandidate is a in-between scene, call recursively and collect
53 : // the in-between scene's object transformation part in o_rInBetweenObjectTransform
54 0 : const basegfx::B3DHomMatrix& rSceneParentTransform = pSceneParent->GetE3dScene().GetTransform();
55 0 : o_rInBetweenObjectTransform = rSceneParentTransform * o_rInBetweenObjectTransform;
56 0 : return tryToFindVCOfE3DScene(*pSceneParent, o_rInBetweenObjectTransform);
57 : }
58 : else
59 : {
60 : // the parent scene is the outmost scene
61 0 : return pSceneParent;
62 : }
63 : }
64 :
65 : // object hierarchy structure is incorrect; no result
66 0 : return 0;
67 : }
68 : } // end of anonymous namespace
69 :
70 :
71 :
72 : namespace sdr
73 : {
74 : namespace contact
75 : {
76 0 : drawinglayer::primitive2d::Primitive2DSequence ViewContactOfE3d::impCreateWithGivenPrimitive3DSequence(
77 : const drawinglayer::primitive3d::Primitive3DSequence& rxContent3D) const
78 : {
79 0 : drawinglayer::primitive2d::Primitive2DSequence xRetval;
80 :
81 0 : if(rxContent3D.hasElements())
82 : {
83 : // try to get the outmost ViewObjectContactOfE3dScene for this single 3d object,
84 : // the ones on the way there are grouping scenes. Collect the in-between scene's
85 : // transformations to build a correct object transformation for the embedded
86 : // object
87 0 : basegfx::B3DHomMatrix aInBetweenObjectTransform;
88 0 : const ViewContactOfE3dScene* pVCOfE3DScene = tryToFindVCOfE3DScene(*this, aInBetweenObjectTransform);
89 :
90 0 : if(pVCOfE3DScene)
91 : {
92 0 : basegfx::B3DVector aLightNormal;
93 0 : const double fShadowSlant(pVCOfE3DScene->getSdrSceneAttribute().getShadowSlant());
94 0 : const basegfx::B3DRange& rAllContentRange = pVCOfE3DScene->getAllContentRange3D();
95 0 : drawinglayer::geometry::ViewInformation3D aViewInformation3D(pVCOfE3DScene->getViewInformation3D());
96 :
97 0 : if(pVCOfE3DScene->getSdrLightingAttribute().getLightVector().size())
98 : {
99 : // get light normal from first light and normalize
100 0 : aLightNormal = pVCOfE3DScene->getSdrLightingAttribute().getLightVector()[0].getDirection();
101 0 : aLightNormal.normalize();
102 : }
103 :
104 0 : if(!aInBetweenObjectTransform.isIdentity())
105 : {
106 : // if aInBetweenObjectTransform is used, create combined ViewInformation3D which
107 : // contains the correct object transformation for the embedded 3d object
108 0 : aViewInformation3D = drawinglayer::geometry::ViewInformation3D(
109 0 : aViewInformation3D.getObjectTransformation() * aInBetweenObjectTransform,
110 0 : aViewInformation3D.getOrientation(),
111 0 : aViewInformation3D.getProjection(),
112 0 : aViewInformation3D.getDeviceToView(),
113 : aViewInformation3D.getViewTime(),
114 0 : aViewInformation3D.getExtendedInformationSequence());
115 : }
116 :
117 : // create embedded 2d primitive and add. LightNormal and ShadowSlant are needed for evtl.
118 : // 3D shadow extraction for correct B2DRange calculation (shadow is part of the object)
119 : const drawinglayer::primitive2d::Primitive2DReference xReference(
120 : new drawinglayer::primitive2d::Embedded3DPrimitive2D(
121 : rxContent3D,
122 : pVCOfE3DScene->getObjectTransformation(),
123 : aViewInformation3D,
124 : aLightNormal,
125 : fShadowSlant,
126 0 : rAllContentRange));
127 :
128 0 : xRetval = drawinglayer::primitive2d::Primitive2DSequence(&xReference, 1);
129 0 : }
130 : }
131 :
132 0 : return xRetval;
133 : }
134 :
135 0 : ViewContactOfE3d::ViewContactOfE3d(E3dObject& rSdrObject)
136 0 : : ViewContactOfSdrObj(rSdrObject)
137 : {
138 0 : }
139 :
140 0 : ViewContactOfE3d::~ViewContactOfE3d()
141 : {
142 0 : }
143 :
144 0 : drawinglayer::primitive3d::Primitive3DSequence ViewContactOfE3d::getVIP3DSWithoutObjectTransform() const
145 : {
146 : // local up-to-date checks. Create new list and compare.
147 0 : drawinglayer::primitive3d::Primitive3DSequence xNew(createViewIndependentPrimitive3DSequence());
148 :
149 0 : if(!drawinglayer::primitive3d::arePrimitive3DSequencesEqual(mxViewIndependentPrimitive3DSequence, xNew))
150 : {
151 : // has changed, copy content
152 0 : const_cast< ViewContactOfE3d* >(this)->mxViewIndependentPrimitive3DSequence = xNew;
153 : }
154 :
155 : // return current Primitive2DSequence
156 0 : return mxViewIndependentPrimitive3DSequence;
157 : }
158 :
159 0 : drawinglayer::primitive3d::Primitive3DSequence ViewContactOfE3d::getViewIndependentPrimitive3DSequence() const
160 : {
161 : // get sequence without object transform
162 0 : drawinglayer::primitive3d::Primitive3DSequence xRetval(getVIP3DSWithoutObjectTransform());
163 :
164 0 : if(xRetval.hasElements())
165 : {
166 : // add object transform if it's used
167 0 : const basegfx::B3DHomMatrix& rObjectTransform(GetE3dObject().GetTransform());
168 :
169 0 : if(!rObjectTransform.isIdentity())
170 : {
171 : const drawinglayer::primitive3d::Primitive3DReference xReference(
172 : new drawinglayer::primitive3d::TransformPrimitive3D(
173 : rObjectTransform,
174 0 : xRetval));
175 :
176 0 : xRetval = drawinglayer::primitive3d::Primitive3DSequence(&xReference, 1);
177 : }
178 : }
179 :
180 : // return current Primitive2DSequence
181 0 : return xRetval;
182 : }
183 :
184 0 : drawinglayer::primitive2d::Primitive2DSequence ViewContactOfE3d::createViewIndependentPrimitive2DSequence() const
185 : {
186 : // also need to create a 2D embedding when the view-independent part is requested,
187 : // see view-dependent part in ViewObjectContactOfE3d::createPrimitive2DSequence
188 : // get 3d primitive vector, isPrimitiveVisible() is done in 3d creator
189 0 : return impCreateWithGivenPrimitive3DSequence(getViewIndependentPrimitive3DSequence());
190 : }
191 :
192 0 : ViewObjectContact& ViewContactOfE3d::CreateObjectSpecificViewObjectContact(ObjectContact& rObjectContact)
193 : {
194 0 : ViewObjectContact* pRetval = new ViewObjectContactOfE3d(rObjectContact, *this);
195 : DBG_ASSERT(pRetval, "ViewContactOfE3d::CreateObjectSpecificViewObjectContact() failed (!)");
196 :
197 0 : return *pRetval;
198 : }
199 : } // end of namespace contact
200 : } // end of namespace sdr
201 :
202 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|