Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

X and Y scaling options are swapped when moving object. #3

Closed
SeymourSchlong opened this issue Apr 19, 2024 · 11 comments
Closed

X and Y scaling options are swapped when moving object. #3

SeymourSchlong opened this issue Apr 19, 2024 · 11 comments

Comments

@SeymourSchlong
Copy link
Contributor

image

Scaling the mesh doesnt seem to have this problem, so maybe should look into using that instead of the whole object.

@DeathWrench
Copy link
Owner

Reference image of Television Container hierarchy:
image
Television Mesh scale:
image
Does this not bug out the scale though? A value of 1 would make it huge I imagine. I was deterred by doing this since 1 as the default is easier to manage. I didn't even try the mesh way though. Ideally if it's buggy like how I imagine, 0.01108255 needs to be rounded to 1 to avoid having to use a calculator to scale things. Gonna get some sleep and update this at some point.

@SeymourSchlong
Copy link
Contributor Author

well if ~0.0111 is the default scale, could you not multiple the config value with it? should give the same result. only other thing to note is that the other components may also need to be scaled.

would be nice to know why it's scaled weird though -- may make for a better solution..

@DeathWrench
Copy link
Owner

Trying this, not working though:

public static class Patchez
{
    [HarmonyPatch(typeof(GameObject), "TelevisionContainer")]
    [HarmonyPostfix]
    public static void PostFix_adjustTVScale(GameObject __instance)
    {
        GameObject TelevisionContainer = __instance.gameObject.transform.parent.gameObject;
        GameObject televisionMesh = __instance.transform.Find("TelevisionMesh").gameObject;

        // Debug logging
        Debug.Log("Original scale: " + televisionMesh.transform.localScale);

        // Calculate new scale factors
        float scaleX = 0.01108255f * ConfigManager.tvScaleX.Value;
        float scaleY = 0.01108255f * ConfigManager.tvScaleY.Value;
        float scaleZ = 0.01108255f * ConfigManager.tvScaleZ.Value;

        // Apply new scale
        televisionMesh.transform.localScale = new Vector3(scaleX, scaleY, scaleZ);

        // Debug logging
        Debug.Log("New scale: " + televisionMesh.transform.localScale);

        TelevisionContainer.transform.GetComponentInChildren<PlaceableShipObject>().yOffset = 0.52f * (ConfigManager.tvScaleY.Value - 1) + 0.52f;
        if (!ConfigManager.configBiggerInteractRadius.Value)
        { return; }
        else 
        {
            GameObject cube = __instance.transform.Find("Cube").gameObject;
            cube.transform.localPosition = new Vector3(0.521f, 0.3f, -0.3f);
            cube.transform.localScale = new Vector3(1f, 1.1f, 1f);
        }
        return;
    }
}

@SeymourSchlong
Copy link
Contributor Author

try using TelevisionContainer.transform.Find("TelevisionMesh").gameObject instead of __instance.transform.Find("TelevisionMesh").gameObject

@DeathWrench
Copy link
Owner

Problem with these changes is that the TV is harder to interact with if you scale it up at all, interact radius no longer lines up with the buttons on the TV. Scaling TelevisionContainer was sort of responsible for the Bigger Interact Radius option TelevisionContainer being the parent of Cube made it properly scale with the TV (sort of) and now it doesn't
image

@SeymourSchlong
Copy link
Contributor Author

yeah, i mention in my first reply that it would be a better solution to find out why its scaled awkwardly

i should probably note that when scaling the mesh the X and Y values are swapped?

@SeymourSchlong
Copy link
Contributor Author

looking at the actual mesh, its rotated 90º itself, which would probably explain why it's swapped in the ghost object
image

@DeathWrench
Copy link
Owner

DeathWrench commented Apr 20, 2024

TelevisionContainer.transform.Find("TelevisionMesh").gameObject

That explains why the x and y was flipped, here's what I have now. I'm getting close.

public static class Patchez
{
    [HarmonyPatch(typeof(GameObject), "TelevisionContainer")]
    [HarmonyPostfix]
    public static void PostFix_adjustTVScale(GameObject __instance)
    {
        GameObject televisionContainer = __instance.gameObject.transform.parent.gameObject;
        GameObject televisionMesh = televisionContainer.transform.Find("TelevisionMesh").gameObject;
        televisionMesh.transform.localScale = new Vector3(0.01108255f * ConfigManager.tvScaleY.Value, 0.01108255f * ConfigManager.tvScaleX.Value, 0.01108255f * ConfigManager.tvScaleZ.Value);

        GameObject cube = televisionContainer.transform.Find("Cube").gameObject;
        Vector3 originalCubeScale = cube.transform.localScale;

        // Calculate the scaling ratio of TelevisionMesh in relation to the original scale of the Cube
        Vector3 scaleRatio = new Vector3(
            televisionMesh.transform.localScale.x * originalCubeScale.x,
            televisionMesh.transform.localScale.y * originalCubeScale.y,
            televisionMesh.transform.localScale.z * originalCubeScale.z
        );


        televisionContainer.transform.GetComponentInChildren<PlaceableShipObject>().yOffset = 0.52f * (ConfigManager.tvScaleY.Value - 1) + 0.52f;
        if (!ConfigManager.configBiggerInteractRadius.Value)
        {
            // Apply the scale ratio to the original scale of the Cube
            cube.transform.localScale = new Vector3(
                originalCubeScale.x * scaleRatio.x,
                originalCubeScale.y * scaleRatio.y,
                originalCubeScale.z// * scaleRatio.z
            );
        }
        else
        {
            cube.transform.localPosition = new Vector3(0.3f, 0.521f, -0.3f);
            cube.transform.localScale = new Vector3(1.1f * originalCubeScale.y, 1f * originalCubeScale.x, 1f);
        }
        return;
    }
}

EDIT:

public static class Patchez
{
    [HarmonyPatch(typeof(GameObject), "TelevisionContainer")]
    [HarmonyPostfix]
    public static void PostFix_adjustTVScale(GameObject __instance)
    {
        GameObject televisionContainer = __instance.gameObject.transform.parent.gameObject;
        GameObject televisionMesh = GameObject.Find("TelevisionMesh").gameObject;
        televisionMesh.transform.localScale = new Vector3(0.01108255f * ConfigManager.tvScaleY.Value, 0.01108255f * ConfigManager.tvScaleX.Value, 0.01108255f * ConfigManager.tvScaleZ.Value);

        GameObject cube = televisionContainer.transform.Find("Cube").gameObject;
        //cube.transform.SetParent(televisionMesh.transform, false); // sets the cube to be parented to the TelevisionMesh instead of TelevisionContainer. Breaks the television.

        televisionContainer.transform.GetComponentInChildren<PlaceableShipObject>().yOffset = 0.52f * (ConfigManager.tvScaleX.Value - 1) + 0.52f;
        if (!ConfigManager.configBiggerInteractRadius.Value)
        {
            cube.transform.localPosition = new Vector3(
                0.3115522f,
                0.01403493f,
                0.03700018f
            );

            cube.transform.localScale = new Vector3(
                ConfigManager.tvScaleY.Value * 0.2601791f,
                ConfigManager.tvScaleX.Value * 0.405167f,
                0.1014986f
            );
            // Scaling for when parented to TelevisionMesh instead of TelevisionContainer
            /*cube.transform.localPosition = new Vector3(
                0.9925914f,
                36.18302f,
                3.338597f
            );

            cube.transform.localScale = new Vector3(
                23.47646f,
                36.55901f,
                9.158413f
            );*/ 
        }
        else
        {
            cube.transform.localPosition = new Vector3(0.521f, 0.3f, -0.3f);
            cube.transform.localScale = new Vector3(
                ConfigManager.tvScaleY.Value * 1f, 
                ConfigManager.tvScaleX.Value * 1.1f, 
                ConfigManager.tvScaleZ.Value * 1f
            );
        }
        return;
    }
}

Been trying a lot of things, getting closer.

@DeathWrench
Copy link
Owner

Should be fixed with 8efcae3

@DeathWrench
Copy link
Owner

Opted not to scale the mesh since the math required to fix everything else is a pain in the ass:
bea3ce8
I got close here, just needed TVAudio scaled, didn't like the bloat though so I reverted it. I'm gonna re-open this and try alternative solutions.

@DeathWrench DeathWrench reopened this Apr 22, 2024
@DeathWrench
Copy link
Owner

Fixed again in 2.0.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants