Exemplo n.º 1
0
        public Texture FindTexture(GameObject gameObject)
        {
            if (gameObject != null)
            {
                var paintable = gameObject.GetComponentInParent <P3dPaintable>();

                if (paintable != null)
                {
                    var material = P3dHelper.GetMaterial(paintable.CachedRenderer, Index);

                    if (material != null && material.HasProperty(Name) == true)
                    {
                        return(material.GetTexture(Name));
                    }
                }
            }

            return(null);
        }
        private void Apply(RenderTexture renderTexture)
        {
            var renderer  = Parent.Root.GetComponent <Renderer>();
            var materials = renderer.sharedMaterials;
            var material  = materials[MaterialIndex];

            material.SetTexture(SlotName, OldTexture);

            //var textureImporter = P3dHelper.GetAssetImporter<TextureImporter>(OldTexture);

            //if (QualitySettings.activeColorSpace == ColorSpace.Linear && textureImporter != null && textureImporter.sRGBTexture == true)
            //{
            //	P3dHelper.ReadPixelsLinearGamma(OldTexture, renderTexture);
            //}
            //else
            //{
            P3dHelper.ReadPixels(OldTexture, renderTexture);
            //}
        }
Exemplo n.º 3
0
        protected override void OnInspector()
        {
            if (P3dPreset.CachedPresets.Contains(Target) == false && P3dHelper.IsAsset(Target) == true)
            {
                P3dPreset.CachedPresets.Add(Target);
            }

            EditorGUILayout.HelpBox("You can use this preset from the Paint in 3D window after making an object paintable.", MessageType.Info);

            Draw("title", "This allows you to name this preset.\n\nNone/null = The GameObject name will be used.");
            Draw("addMaterialCloner", "Automatically add the P3dMaterialCloner.");

            if (AnyDrawInvalidIndex() == true)
            {
                EditorGUILayout.Separator();

                EditorGUILayout.HelpBox("P3dPaintableTexture slot index values should be 0 for presets, because they will be overwritten when added.", MessageType.Warning);
            }
        }
Exemplo n.º 4
0
        private void Calculate()
        {
            if (paintableTexture != null && paintableTexture.Activated == true)
            {
                var renderTexture = paintableTexture.Current;
                var temporary     = default(RenderTexture);

                if (P3dHelper.Downsample(renderTexture, downsampleSteps, ref temporary) == true)
                {
                    Calculate(temporary, 1 << downsampleSteps);

                    P3dHelper.ReleaseRenderTexture(temporary);
                }
                else
                {
                    Calculate(renderTexture, 1);
                }
            }
        }
Exemplo n.º 5
0
        protected virtual void OnDestroy()
        {
            if (activated == true)
            {
                if (string.IsNullOrEmpty(saveName) == false)
                {
                    Save();
                }

                P3dHelper.ReleaseRenderTexture(current);

                if (previewSet == true)
                {
                    P3dHelper.ReleaseRenderTexture(preview);
                }

                ClearStates();
            }
        }
Exemplo n.º 6
0
        private void UpdateFinger(int index, Vector2 screenPosition, float pressure, bool up)
        {
            for (var i = fingers.Count - 1; i >= 0; i--)
            {
                var finger = fingers[i];

                if (finger.Index == index)
                {
                    finger.Pressure  = pressure;
                    finger.Down      = false;
                    finger.Up        = up;
                    finger.PositionD = finger.PositionC;
                    finger.PositionC = finger.PositionB;
                    finger.PositionB = finger.PositionA;
                    finger.PositionA = screenPosition;

                    finger.SmoothPositions.Clear();

                    finger.SmoothPositions.Add(finger.PositionC);

                    if (up == true)
                    {
                        finger.SmoothPositions.Add(finger.PositionB);
                        finger.SmoothPositions.Add(finger.PositionA);
                    }
                    else
                    {
                        var steps = Mathf.FloorToInt(Vector2.Distance(finger.PositionB, finger.PositionC));
                        var step  = P3dHelper.Reciprocal(steps);

                        for (var j = 1; j <= steps; j++)
                        {
                            var head = Hermite(finger.PositionD, finger.PositionC, finger.PositionB, finger.PositionA, j * step);

                            finger.SmoothPositions.Add(head);
                        }
                    }

                    break;
                }
            }
        }
