private void LoadTool(P3dTool prefab) { if (materialInstance != null) { materialInstance.transform.SetParent(null, false); } ClearTool(); Settings.CurrentTool = prefab; if (EditorApplication.isPlaying == true) { toolInstance = Instantiate(prefab); toolInstance.gameObject.hideFlags = HideFlags.DontSaveInBuild | HideFlags.DontSaveInEditor; toolInstance.transform.SetParent(P3dPaintableManager.GetOrCreateInstance().transform); if (materialInstance != null) { materialInstance.transform.SetParent(toolInstance.transform, false); } } Repaint(); }
public void HandleHitRaycast(bool preview, int priority, float pressure, int seed, RaycastHit hit, Quaternion rotation) { var model = hit.collider.GetComponentInParent <P3dModel>(); if (model != null) { var paintableTextures = P3dPaintableTexture.Filter(model, group); if (paintableTextures.Count > 0) { var finalColor = color; var finalTexture = texture; if (modifiers != null && modifiers.Count > 0) { P3dHelper.BeginSeed(seed); modifiers.ModifyColor(ref finalColor, preview, pressure); modifiers.ModifyTexture(ref finalTexture, preview, pressure); P3dHelper.EndSeed(); } P3dCommandReplace.Instance.SetState(preview, priority); P3dCommandReplace.Instance.SetMaterial(finalTexture, finalColor); for (var i = paintableTextures.Count - 1; i >= 0; i--) { var paintableTexture = paintableTextures[i]; P3dPaintableManager.Submit(P3dCommandReplace.Instance, model, paintableTexture); } } } }
private Vector3 HandleHitCommon(Quaternion rotation, float pressure) { var finalOpacity = opacity; var finalRadius = radius; var finalHardness = hardness; var finalColor = color; var finalAngle = angle; var finalTexture = texture; var finalMatrix = tileTransform != null ? tileTransform.localToWorldMatrix : Matrix4x4.identity; var finalAspect = P3dHelper.GetAspect(shape, texture); P3dPaintableManager.BuildModifiers(gameObject); P3dPaintableManager.ModifyColor(pressure, ref finalColor); P3dPaintableManager.ModifyAngle(pressure, ref finalAngle); P3dPaintableManager.ModifyOpacity(pressure, ref finalOpacity); P3dPaintableManager.ModifyHardness(pressure, ref finalHardness); P3dPaintableManager.ModifyRadius(pressure, ref finalRadius); P3dPaintableManager.ModifyTexture(pressure, ref finalTexture); rotation = rotation * Quaternion.Euler(0.0f, 0.0f, finalAngle); var finalSize = Command.Instance.SetShape(rotation, scale, finalRadius, finalAspect); Command.Instance.SetMaterial(blendMode, texture, shape, shapeChannel, finalHardness, wrapping, normalBack, normalFront, normalFade, finalColor, finalOpacity, tileTexture, finalMatrix, tileBlend); return(finalSize); }
public void HandleHitPoint(List <P3dCommand> commands, List <P3dTransform> repeaters, bool preview, Collider collider, Vector3 worldPosition, Quaternion worldRotation, float pressure) { if (collider != null) { var model = collider.GetComponent <P3dModel>(); if (model != null) { var paintableTextures = P3dPaintableTexture.Filter(model, groups); if (paintableTextures.Count > 0) { var finalColor = color; var finalOpacity = opacity; var finalTexture = texture; P3dPaintableManager.BuildModifiers(gameObject); P3dPaintableManager.ModifyColor(ref finalColor); P3dPaintableManager.ModifyOpacity(ref finalOpacity); P3dPaintableManager.ModifyTexture(ref finalTexture); Command.Instance.SetMaterial(blendMode, finalTexture, finalColor, opacity); for (var i = paintableTextures.Count - 1; i >= 0; i--) { var paintableTexture = paintableTextures[i]; P3dPaintableManager.Submit(Command.Instance, model, paintableTexture, preview); } } } } }
public void HandleHitPoint(bool preview, int priority, Collider collider, Vector3 worldPosition, Quaternion worldRotation, float pressure) { if (collider != null) { var model = collider.GetComponent <P3dModel>(); if (model != null) { var paintableTextures = P3dPaintableTexture.Filter(model, group); if (paintableTextures.Count > 0) { var finalColor = color; var finalTexture = texture; P3dPaintableManager.BuildModifiers(gameObject); P3dPaintableManager.ModifyColor(pressure, ref finalColor); P3dPaintableManager.ModifyTexture(pressure, ref finalTexture); Command.Instance.SetState(preview, priority); Command.Instance.SetMaterial(finalTexture, finalColor); for (var i = paintableTextures.Count - 1; i >= 0; i--) { var paintableTexture = paintableTextures[i]; P3dPaintableManager.Submit(Command.Instance, model, paintableTexture); } } } } }
public void HandleHitPoint(List <P3dCommand> commands, List <P3dTransform> repeaters, bool preview, Collider collider, Vector3 worldPosition, Quaternion worldRotation, float pressure) { var finalOpacity = opacity + (1.0f - opacity) * opacityPressure * pressure; var finalRadius = radius + radiusPressure * pressure; var finalDepth = depth + depthPressure * pressure; var finalHardness = hardness + hardnessPressure * pressure; var finalColor = color; var finalAngle = angle; var finalTexture = texture; P3dPaintableManager.BuildModifiers(gameObject); P3dPaintableManager.ModifyColor(ref finalColor); P3dPaintableManager.ModifyAngle(ref finalAngle); P3dPaintableManager.ModifyOpacity(ref finalOpacity); P3dPaintableManager.ModifyHardness(ref finalHardness); P3dPaintableManager.ModifyRadius(ref finalRadius); P3dPaintableManager.ModifyTexture(ref finalTexture); worldRotation = worldRotation * Quaternion.Euler(0.0f, 0.0f, finalAngle); Command.Instance.SetLocation(worldPosition, worldRotation, scale, finalRadius, finalTexture, finalDepth); Command.Instance.SetMaterial(blendMode, texture, finalHardness, normalBack, normalFront, normalFade, finalColor, finalOpacity, shape); P3dPaintableManager.SubmitAll(Command.Instance, preview, layers, groups, targetModel, targetTexture, repeaters, commands); }
/// <summary>This method paints all pixels at the specified point using the shape of a sphere.</summary> public void HandleHitPoint(bool preview, int priority, float pressure, int seed, Vector3 position, Quaternion rotation) { if (paint != PaintType.In3D) { return; } if (modifiers != null && modifiers.Count > 0) { P3dHelper.BeginSeed(seed); modifiers.ModifyPosition(ref position, preview, pressure); P3dHelper.EndSeed(); } P3dCommandDecal.Instance.SetState(preview, priority); P3dCommandDecal.Instance.SetLocation(position); var worldSize = HandleHitCommon(preview, pressure, seed, rotation); var worldRadius = P3dHelper.GetRadius(worldSize); var worldPosition = position; HandleMaskCommon(worldPosition); P3dPaintableManager.SubmitAll(P3dCommandDecal.Instance, worldPosition, worldRadius, layers, group, targetModel, targetTexture); }
public void HandleHitPoint(bool preview, int priority, Collider collider, Vector3 worldPosition, Quaternion worldRotation, float pressure) { if (collider != null) { var model = collider.GetComponent <P3dModel>(); if (model != null) { var paintableTextures = P3dPaintableTexture.Filter(model, group); if (paintableTextures.Count > 0) { Command.Instance.SetState(preview, priority); Command.Instance.SetMaterial(textureR, textureG, textureB, textureA, channelR, channelG, channelB, channelA); for (var i = paintableTextures.Count - 1; i >= 0; i--) { var paintableTexture = paintableTextures[i]; P3dPaintableManager.Submit(Command.Instance, model, paintableTexture); } } } } }
public void HandleHitCoord(bool preview, int priority, float pressure, int seed, P3dHit hit, Quaternion rotation) { var model = hit.Root.GetComponentInParent <P3dModel>(); if (model != null) { var paintableTextures = P3dPaintableTexture.FilterAll(model, group); if (paintableTextures.Count > 0) { var finalColor = color; var finalOpacity = opacity; var finalTexture = texture; if (modifiers != null && modifiers.Count > 0) { P3dHelper.BeginSeed(seed); modifiers.ModifyColor(ref finalColor, preview, pressure); modifiers.ModifyOpacity(ref finalOpacity, preview, pressure); modifiers.ModifyTexture(ref finalTexture, preview, pressure); P3dHelper.EndSeed(); } P3dCommandFill.Instance.SetState(preview, priority); P3dCommandFill.Instance.SetMaterial(blendMode, finalTexture, finalColor, opacity, minimum); for (var i = paintableTextures.Count - 1; i >= 0; i--) { var paintableTexture = paintableTextures[i]; P3dPaintableManager.Submit(P3dCommandFill.Instance, model, paintableTexture); } } } }
/// <summary>This allows you to paint all pixels within a sphere at the specified point.</summary> public void HandleHitPoint(List <P3dCommand> commands, List <P3dTransform> repeaters, bool preview, Collider collider, Vector3 worldPosition, Quaternion worldRotation, float pressure) { var finalOpacity = opacity + (1.0f - opacity) * opacityPressure * pressure; var finalRadius = radius + radiusPressure * pressure; var finalHardness = hardness + hardnessPressure * pressure; var finalColor = color; var finalTexture = texture; P3dPaintableManager.BuildModifiers(gameObject); P3dPaintableManager.ModifyColor(ref finalColor); P3dPaintableManager.ModifyOpacity(ref finalOpacity); P3dPaintableManager.ModifyRadius(ref finalRadius); P3dPaintableManager.ModifyHardness(ref finalHardness); if (scale == Vector3.one) // Sphere? { Command.Instance.SetLocation(worldPosition, finalRadius); } else // Elipse? { Command.Instance.SetLocation(worldPosition, scale * finalRadius, rotateTo == RotationType.World ? worldRotation : Quaternion.identity); } Command.Instance.SetMaterial(blendMode, finalHardness, finalColor, finalOpacity, finalTexture, strength, tiling); P3dPaintableManager.SubmitAll(Command.Instance, preview, layers, groups, targetModel, targetTexture, repeaters, commands); }
protected override void OnEnable() { base.OnEnable(); if (activation == ActivationType.OnEnable && activated == false) { Activate(); } P3dPaintableManager.GetOrCreateInstance(); }
/// <summary>This method paints all pixels between two pairs of points using the shape of a sphere.</summary> public void HandleHitQuad(bool preview, int priority, Vector3 position, Vector3 endPosition, Vector3 position2, Vector3 endPosition2, Quaternion rotation, float pressure) { Command.Instance.SetState(preview, priority); Command.Instance.SetLocation(position, endPosition, position2, endPosition2); var worldSize = HandleHitCommon(rotation, pressure); var worldRadius = P3dHelper.GetRadius(worldSize, position, endPosition, position2, endPosition2); var worldPosition = P3dHelper.GetPosition(position, endPosition, position2, endPosition2); P3dPaintableManager.SubmitAll(Command.Instance, worldPosition, worldRadius, layers, group, targetModel, targetTexture); }
/// <summary>This method paints all pixels between three points using the shape of a sphere.</summary> public void HandleHitTriangle(bool preview, int priority, float pressure, int seed, Vector3 positionA, Vector3 positionB, Vector3 positionC, Quaternion rotation) { P3dCommandSphere.Instance.SetState(preview, priority); P3dCommandSphere.Instance.SetLocation(positionA, positionB, positionC); var worldSize = HandleHitCommon(preview, pressure, seed, rotation); var worldRadius = P3dHelper.GetRadius(worldSize, positionA, positionB, positionC); var worldPosition = P3dHelper.GetPosition(positionA, positionB, positionC); HandleMaskCommon(worldPosition); P3dPaintableManager.SubmitAll(P3dCommandSphere.Instance, worldPosition, worldRadius, layers, group, targetModel, targetTexture); }
public void HandleHitRaycast(bool preview, int priority, RaycastHit hit, float pressure) { var model = hit.collider.GetComponent <P3dModel>(); if (model != null) { var paintableTextures = P3dPaintableTexture.Filter(model, group); var finalOpacity = opacity + (1.0f - opacity) * opacityPressure * pressure; var finalRadius = radius + radiusPressure * pressure; var finalColor = color; var finalAngle = angle; var finalTexture = texture; P3dPaintableManager.BuildModifiers(gameObject); P3dPaintableManager.ModifyColor(pressure, ref finalColor); P3dPaintableManager.ModifyAngle(pressure, ref finalAngle); P3dPaintableManager.ModifyOpacity(pressure, ref finalOpacity); P3dPaintableManager.ModifyRadius(pressure, ref finalRadius); P3dPaintableManager.ModifyTexture(pressure, ref finalTexture); Command.Instance.SetMaterial(blendMode, finalTexture, finalColor, finalOpacity, shape); for (var i = paintableTextures.Count - 1; i >= 0; i--) { var paintableTexture = paintableTextures[i]; var coord = default(Vector2); switch (paintableTexture.Channel) { case P3dCoord.First: { coord = hit.textureCoord; } break; case P3dCoord.Second: { coord = hit.textureCoord2; } break; } Command.Instance.SetState(preview, priority); Command.Instance.SetLocation(paintableTexture.Current, coord, finalAngle, scale, finalRadius, texture); P3dPaintableManager.Submit(Command.Instance, model, paintableTexture); } } }
/// <summary>This allows you to paint all pixels within a capsule between the specified points.</summary> public void HandleHitLine(List <P3dCommand> commands, List <P3dTransform> repeaters, bool preview, Vector3 worldPositionA, Vector3 worldPositionB, float pressureA, float pressureB) { var finalOpacityA = opacity + (1.0f - opacity) * opacityPressure * pressureA; var finalRadiusA = radius + radiusPressure * pressureA; var finalHardnessA = hardness + hardnessPressure * pressureA; //var finalOpacityB = opacity + (1.0f - opacity) * opacityPressure * pressureB; //var finalRadiusB = radius + radiusPressure * pressureB; //var finalHardnessB = hardness + hardnessPressure * pressureB; Command.Instance.SetLocation(worldPositionA, worldPositionB, finalRadiusA); Command.Instance.SetMaterial(blendMode, finalHardnessA, color, finalOpacityA, texture, strength, tiling); P3dPaintableManager.SubmitAll(Command.Instance, preview, layers, groups, targetModel, targetTexture, repeaters, commands); }
/// <summary>This method paints all pixels between two pairs of points using the shape of a sphere.</summary> public void HandleHitQuad(bool preview, int priority, float pressure, int seed, Vector3 position, Vector3 endPosition, Vector3 position2, Vector3 endPosition2, Quaternion rotation) { if (paint != PaintType.In3D) { return; } P3dCommandDecal.Instance.SetState(preview, priority); P3dCommandDecal.Instance.SetLocation(position, endPosition, position2, endPosition2); var worldSize = HandleHitCommon(preview, pressure, seed, rotation); var worldRadius = P3dHelper.GetRadius(worldSize, position, endPosition, position2, endPosition2); var worldPosition = P3dHelper.GetPosition(position, endPosition, position2, endPosition2); HandleMaskCommon(worldPosition); P3dPaintableManager.SubmitAll(P3dCommandDecal.Instance, worldPosition, worldRadius, layers, group, targetModel, targetTexture); }
/// <summary>This method paints the scene using the current component settings at the specified <b>RaycastHit</b>. /// NOTE: The <b>rotation</b> argument is in world space, where <b>Quaternion.identity</b> means the paint faces forward on the +Z axis, and up is +Y.</summary> public void HandleHitRaycast(bool preview, int priority, float pressure, int seed, RaycastHit hit, Quaternion rotation) { if (paint == PaintType.In3D) { return; } var model = hit.collider.GetComponent <P3dModel>(); if (model != null) { var paintableTextures = P3dPaintableTexture.Filter(model, group); for (var i = paintableTextures.Count - 1; i >= 0; i--) { var paintableTexture = paintableTextures[i]; var coord = paintableTexture.GetCoord(ref hit); if (modifiers != null && modifiers.Count > 0) { var position = (Vector3)coord; P3dHelper.BeginSeed(seed); modifiers.ModifyPosition(ref position, preview, pressure); P3dHelper.EndSeed(); coord = position; } P3dCommandDecal.Instance.SetState(preview, priority); P3dCommandDecal.Instance.SetLocation(coord, false); HandleHitCommon(preview, pressure, seed, rotation); P3dCommandDecal.Instance.ApplyAspect(paintableTexture.Current); P3dPaintableManager.Submit(P3dCommandDecal.Instance, model, paintableTexture); } } }
public void HandleHitCoord(bool preview, int priority, float pressure, int seed, P3dHit hit, Quaternion rotation) { var model = hit.Root.GetComponentInParent <P3dModel>(); if (model != null) { var paintableTextures = P3dPaintableTexture.FilterAll(model, group); if (paintableTextures.Count > 0) { P3dCommandReplaceChannels.Instance.SetState(preview, priority); P3dCommandReplaceChannels.Instance.SetMaterial(textureR, textureG, textureB, textureA, channelR, channelG, channelB, channelA); for (var i = paintableTextures.Count - 1; i >= 0; i--) { var paintableTexture = paintableTextures[i]; P3dPaintableManager.Submit(P3dCommandReplaceChannels.Instance, model, paintableTexture); } } } }
private Vector3 HandleHitCommon(Quaternion rotation, float pressure) { var finalOpacity = opacity; var finalRadius = radius; var finalHardness = hardness; var finalColor = color; var finalTileMatrix = tileTransform != null ? tileTransform.localToWorldMatrix : Matrix4x4.identity; P3dPaintableManager.BuildModifiers(gameObject); P3dPaintableManager.ModifyColor(pressure, ref finalColor); P3dPaintableManager.ModifyOpacity(pressure, ref finalOpacity); P3dPaintableManager.ModifyRadius(pressure, ref finalRadius); P3dPaintableManager.ModifyHardness(pressure, ref finalHardness); var finalSize = scale * finalRadius; Command.Instance.SetShape(finalSize, rotateTo == RotationType.World ? Quaternion.identity : rotation); Command.Instance.SetMaterial(BlendMode, finalHardness, finalColor, finalOpacity, tileTexture, finalTileMatrix, tileBlend); return(finalSize); }
protected virtual void Update() { if (paintableTexture != null && paintableTexture.Activated == true) { if (speed > 0.0f) { counter += speed * Time.deltaTime; } if (counter >= threshold) { var step = Mathf.FloorToInt(counter * 255.0f); if (step > 0) { var change = step / 255.0f; counter -= change; P3dCommandFill.Instance.SetState(false, 0); P3dCommandFill.Instance.SetMaterial(blendMode, texture, color, Mathf.Min(change, 1.0f), Mathf.Min(change, 1.0f)); var command = P3dPaintableManager.Submit(P3dCommandFill.Instance, paintableTexture.Paintable, paintableTexture); if (maskPaintableTexture != null) { command.LocalMaskTexture = maskPaintableTexture.Current; command.LocalMaskChannel = P3dHelper.IndexToVector((int)maskChannel); } else if (maskTexture != null) { command.LocalMaskTexture = maskTexture; command.LocalMaskChannel = P3dHelper.IndexToVector((int)maskChannel); } } } } }
static Command() { cachedSpotMaterials = P3dPaintableManager.BuildMaterialsBlendModes("Hidden/Paint in 3D/Decal"); cachedLineMaterials = P3dPaintableManager.BuildMaterialsBlendModes("Hidden/Paint in 3D/Decal", "P3D_LINE"); cachedQuadMaterials = P3dPaintableManager.BuildMaterialsBlendModes("Hidden/Paint in 3D/Decal", "P3D_QUAD"); }
static Command() { cachedMaterial = P3dPaintableManager.BuildMaterial("Hidden/Paint in 3D/Replace"); }
private void Bake(RenderTexture temporary, int width, int height, RenderTextureFormat format, int scale) { if (bakedPixels == null) { bakedPixels = new List <bool>(); } else { bakedPixels.Clear(); } baked = true; bakedMesh = mesh; bakedSize = new Vector2Int(width, height); if (cachedMaterial == null) { cachedMaterial = P3dPaintableManager.BuildMaterial("Hidden/Paint in 3D/White"); } cachedMaterial.SetVector(P3dShader._Channel, P3dHelper.IndexToVector((int)PaintableTexture.Channel)); // Write to temp RenderTexture var oldActive = RenderTexture.active; var renderTexture = temporary; if (temporary == null) { var desc = new RenderTextureDescriptor(width, height, format, 0); renderTexture = P3dHelper.GetRenderTexture(desc); } RenderTexture.active = renderTexture; GL.Clear(true, true, Color.black); cachedMaterial.SetPass(0); Graphics.DrawMeshNow(mesh, Matrix4x4.identity, PaintableTexture.Slot.Index); RenderTexture.active = oldActive; // Get readable copy var readable = P3dHelper.GetReadableCopy(renderTexture); if (temporary == null) { P3dHelper.ReleaseRenderTexture(renderTexture); } // Run through pixels to count total and build binary mask bakedPixels.Capacity = width * height; total = 0; for (var y = 0; y < height; y++) { for (var x = 0; x < width; x++) { if (readable.GetPixel(x, y).r > 0.5f) { bakedPixels.Add(true); total += scale; } else { bakedPixels.Add(false); } } } // Clean up P3dHelper.Destroy(readable); }
static Command() { cachedMaterials = P3dPaintableManager.BuildMaterialsBlendModes("Hidden/Paint in 3D/Direct Decal"); }
private void BakeOverlap() { var desc = new RenderTextureDescriptor(1024, 1024, RenderTextureFormat.ARGB32, 0); var renderTexture = P3dHelper.GetRenderTexture(desc); if (overlapMaterial == null) { overlapMaterial = P3dPaintableManager.BuildMaterial("Hidden/Paint in 3D/Overlap"); } overlapMaterial.SetVector(P3dShader._Channel, P3dHelper.IndexToVector(coord)); var oldActive = RenderTexture.active; RenderTexture.active = renderTexture; GL.Clear(true, true, Color.black); overlapMaterial.SetPass(0); Graphics.DrawMeshNow(mesh, Matrix4x4.identity, submesh); RenderTexture.active = oldActive; overlapTex = P3dHelper.GetReadableCopy(renderTexture); P3dHelper.ReleaseRenderTexture(renderTexture); var utilizationCount = 0; var overlapCount = 0; for (var y = 0; y < overlapTex.height; y++) { for (var x = 0; x < overlapTex.width; x++) { var pixel = overlapTex.GetPixel(x, y); if (pixel.r > 0.0f) { if (pixel.r > 1.5 / 255.0f) { pixel = Color.red; overlapCount += 1; } else { pixel = Color.gray; } utilizationCount += 1; overlapTex.SetPixel(x, y, pixel); } } } var total = overlapTex.width * overlapTex.height * 0.01f; utilizationPercent = utilizationCount / total; overlapPercent = overlapCount / total; overlapTex.Apply(); }
private void Bake(RenderTexture renderTexture, int width, int height, int scale) { if (bakedPixels == null) { bakedPixels = new List <bool>(); } else { bakedPixels.Clear(); } bakedMesh = mesh; bakedSize = new Vector2Int(width, height); if (cachedMaterial == null) { cachedMaterial = P3dPaintableManager.BuildMaterial("Hidden/Paint in 3D/White"); } switch (PaintableTexture.Channel) { case P3dChannel.UV: cachedMaterial.SetVector(P3dShader._Channel, new Vector4(1.0f, 0.0f, 0.0f, 0.0f)); break; case P3dChannel.UV2: cachedMaterial.SetVector(P3dShader._Channel, new Vector4(0.0f, 1.0f, 0.0f, 0.0f)); break; case P3dChannel.UV3: cachedMaterial.SetVector(P3dShader._Channel, new Vector4(0.0f, 0.0f, 1.0f, 0.0f)); break; case P3dChannel.UV4: cachedMaterial.SetVector(P3dShader._Channel, new Vector4(0.0f, 0.0f, 0.0f, 1.0f)); break; } // Write to temp RenderTexture var oldActive = RenderTexture.active; RenderTexture.active = renderTexture; GL.Clear(true, true, Color.black); cachedMaterial.SetPass(0); Graphics.DrawMeshNow(mesh, Matrix4x4.identity, PaintableTexture.Slot.Index); RenderTexture.active = oldActive; // Get readable copy var readable = P3dHelper.GetReadableCopy(renderTexture); // Run through pixels to count total and build binary mask bakedPixels.Capacity = width * height; total = 0; for (var y = 0; y < height; y++) { for (var x = 0; x < width; x++) { if (readable.GetPixel(x, y).r > 0.5f) { bakedPixels.Add(true); total += scale; } else { bakedPixels.Add(false); } } } // Clean up P3dHelper.Destroy(readable); }
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; }
static Command() { cachedMaterials = P3dPaintableManager.BuildMaterialsBlendModes("Hidden/Paint in 3D/Sphere Triplanar"); }
static Command() { cachedMaterial = P3dPaintableManager.BuildMaterial("Hidden/Paint in 3D/Sphere Blur"); }
static Command() { cachedMaterials = P3dPaintableManager.BuildMaterialsBlendModes("Hidden/Paint in 3D/Fill"); cachedSwaps = P3dPaintableManager.BuildSwapBlendModes(); }