8
\$\begingroup\$

In Blender, I have created a sphere with a panoramic texture on the inside. I have also manually created a plane mesh (curved to match the size of the sphere) that sits on the inside wall where I can draw a different texture.

This is great, but I really want to reduce the manual labor, and do some of this work in a script -- like having a variable for the panoramic image, and coordinates of the area in the photograph that I want to replace with a new mesh.

The hardest part of doing this is going to be creating a curved mesh in code that can sit on the inside wall of a sphere.

Can anyone point me in the right direction?

\$\endgroup\$
  • \$\begingroup\$ Can you elaborate on what you would like to happen with less effort? Explain your current method and your end result in more detail? \$\endgroup\$ – Seth Battin Dec 19 '13 at 4:37
  • \$\begingroup\$ Also, why do these two meshes need to interact? Could you simply specify size and coordinates for the inner mesh, and draw it where ever it needs to be? Why does it need to be specified in terms of the outer sphere? \$\endgroup\$ – Seth Battin Dec 19 '13 at 4:38
  • \$\begingroup\$ I'd like to be able to map a equirectangular image on the inside of a sphere, and make rectangular picture frames (in the image) contain dynamic images. However, I don't want to recreate everything from the ground up each time I want to introduce a new equirectangular image.... To make it easy, I would like to take the flattened image, and use something like photoshop to find the xy coordinates of a picture frame, and have a new mesh that shrink wrapped to the sphere which corresponds to those 2d coordinates. \$\endgroup\$ – user5025 Dec 19 '13 at 6:06
  • \$\begingroup\$ You're aware that Unity supports skyboxes? It sounds like that's what you're trying to achieve. \$\endgroup\$ – MichaelHouse Dec 19 '13 at 6:18
  • \$\begingroup\$ I'm aware of skyboxes, but it doesn't solve my problem unfortunately. I need a way to create a curved mesh (that will sit perfecltly on the inside of a sphere), based on the coordinates of a picture frame in an equirectangular image. \$\endgroup\$ – user5025 Dec 19 '13 at 7:50
0
\$\begingroup\$

What you are trying to achieve seems very much related to this :

Analogue of spherical coordinates in n-dimensions

in your case in 2 dimensions then you just use this formula to map the vertices of rectangle you have (lets hope it is subdivided) on your sphere (dont forget to multiply by the halfDiameter somewhere. Only mathematicians are living on a unit sphere all other decent people are using diameters...)

EDIT : As all this is a bit vague i give some more insights What you need from this formula to be used :

x = r*sinθ*cosφ
y = r*sinθ*sinφ
z = r*cosθ

θ and φ being the spherical coordinates you are looking for (Latitude and Longitude) to get it you take the x/y coordinates of the points on portion of the panoramic image as such :

public Void getPointPosOnSphere(float Longitude,float Latitude,float r) {
    x = r*Mathf.sin(Longitude)*Mathf.cos(Latitude);
    y = r*Mathf.sin(Longitude)*Mathf.sin(Latitude);
    z = r*Mathf.cos(Longitude);
    return new Vector3(x,y,z);
}

//here you could have a for loop iterating through points of your rectangle for each
//point you'd have associated a map coordinate :
Vector3 pointSpacePos = getPointPosOnSphere(pointCoordY,pointCoordX,HalfDiamater);
//End of the for loop

then you would get your quad mapped on a sphere based from his xy position on a 2D coordinate system translated to the 3D position on the space according to sphere mapping.

EDIT : Just got an idea, to go further you could encapsulate the coordinates of the plane on the sphere using UV values as such :

for(int i = 0;i < vertices.Length; i++) {
    vertices[i] = getPointPosOnSphere(UV[i].y,UV[i].x,HalfDiamater);
}

There you could manage the quad position on your favorite 3D software (or even by code through unity) just by assigning UV values (if from 0 to 1 on both axes then quad will be wrapped all around the sphere)

WARNING : Using UV's will require you to do a Radians to Degrees conversion. (as UV is 0 to 1)

| improve this answer | |
\$\endgroup\$
0
\$\begingroup\$

Géry Arduino's answer above pointed me in the right direction, but I would like to add couple of things here.

1) Following will not work in unity because of coordinate system differences

    return new Vector3(x,y,z); 

change this to

    return new Vector3(x,z,y);

2) I was not clear on input range of long and lat values defined in the method signature

     public Void getPointPosOnSphere(float Longitude,float Latitude,float r)

Both Longitude and Latitude values should be in radians. Their range is as follows

     Longitude: 0°-180° (0 - π)
     Latitude: 0°-360° (0 - 2π)
| improve this answer | |
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.