Exemplo n.º 7
0
        private void CheckCollision(Collision collision)
        {
            if (cooldown > 0.0f)
            {
                return;
            }

            // Only handle the collision if the impact was strong enough
            if (collision.relativeVelocity.magnitude > threshold)
            {
                cooldown = delay;

                // Calculate up vector ahead of time
                var finalUp  = orientation == OrientationType.CameraUp ? P3dHelper.GetCameraUp(_camera) : Vector3.up;
                var contacts = collision.contacts;

                for (var i = contacts.Length - 1; i >= 0; i--)
                {
                    var contact       = contacts[i];
                    var finalPosition = contact.point + contact.normal * offset;
                    var finalRotation = Quaternion.LookRotation(-contact.normal, finalUp);

                    hitCache.InvokePoints(gameObject, null, null, false, contact.otherCollider, finalPosition, finalRotation, 1.0f);

                    if (raycastDistance > 0.0f)
                    {
                        var ray = new Ray(contact.point + contact.normal * raycastDistance, -contact.normal);
                        var hit = default(RaycastHit);

                        if (contact.otherCollider.Raycast(ray, out hit, raycastDistance * 2.0f) == true)
                        {
                            hitCache.InvokeRaycast(gameObject, null, null, false, hit, 1.0f);
                        }
                    }

                    if (onlyUseFirstContact == true)
                    {
                        break;
                    }
                }
            }
        }
Exemplo n.º 8
0
        public string GetTitle(Material material)
        {
            if (material != null)
            {
                var shader = material.shader;

                if (shader != null)
                {
                    foreach (var texEnv in P3dHelper.GetTexEnvs(shader))
                    {
                        if (texEnv.Name == Name)
                        {
                            return(texEnv.Title);
                        }
                    }
                }
            }

            return(Name);
        }
        /// <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 (modifiers != null && modifiers.Count > 0)
            {
                P3dHelper.BeginSeed(seed);
                modifiers.ModifyPosition(ref position, preview, pressure);
                P3dHelper.EndSeed();
            }

            P3dCommandSphere.Instance.SetState(preview, priority);
            P3dCommandSphere.Instance.SetLocation(position);

            var worldSize     = HandleHitCommon(preview, pressure, seed, rotation);
            var worldRadius   = P3dHelper.GetRadius(worldSize);
            var worldPosition = position;

            HandleMaskCommon(worldPosition);

            P3dPaintableManager.SubmitAll(P3dCommandSphere.Instance, worldPosition, worldRadius, layers, group, targetModel, targetTexture);
        }
Exemplo n.º 10
0
            public void Resize()
            {
                foreach (var slot in Slots)
                {
                    if (slot.Texture != null)
                    {
                        if (slot.Texture.width != Width || slot.Texture.height != Height)
                        {
                            var desc           = slot.Texture.descriptor; desc.width = Width; desc.height = Height;
                            var resizedTexture = P3dHelper.GetRenderTexture(desc);

                            P3dPaintReplace.Blit(resizedTexture, slot.Texture, Color.white);

                            P3dHelper.ReleaseRenderTexture(slot.Texture);

                            slot.Texture = resizedTexture;
                        }
                    }
                }
            }
Exemplo n.º 11
0
        public static P3dMask Find(Vector3 position, LayerMask layers)
        {
            var bestMask     = default(P3dMask);
            var bestDistance = float.PositiveInfinity;

            foreach (var instance in instances)
            {
                if (P3dHelper.IndexInMask(instance.gameObject.layer, layers) == true)
                {
                    var distance = Vector3.SqrMagnitude(position - instance.transform.position);

                    if (distance < bestDistance)
                    {
                        bestMask = instance;
                    }
                }
            }

            return(bestMask);
        }
Exemplo n.º 12
0
        /// <summary>This method will replace the current texture state with the specified image data (e.g. png).</summary>
        public void LoadFromData(byte[] data, bool allowResize = true)
        {
            if (data != null && data.Length > 0)
            {
                var tempTexture = new Texture2D(1, 1, TextureFormat.ARGB32, false, QualitySettings.activeColorSpace == ColorSpace.Linear);

                tempTexture.LoadImage(data);

                if (allowResize == true)
                {
                    Replace(tempTexture, Color.white);
                }
                else
                {
                    Clear(tempTexture, Color.white);
                }

                P3dHelper.Destroy(tempTexture);
            }
        }
        protected virtual void Update()
        {
            var finalCounters = counters.Count > 0 ? counters : null;
            var total         = P3dChangeCounter.GetTotal(finalCounters);
            var count         = P3dChangeCounter.GetCount(finalCounters);

            if (inverse == true)
            {
                count = total - count;
            }

            var final   = format;
            var percent = P3dHelper.RatioToPercentage(P3dHelper.Divide(count, total), decimalPlaces);

            final = final.Replace("{TOTAL}", total.ToString());
            final = final.Replace("{COUNT}", count.ToString());
            final = final.Replace("{PERCENT}", percent.ToString());

            cachedText.text = final;
        }
        public void GetPrepared(ref Mesh mesh, ref Matrix4x4 matrix)
        {
            if (prepared == false)
            {
                prepared = true;

                if (cachedRendererSet == false)
                {
                    CacheRenderer();
                }

                if (cachedSkinnedSet == true)
                {
                    if (bakedMeshSet == false)
                    {
                        bakedMesh    = new Mesh();
                        bakedMeshSet = true;
                    }

                    var scaling       = P3dHelper.Reciprocal3(cachedTransform.lossyScale);
                    var oldLocalScale = cachedTransform.localScale;

                    cachedTransform.localScale = Vector3.one;

                    cachedSkinned.BakeMesh(bakedMesh);

                    cachedTransform.localScale = oldLocalScale;

                    preparedMesh   = bakedMesh;
                    preparedMatrix = cachedTransform.localToWorldMatrix * Matrix4x4.Scale(scaling);
                }
                else
                {
                    preparedMesh   = cachedFilter.sharedMesh;
                    preparedMatrix = transform.localToWorldMatrix;
                }
            }

            mesh   = preparedMesh;
            matrix = preparedMatrix;
        }
Exemplo n.º 15
0
        protected override void OnInspector()
        {
            if (Any(t => t.Activated == true))
            {
                EditorGUILayout.HelpBox("This component has been activated.", MessageType.Info);
            }

            DrawExpand(ref expandSlot, "slot", "The material index and shader texture slot name that this component will paint.");
            if (expandSlot == true)
            {
                BeginIndent();
                BeginDisabled();
                EditorGUI.ObjectField(P3dHelper.Reserve(), new GUIContent("Texture", "This is the current texture in the specified texture slot."), Target.Slot.FindTexture(Target.gameObject), typeof(Texture), false);
                EndDisabled();
                EndIndent();
            }
            Draw("coord", "The UV channel this texture is mapped to.");
            Draw("shaderKeyword", "Some shaders require specific shader keywords to be enabled when adding new textures. If there is no texture in your selected slot then you may need to set this keyword.");

            Separator();

            Draw("group", "The group you want to associate this texture with. Only painting components with a matching group can paint this texture. This allows you to paint multiple textures at the same time with different settings (e.g. Albedo + Normal).");
            Draw("state", "This allows you to set how this texture's state is stored. This allows you to perform undo and redo operations.\n\nFullTextureCopy = A full copy of your texture will be copied for each state. This allows you to quickly undo and redo, and works with animated skinned meshes, but it uses up a lot of texture memory.\n\nLocalCommandCopy = Each paint command will be stored in local space for each state. This allows you to perform unlimited undo and redo states with minimal memory usage, because the object will be repainted from scratch. However, performance will depend on how many states must be redrawn.");
            if (Any(t => t.State == P3dPaintableTexture.StateType.FullTextureCopy))
            {
                BeginIndent();
                Draw("stateLimit", "The amount of times this texture can have its paint operations undone.", "Limit");
                EndIndent();
            }
            Draw("saveName", "If you want this texture to automatically save/load, then you can set the unique save name for it here. Keep in mind this setting won't work properly with prefab spawning since all clones will share the same SaveName.");

            Separator();

            Draw("format", "The format of the created texture.");
            Draw("mipMaps", "The mip maps of the created texture.\n\nAuto = On or Off based on the <b>Texture</b> mip map count.\n\nForceOn = Always enabled.\n\nForceOff = Always disabled.");
            Draw("keepUnpaintable", "If you disable this, then the unpaintable areas of this texture be discarded, and thus improve painting performance.\n\nNOTE: This is on by default, because some effects may require them to be preserved.");

            DrawSize();
            DrawTexture();
            Draw("color", "When activated or cleared, this paintable texture will be given this color.\n\nNOTE: If Texture is set, then each pixel RGBA value will be multiplied/tinted by this color.");
        }
