How To Create and Set Mesh Dynamically Using Script (C# or Javascript) On Sphere

Hello Everybody,

I am creating appolication like google earth. I want to create partition of sphere like
which is created for actual earth using langitide and latitude.

For that I have created Mesh in Maya and then imported it in Unity. This Mesh contains
different Materials and I can also change texture of this material run time using script.

But I want to create Mesh with different Matirials in Unity using scripting so that for
each material I can set different texture dynamically.

I am trying to do this things since many days but not getting how accomplish this.

If you can provide code for that then it will be better for me.

Thanks in Advance.

Hi Bhavesh. You don’t say what things you have tried, so guess I can only answer by going back to basics. I think you might want to create a sphere that has multiple textures. Think of it a bit like an onion with different shells. On the outside you have your regular world map and you use this when the zoom level tells you that most of the world is visible. Beneath this you might have a couple of second texture shells, that you constantly change the textures that are on them. You use some alpha values to control which of these three shells/textures are visible. I would imagine that all 3 shells can share the same UV map that you already have in place. However if you have a high res map of India that you want to use when the user is zoomed in on that sub-continent, you will want to recompute the UV values it uses. Possibly you can submit to your shader the Longitude and Latitude values that are at the centre of the screen, and the values that are at the bottom left and top right corners of your India texture. I’d suggest you look at how to convert the UVs from your world map into the UVs that apply to India.

Not sure how well I explained that. Think about it this way. Take your globe and stick a small postage stamp onto it. The postage stamp has UVs in the range 0…1. You’ve placed this on your global centred at some long/lat. What is the equation that converts long/lat into the UV range on the stamp.

Summarising, I think you have some maths to do, and then write a shader that can render the layers that you need, using the textures that you have. (And if you are not up for writing a shader yet, then emulate this with 3 spheres that are all slightly different sizes and just select which one to render. And you might be able to set texture offset and scale to emulate the UV calculations.)