コード例 #1
0
        private void DoPaint(bool preview, Ray ray, RaycastHit hit)
        {
            pendingCommands.Clear();

            var aspect = P3dHelper.GetAspect(currentPaintBrush.Shape);

            switch (currentPaintMaterial.Style)
            {
            case P3dPaintMaterial.StyleType.Seamless:
            {
                foreach (var slot in currentPaintMaterial.Slots)
                {
                    var radius     = currentPaintBrush.Radius * settings.PaintScale;
                    var tileMatrix = Matrix4x4.TRS(Vector3.zero, Quaternion.identity, new Vector3(settings.PaintTile, settings.PaintTile, settings.PaintTile));
                    var color      = currentPaintBrush.Color;

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

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

                    P3dPaintDecal.Command.Instance.SetShape(Quaternion.LookRotation(ray.direction), Vector3.one, radius, aspect);

                    P3dPaintDecal.Command.Instance.SetLocation(hit.point);

                    P3dPaintDecal.Command.Instance.SetMaterial(P3dBlendMode.AlphaBlend, null, currentPaintBrush.Shape, currentPaintBrush.ShapeChannel, 1.0f, 1.0f, 1.0f, 1.0f, 0.1f, color, 1.0f, slot.Texture, tileMatrix, 3.0f);

                    pendingCommands.Add(P3dPaintDecal.Command.Instance.SpawnCopy());
                }
            }
            break;

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

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

                foreach (var slot in currentPaintMaterial.Slots)
                {
                    var radius = currentPaintBrush.Radius * settings.PaintScale;
                    var color  = currentPaintBrush.Color;

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

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

                    P3dPaintDecal.Command.Instance.SetShape(Quaternion.LookRotation(ray.direction), Vector3.one, radius, aspect);

                    P3dPaintDecal.Command.Instance.SetLocation(hit.point);

                    P3dPaintDecal.Command.Instance.SetMaterial(P3dBlendMode.AlphaBlend, slot.Texture, shape, currentPaintBrush.ShapeChannel, 1.0f, 1.0f, 1.0f, 1.0f, 0.1f, color, 1.0f, null, Matrix4x4.identity, 1.0f);

                    pendingCommands.Add(P3dPaintDecal.Command.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);
            }

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

                P3dPaintableManager.BuildCloners(tempCloners);

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

                        P3dPaintableManager.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;
        }