Exemplo n.º 16
0
        public void Activate()
        {
            if (activated == false)
            {
                UpdateMaterial();

                if (material != null)
                {
                    var finalWidth   = width;
                    var finalHeight  = height;
                    var finalTexture = material.GetTexture(slot.Name);

                    CachedPaintable.ScaleSize(ref finalWidth, ref finalHeight);

                    if (texture != null)
                    {
                        finalTexture = texture;
                    }

                    if (string.IsNullOrEmpty(shaderKeyword) == false)
                    {
                        material.EnableKeyword(shaderKeyword);
                    }

                    current = P3dHelper.GetRenderTexture(finalWidth, finalHeight, 0, format);

                    P3dPaintReplace.Blit(current, finalTexture, color);

                    material.SetTexture(slot.Name, current);

                    activated = true;

                    if (string.IsNullOrEmpty(saveName) == false)
                    {
                        Load();
                    }

                    NotifyOnModified(false);
                }
            }
        }
Exemplo n.º 17
0
        /// <summary>This allows you to get a list of all paintable textures on a P3dModel/P3dPaintable within the specified group mask.</summary>
        public static List <P3dPaintableTexture> Filter(P3dModel model, int groupMask)
        {
            tempPaintableTextures.Clear();

            if (model.Paintable != null)
            {
                var paintableTextures = model.Paintable.PaintableTextures;

                for (var i = paintableTextures.Count - 1; i >= 0; i--)
                {
                    var paintableTexture = paintableTextures[i];

                    if (P3dHelper.IndexInMask(paintableTexture.group, groupMask) == true)
                    {
                        tempPaintableTextures.Add(paintableTexture);
                    }
                }
            }

            return(tempPaintableTextures);
        }
Exemplo n.º 18
0
        protected override void OnInspector()
        {
            TARGET tgt; TARGET[] tgts; GetTargets(out tgt, out tgts);

            if (P3dPreset.CachedPresets.Contains(tgt) == false && P3dHelper.IsAsset(tgt) == true)
            {
                P3dPreset.CachedPresets.Add(tgt);
            }

            Info("You can use this preset from the Paint in 3D window after making an object paintable.");

            Draw("title", "This allows you to name this preset.\n\nNone/null = The GameObject name will be used.");
            Draw("addMaterialCloner", "Automatically add the P3dMaterialCloner.");

            if (AnyDrawInvalidIndex(tgts) == true)
            {
                Separator();

                Warning("P3dPaintableTexture slot index values should be 0 for presets, because they will be overwritten when added.");
            }
        }
Exemplo n.º 19
0
        protected override void OnInspector()
        {
            if (All(t => t.Activated == true))
            {
                EditorGUILayout.HelpBox("This component has already activated.", MessageType.Info);
            }

            if (Any(t => t.Activated == false))
            {
                BeginError(Any(t => t.Index < 0 || t.Index >= t.GetComponent <Renderer>().sharedMaterials.Length));
                DrawDefault("index", "The material index that will be cloned. This matches the Materials list in your MeshRenderer/SkinnedMeshRenderer, where 0 is the first material.");
                EndError();
                BeginDisabled();
                EditorGUILayout.ObjectField("Material", P3dHelper.GetMaterial(Target.gameObject, Target.Index), typeof(Material), false);
                EndDisabled();

                Separator();

                DrawDefault("otherRenderers", "If this material is used in multiple renderers, you can specify them here. This usually happens with different LOD levels.");
            }
        }
