Last active
November 11, 2023 01:44
-
-
Save Syfaro/583e6e1a949e0156fd022db0f05625eb to your computer and use it in GitHub Desktop.
Download OBJ previews of products from Bad Dragon
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from typing import List, Iterator | |
import os | |
import urllib.request | |
import json | |
from dataclasses import dataclass | |
import argparse | |
PRODUCT_URL = "https://bad-dragon.com/api/products" | |
SAVE_DIR = "models" | |
@dataclass | |
class DownloadableProduct: | |
name: str | |
preview_object_url: str | |
preview_texture_map_url: str | |
preview_normal_map_url: str | |
def load_products() -> List[dict]: | |
with urllib.request.urlopen(PRODUCT_URL) as f: | |
return json.load(f) | |
def process_products(products: List[dict]) -> Iterator[DownloadableProduct]: | |
for product in products: | |
name = product.get("sku") | |
preview_object_url = product.get("previewObjModel", {}).get("url") | |
preview_texture_map_url = product.get("previewTextureMap", {}).get("url") | |
preview_normal_map_url = product.get("previewNormalMap", {}).get("url") | |
if ( | |
not name | |
or not preview_object_url | |
or not preview_texture_map_url | |
or not preview_normal_map_url | |
): | |
continue | |
yield DownloadableProduct( | |
name, preview_object_url, preview_texture_map_url, preview_normal_map_url | |
) | |
def download_file(url: str, path: str) -> None: | |
if os.path.exists(path): | |
print("Already downloaded {path}".format(path=path)) | |
return | |
print("Downloading {path}".format(path=path)) | |
urllib.request.urlretrieve(url, path) | |
def download_product( | |
product: DownloadableProduct, save_dir: str, include_maps: bool = False | |
) -> None: | |
download_file( | |
product.preview_object_url, | |
os.path.join(save_dir, "{name}.obj".format(name=product.name)), | |
) | |
if include_maps: | |
download_file( | |
product.preview_texture_map_url, | |
os.path.join(save_dir, "{name}_texture_map.png".format(name=product.name)), | |
) | |
download_file( | |
product.preview_normal_map_url, | |
os.path.join(save_dir, "{name}_normal_map.png".format(name=product.name)), | |
) | |
if __name__ == "__main__": | |
parser = argparse.ArgumentParser(description="Download Bad Dragon preview objects.") | |
parser.add_argument( | |
"--maps", help="include texture and normal maps", action="store_true" | |
) | |
parser.add_argument("dir", help="Path to save models", nargs="?", default=SAVE_DIR) | |
args = parser.parse_args() | |
if not os.path.exists(args.dir): | |
os.mkdir(args.dir) | |
print("Saving objects to {dir}".format(dir=args.dir)) | |
products = load_products() | |
for product in process_products(products): | |
download_product(product, args.dir, args.maps) |
foxwearingbox
commented
Apr 19, 2023
via email
np
…On Tue, Apr 18, 2023 at 8:09 PM Zrksie ***@***.***> wrote:
***@***.**** commented on this gist.
------------------------------
you have to tell it to import .obj files, its one of the options in the
"files" tab i think
… <#m_3868553004770538132_>
Thank you it worked
—
Reply to this email directly, view it on GitHub
<https://gist.github.com/Syfaro/583e6e1a949e0156fd022db0f05625eb#gistcomment-4541246>
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AT2YWYEIQAE5VJRRKTJNJM3XB4UNPBFKMF2HI4TJMJ2XIZLTSKBKK5TBNR2WLJDHNFZXJJDOMFWWLK3UNBZGKYLEL52HS4DFQKSXMYLMOVS2I5DSOVS2I3TBNVS3W5DIOJSWCZC7OBQXE5DJMNUXAYLOORPWCY3UNF3GS5DZVRZXKYTKMVRXIX3UPFYGLK2HNFZXIQ3PNVWWK3TUUZ2G64DJMNZZDAVEOR4XAZNEM5UXG5FFOZQWY5LFVA4DGNJUGA3DAMNHORZGSZ3HMVZKMY3SMVQXIZI>
.
You are receiving this email because you commented on the thread.
Triage notifications on the go with GitHub Mobile for iOS
<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
or Android
<https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>
.
is there a way to construct the model with the texture maps to give it the high res look like the preveiw?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment