Exemplo n.º 1
0
        public static void SubmitAll(P3dCommand command, Vector3 position, float radius, int layerMask, P3dGroup group, P3dModel targetModel, P3dPaintableTexture targetTexture)
        {
            DoSubmitAll(command, position, radius, layerMask, group, targetModel, targetTexture);

            // Repeat paint?
            P3dClone.BuildCloners();

            for (var c = 0; c < P3dClone.ClonerCount; c++)
            {
                for (var m = 0; m < P3dClone.MatrixCount; m++)
                {
                    var copy = command.SpawnCopy();

                    P3dClone.Clone(copy, c, m);

                    DoSubmitAll(copy, position, radius, layerMask, group, targetModel, targetTexture);

                    copy.Pool();
                }
            }
        }
Exemplo n.º 2
0
        private void DoPaint(bool preview, float pressure, Ray ray, RaycastHit hit, Mesh hitMesh, Matrix4x4 hitMatrix)
        {
            pendingCommands.Clear();

            var finalPosition = hit.point;
            var finalAngle    = settings.PaintAngle;
            var finalOpacity  = settings.PaintOpacity;
            var finalRadius   = settings.PaintScale;
            var finalRotation = Quaternion.LookRotation(ray.direction);
            var finalAspect   = P3dHelper.GetAspect(paintBrushData.Shape);

            paintBrushData.Modifiers.ModifyAngle(ref finalAngle, false, pressure);
            paintBrushData.Modifiers.ModifyOpacity(ref finalOpacity, false, pressure);
            paintBrushData.Modifiers.ModifyPosition(ref finalPosition, false, pressure);
            paintBrushData.Modifiers.ModifyRadius(ref finalRadius, false, pressure);

            var finalSize = Vector3.one * finalRadius;

            switch (currentPaintMaterial.Style)
            {
            case P3dPaintMaterial.StyleType.Seamless:
            {
                foreach (var slot in currentPaintMaterial.Slots)
                {
                    var tileMatrix = Matrix4x4.TRS(Vector3.zero, Quaternion.identity, new Vector3(settings.PaintTile, settings.PaintTile, settings.PaintTile));
                    var finalColor = Color.white;

                    if (slot.Group == settings.ColorModifies)
                    {
                        finalColor *= settings.PaintColor;

                        paintBrushData.Modifiers.ModifyColor(ref finalColor, false, pressure);
                    }

                    P3dCommandDecal.Instance.SetState(preview, slot.Group);                             // Store group in priority

                    SubmitLocation(hit, hitMesh, hitMatrix, finalPosition);

                    P3dCommandDecal.Instance.SetShape(finalRotation, P3dHelper.ScaleAspect(finalSize, finalAspect), finalAngle);

                    P3dCommandDecal.Instance.SetMaterial(P3dBlendMode.AlphaBlend, null, paintBrushData.Shape, paintBrushData.ShapeChannel, 1.0f, 1.0f, settings.PaintNormalBack, settings.PaintNormalFront, settings.PaintNormalFade, finalColor, finalOpacity, slot.Texture, tileMatrix, 1.0f, 2.0f);

                    P3dCommandDecal.Instance.ClearMask();

                    pendingCommands.Add(P3dCommandDecal.Instance.SpawnCopy());
                }
            }
            break;

            case P3dPaintMaterial.StyleType.Decal:
            {
                var shape = paintBrushData.Shape != null ? paintBrushData.Shape : currentPaintMaterial.Shape;

                if (shape != null)
                {
                    finalAspect = P3dHelper.GetAspect(shape);
                }
                else
                {
                    foreach (var slot in currentPaintMaterial.Slots)
                    {
                        if (slot.Texture != null)
                        {
                            finalAspect = P3dHelper.GetAspect(slot.Texture); break;
                        }
                    }
                }

                foreach (var slot in currentPaintMaterial.Slots)
                {
                    var finalColor = Color.white;

                    if (slot.Group == settings.ColorModifies)
                    {
                        finalColor *= settings.PaintColor;

                        paintBrushData.Modifiers.ModifyColor(ref finalColor, false, pressure);
                    }

                    P3dCommandDecal.Instance.SetState(preview, slot.Group);                             // Store group in priority

                    SubmitLocation(hit, hitMesh, hitMatrix, finalPosition);

                    P3dCommandDecal.Instance.SetShape(finalRotation, P3dHelper.ScaleAspect(finalSize, finalAspect), finalAngle);

                    P3dCommandDecal.Instance.SetMaterial(P3dBlendMode.AlphaBlend, slot.Texture, shape, paintBrushData.ShapeChannel, 1.0f, 1.0f, settings.PaintNormalBack, settings.PaintNormalFront, settings.PaintNormalFade, finalColor, finalOpacity, null, Matrix4x4.identity, 1.0f, 2.0f);

                    P3dCommandDecal.Instance.ClearMask();

                    pendingCommands.Add(P3dCommandDecal.Instance.SpawnCopy());
                }
            }
            break;
            }

            // Clone pending commands
            clonedCommands.Clear();

            tempCloners.Clear();

            currentCloners.RemoveAll(c => scene.Cloners.Contains(c) == false);

            foreach (var cloner in currentCloners)
            {
                tempCloners.Add(cloner);
            }

            // Remove excluded or non-isolated groups (stored in priority)
            if (isolatedGroups.Count > 0)
            {
                pendingCommands.RemoveAll(c => isolatedGroups.Contains(c.Priority) == false);
            }
            else
            {
                pendingCommands.RemoveAll(c => excludedGroups.Contains(c.Priority) == true);
            }

            foreach (var command in pendingCommands)
            {
                clonedCommands.Add(command.SpawnCopy());

                P3dClone.BuildCloners(tempCloners);

                for (var c = 0; c < P3dClone.ClonerCount; c++)
                {
                    for (var m = 0; m < P3dClone.MatrixCount; m++)
                    {
                        var copy = command.SpawnCopy();

                        P3dClone.Clone(copy, c, m);

                        clonedCommands.Add(copy);
                    }
                }
            }

            pendingCommands.Clear();

            // Paint commands
            paintedGroups.Clear();

            foreach (var command in clonedCommands)
            {
                foreach (var mat in scene.Mats)
                {
                    var image = currentLayer.GetImage(mat.Id, command.Priority);                     // Group is stored in priority

                    foreach (var obj in scene.Objs)
                    {
                        if (obj.Mesh != null && obj.Paintable == true)
                        {
                            for (var j = 0; j < obj.MatIds.Count; j++)
                            {
                                if (mat.Id == obj.MatIds[j])
                                {
                                    var subMesh = Mathf.Max(j, obj.Mesh.subMeshCount - 1);

                                    Render(command, mat, image, obj, subMesh);
                                }
                            }
                        }
                    }
                }

                command.Pool();
            }

            pendingUpdate = true;
        }