Exemplo n.º 20
0
            private static bool Blit(Material cachedMaterial, ref RenderTexture renderTexture)
            {
                if (cachedSwap == true)
                {
                    var swap = P3dHelper.GetRenderTexture(renderTexture.width, renderTexture.height, renderTexture.depth, renderTexture.format);

                    cachedMaterial.SetTexture(P3dShader._Buffer, renderTexture);

                    P3dHelper.Blit(swap, cachedMaterial);

                    P3dHelper.ReleaseRenderTexture(renderTexture);

                    renderTexture = swap;

                    return(true);
                }

                P3dHelper.Blit(renderTexture, cachedMaterial);

                return(false);
            }
        public RenderTexture PreparePaint()
        {
            if (Locked == true)
            {
                var renderer   = Parent.Root.GetComponent <Renderer>();
                var materials  = renderer.sharedMaterials;
                var material   = materials[MaterialIndex];
                var colorSpace = Colors;

                if (colorSpace == RenderTextureReadWrite.Default)
                {
                    var importer = P3dHelper.GetAssetImporter <TextureImporter>(OldTexture);

                    if (importer != null)
                    {
                        colorSpace = importer.sRGBTexture == true ? RenderTextureReadWrite.sRGB : RenderTextureReadWrite.Linear;
                    }
                }

                if (NewTexture == null)
                {
                    NewTexture = P3dHelper.GetRenderTexture(OldTexture.width, OldTexture.height, 0, RenderTextureFormat.ARGB32, colorSpace);

                    P3dHelper.Blit(NewTexture, OldTexture);
                }

                if (NewTexture.width != OldTexture.width || NewTexture.height != OldTexture.height)
                {
                    NewTexture = P3dHelper.GetRenderTexture(OldTexture.width, OldTexture.height, 0, RenderTextureFormat.ARGB32, colorSpace);

                    P3dHelper.Blit(NewTexture, OldTexture);
                }

                material.SetTexture(SlotName, NewTexture);

                return(NewTexture);
            }

            return(null);
        }
Exemplo n.º 22
0
        private void ExecuteCommands(List <P3dCommand> commands, bool sendNotifications, ref RenderTexture main, ref RenderTexture swap, ref Mesh preparedMesh, ref Matrix4x4 preparedMatrix)
        {
            RenderTexture.active = main;

            for (var i = 0; i < commands.Count; i++)
            {
                var command = commands[i];

                RenderTexture.active = swap;

                command.Apply(main);

                if (command.RequireMesh == true)
                {
                    paintable.GetPrepared(ref preparedMesh, ref preparedMatrix);

                    P3dHelper.Draw(command.Material, preparedMesh, preparedMatrix, slot.Index, coord);
                }
                else
                {
                    P3dHelper.Draw(command.Material);
                }

                P3dHelper.Swap(ref main, ref swap);

                command.Pool();
            }

            commands.Clear();

            if (main.useMipMap == true)
            {
                main.GenerateMips();
            }

            if (sendNotifications == true)
            {
                NotifyOnModified(commands == previewCommands);
            }
        }
Exemplo n.º 23
0
        private void HandleExport()
        {
            var basePath = AssetDatabase.GetAssetPath(scene);

            if (string.IsNullOrEmpty(basePath) == true)
            {
                basePath = "Assets/";
            }
            else
            {
                basePath = System.IO.Path.GetDirectoryName(basePath) + "/";
            }

            foreach (var mat in scene.Mats)
            {
                if (mat.Template != null)
                {
                    foreach (var matSlot in mat.Slots)
                    {
                        var sceneSlot = mat.Template.Slots.FirstOrDefault(s => s.Name == matSlot.Name);

                        if (sceneSlot != null && matSlot.Texture != null)
                        {
                            var path    = basePath + settings.ExportFormat.Replace("{SCENE}", scene.name).Replace("{MATERIAL}", mat.Name).Replace("{TEXTURE}", sceneSlot.GetAlias()) + ".png";
                            var texture = P3dHelper.GetReadableCopy(matSlot.Texture);
                            var data    = texture.EncodeToPNG();

                            DestroyImmediate(texture);

                            System.IO.File.WriteAllBytes(path, data);

                            Debug.Log("EXPORT " + path);
                        }
                    }
                }
            }

            AssetDatabase.SaveAssets();
            AssetDatabase.Refresh();
        }
