Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by prodigee · Feb 09, 2017 at 03:32 PM · texturestexture atlassciptingwww.loadimageintotexture

How to apply texture to gameobject with texture atlas?

I'm trying to download a series of map tiles from an internet source, put them into a texture atlas, and then apply the "stitched" image as a single texture to an object. Because of the nature of the tiles, I can't simply use and use www.LoadImageIntoTexture - this will only work for a single image (I do implement this in my script, however). I read on some other forum answer that the best way to stitch images together in a collage-like fashion was to use a texture atlas. However, I've been running into issues that I believe may be due to a lack of understanding the texture atlas technique, or the C# language. I'm new to Unity.

I'm also using a coroutine within a for loop in order to populate my texture2d array. Not sure if this is the proper use of a coroutine, but I know I had to use one when experimenting with downloading a single image (waiting for the image to finish downloading in the start function) and applying it to a texture. I've been working in steps.

Each image is 256 x 256, which makes an 8x8 atlas of 2048 by 2048 pixels. I don't understand how to use the rects variable, but it was on the scripting documentation for the Texture2D.PackTextures page, so I figured I should probably include it?

Any help would be much appreciated! Here's my script for reference:

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class TextureEditor : MonoBehaviour {
 
     public Texture2D[] atlasTextures;
     public Rect[] rects;
 
     // Use this for initialization
     IEnumerator Start () {
 
         int idx = 0;
         for(int i = 0; i < 8; i++) //8 cols of tiled images
         {
             for(int j = 0; j < 8; j++) //8 rows
             {
                 string URL = System.String.Format("a.maps.owm.io:8099/589a02cf24cec8000135acd1/3/{a}/{b}?hash=0135e466b47705745ffa9e6a98379755", i, j); //URL is a custom map on OpenWeatherMap.com, you may not be able to test it, but I'm not sure
                 WWW www = new WWW("http://" + URL);
                 yield return www;
                 www.LoadImageIntoTexture(atlasTextures[idx]);
                 idx++;
             }
         }
         Texture2D atlas = new Texture2D(2048, 2048);
         rects = atlas.PackTextures(atlasTextures, 0, 2048); //what do I do with this?
 
         GetComponent<Renderer>().material.mainTexture = atlas; //this was honestly a total guess of what to do. I just know atlas is a texture object, thought maybe it would work.
     }
     
     // Update is called once per frame
     void Update () {
         
     }
 }

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Pink texture with Resources.Load 0 Answers

Sprites compression question (their size in build) 2 Answers

Texture lighting and seam issues 1 Answer

(C#) change texture and shadow resolution 0 Answers

Monocolor texture problem 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges