Esempio n. 1
0
        public void CreatePreviewModel()
        {
            // Is there a model, is it valid, and does it need a new preview object?
            if (m_Model == null || !m_Model.m_Valid || m_Model == m_ModelPreviewModel)
            {
                return;
            }

            // We know the model has changed, so destroy the preview.
            if (m_ModelPreview != null)
            {
                Destroy(m_ModelPreview.gameObject);
            }

            // Remember the model for which this preview was created.
            m_ModelPreviewModel = m_Model;

            // Build the actual preview.
            m_ModelPreview = Instantiate(m_Model.m_ModelParent);
            HierarchyUtils.RecursivelySetLayer(m_ModelPreview, LayerMask.NameToLayer("Panels"));
            m_ModelPreview.gameObject.SetActive(true);
            m_ModelPreview.parent = m_PreviewParent;
            float maxSide = Mathf.Max(m_Model.m_MeshBounds.size.x,
                                      Mathf.Max(m_Model.m_MeshBounds.size.y, m_Model.m_MeshBounds.size.z));
            TrTransform xf = TrTransform.S(1 / maxSide) * TrTransform.T(-m_Model.m_MeshBounds.center);

            Coords.AsLocal[m_ModelPreview] = xf;
            HierarchyUtils.RecursivelyDisableShadows(m_ModelPreview);
        }
Esempio n. 2
0
        /// Given a transform, returns that transform in another basis.
        /// Since it's a Transform, xfInput is in Global (Room) space, Unity axes, decimeters.
        /// The new basis is: Scene space, with the Payload's axes and units.
        public static Matrix4x4 ChangeBasis(
            Transform xfInput, SceneStatePayload payload)
        {
            Matrix4x4 basis        = AxisConvention.GetFromUnity(payload.axes);
            Matrix4x4 basisInverse = AxisConvention.GetToUnity(payload.axes);

            return(ChangeBasis(App.Scene.AsScene[xfInput], basis, basisInverse)
                   .TransformBy(TrTransform.S(payload.exportUnitsFromAppUnits))
                   .ToMatrix4x4());
        }
Esempio n. 3
0
        protected override void MaybeCreateChildrenImpl()
        {
            // TODO: when too many children, starve an old one in order to create another.

            int kBranchCount = 12;
            int kFrondCount  = 16;

            if (m_recursionLevel == 0)
            {
                // Trunk
                if (m_children.Count == 0)
                {
                    InitializeAndAddChild(new PbChildIdentityXf(), m_trunkBrush, m_trunkColor);
                }
                if (DistanceSinceLastKnotBasedChild() > m_branchFrequency &&
                    m_children.Count < kBranchCount + 1)
                {
                    int salt = m_children.Count;
                    // Children 1 - 13 are the branches; early ones grow faster.
                    float       growthPercent = (kBranchCount + 1 - (float)m_children.Count) / kBranchCount;
                    TrTransform offset        =
                        // Branches don't extend as quickly as the trunk
                        TrTransform.S(m_branchScale * growthPercent) *
                        // Randomly place around the tree
                        TrTransform.R(m_rng.InRange(salt, 0f, 360f), Vector3.forward) *
                        // Angle the branches backwards (away from the stroke tip)
                        TrTransform.R(120, Vector3.right);
                    InitializeAndAddChild(
                        new PbChildWithOffset(m_knots.Count - 1, AttachFrame.LineTangent, offset, 0),
                        m_Desc, // Recurse with same brush
                        Color.white, m_branchRelativeSize);
                }
            }
            else if (m_recursionLevel == 1)
            {
                // Branch
                if (m_children.Count == 0)
                {
                    InitializeAndAddChild(new PbChildIdentityXf(), m_branchBrush, m_branchColor);
                }
                // TODO: would like this frequency to be higher for tinier branches
                if (DistanceSinceLastKnotBasedChild() > m_frondFrequency &&
                    m_children.Count < kFrondCount + 1)
                {
                    float growthPercent = 1; // (kFrondCount + 1 - (float)m_children.Count) / kFrondCount;
                    for (int deg = -30; deg <= 30; deg += 60)
                    {
                        TrTransform offset =
                            // Fronds don't grow as quickly as the branch
                            TrTransform.S(m_frondScale * growthPercent) *
                            TrTransform.R(deg, Vector3.up);
                        InitializeAndAddChild(
                            new PbChildWithOffset(m_knots.Count - 1, AttachFrame.LineTangent, offset, 0),
                            m_frondBrush, m_frondColor, m_frondRelativeSize);
                        TrTransform decoOffset = TrTransform.T(m_decoOffset);
                        InitializeAndAddChild(
                            new PbChildWithOffset(-1, AttachFrame.LineTangent, decoOffset, m_decoTwist),
                            m_decoBrush, Color.white, m_frondRelativeSize);
                    }
                }
            }
        }