Exemplo n.º 24
0
        /// <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);
                }
            }
        }
        protected virtual void Update()
        {
            // Calculate delta
            if (CanRotate == true && Application.isPlaying == true)
            {
                var delta = P3dInputManager.GetAverageDeltaScaled(fingers);

                pitch -= delta.y * pitchSensitivity;
                yaw   += delta.x * yawSensitivity;
            }

            pitch = Mathf.Clamp(pitch, pitchMin, pitchMax);

            // Smoothly dampen values
            var factor = P3dHelper.DampenFactor(dampening, Time.deltaTime);

            currentPitch = Mathf.Lerp(currentPitch, pitch, factor);
            currentYaw   = Mathf.Lerp(currentYaw, yaw, factor);

            // Apply new rotation
            transform.localRotation = Quaternion.Euler(currentPitch, currentYaw, 0.0f);
        }
Exemplo n.º 26
0
        protected override void OnInspector()
        {
            if (P3dMaterial.CachedMaterials.Contains(Target) == false && P3dHelper.IsAsset(Target) == true)
            {
                P3dMaterial.CachedMaterials.Add(Target);
            }

            Draw("category");
            Draw("icon");

            EditorGUILayout.Separator();

            EditorGUILayout.LabelField("Material Builder", EditorStyles.boldLabel);

            DrawMaterialBuilder();

            EditorGUILayout.Separator();

            EditorGUILayout.LabelField("Icon Builder", EditorStyles.boldLabel);

            DrawIconBuilder();
        }
Exemplo n.º 27
0
        protected virtual void Update()
        {
            inputManager.Update(key);

            if (prefab != null)
            {
                var fingers = inputManager.Fingers;

                if (fingers.Count == 1 && fingers[0].Down == true && fingers[0].StartedOverGui == false)
                {
                    var camera = P3dHelper.GetCamera();

                    if (camera != null)
                    {
                        if (storeStates == true)
                        {
                            P3dStateManager.StoreAllStates();
                        }

                        // Find the ray for this screen position
                        var ray      = camera.ScreenPointToRay(P3dInputManager.MousePosition);
                        var rotation = Quaternion.LookRotation(ray.direction);

                        // Loop through all prefabs and spawn them
                        var clone = Instantiate(prefab, ray.origin, rotation);

                        clone.SetActive(true);

                        // Throw with velocity?
                        var cloneRigidbody = clone.GetComponent <Rigidbody>();

                        if (cloneRigidbody != null)
                        {
                            cloneRigidbody.velocity = clone.transform.forward * Speed;
                        }
                    }
                }
            }
        }
Exemplo n.º 28
0
        public void UpdateRequest()
        {
#if ASYNC_READBACK_SUPPORTED
            if (requested == true)
            {
                if (request.hasError == true)
                {
                    requested = false;

                    CompleteDirectly();
                }
                else if (request.done == true)
                {
                    requested = false;

                    buffer = P3dHelper.ReleaseRenderTexture(buffer);

                    OnComplete(request.GetData <Color32>());
                }
            }
#endif
        }
        private IEnumerator DelayedOnHit(Vector3 pointA, Vector3 pointB)
        {
            var vector      = pointB - pointA;
            var maxDistance = vector.magnitude;
            var ray         = new Ray(pointA, vector);
            var hit         = default(RaycastHit);

            if (Physics.Raycast(ray, out hit, maxDistance, layers) == true)
            {
                var distance01 = Mathf.InverseLerp(0.0f, radius, hit.distance);

                // Wait based on hit distance
                yield return(new WaitForSeconds(distance01 * delayMax));

                var finalUp       = orientation == OrientationType.CameraUp ? P3dHelper.GetCameraUp(_camera) : Vector3.up;
                var finalPosition = hit.point + hit.normal * offset;
                var finalNormal   = normal == NormalType.HitNormal ? -hit.normal : ray.direction;
                var finalRotation = Quaternion.LookRotation(finalNormal, finalUp);

                hitCache.InvokePoints(gameObject, preview, priority, hit.collider, finalPosition, finalRotation, 1.0f - distance01);
            }
        }
Exemplo n.º 30
0
        public bool IsTransformed(GameObject gameObject)
        {
            if (gameObject != null)
            {
                var paintable = gameObject.GetComponentInParent <P3dPaintable>();

                if (paintable != null)
                {
                    var material = P3dHelper.GetMaterial(paintable.CachedRenderer, Index);

                    if (material != null)
                    {
                        if (material.GetTextureScale(Name) != Vector2.one || material.GetTextureOffset(Name) != Vector2.zero)
                        {
                            return(true);
                        }
                    }
                }
            }

            return(false);
        }