Skip to content

Commit

Permalink
Merge pull request #244 from princeton-vl/static_asset_patch
Browse files Browse the repository at this point in the history
fix hello_world_crash, change external asset spec to path
  • Loading branch information
pvl-bot committed Aug 20, 2024
2 parents e63767c + 83b558f commit 04fe4d3
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 25 deletions.
27 changes: 22 additions & 5 deletions docs/StaticAssets.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ I would recommend using .glb or .gltf files since they are the most extensively

1. Download the following assets in .glb format from Sketchfab:

- [Iron Shelf](https://sketchfab.com/3d-models/iron-shelf-fd0cd420ffe04ac08174926f6b175d3f) (Attributed to Thunder and is licensed under CC BY-SA 4.0. We use this asset with modification, i.e. merge parts, scale).
- [Iron Shelf](https://sketchfab.com/3d-models/iron-shelf-fd0cd420ffe04ac08174926f6b175d3f) (Attributed to Thunder and is licensed under [CC BY-SA 4.0](https://creativecommons.org/licenses/by-sa/4.0/). We use this asset with modification, i.e. rendered image).

- [Office Couch](https://sketchfab.com/3d-models/office-couch-ca63db1db205476fa6f54e1603b7d15d) (Attributed to Virenimation and is licensed under CC BY 4.0. We use this asset with modification, i.e. merge parts, scale).
- [Office Couch](https://sketchfab.com/3d-models/office-couch-ca63db1db205476fa6f54e1603b7d15d) (Attributed to Virenimation and is licensed under [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/). We use this asset with modification, i.e. rendered image).

- [Table](https://sketchfab.com/3d-models/de-table-63e4d8faac73435fa7e9e929baa2c175) (Attributed to DeCloud and is licensed under CC BY 4.0. We use this asset with modification, i.e. merge parts, scale).
- [Table](https://sketchfab.com/3d-models/de-table-63e4d8faac73435fa7e9e929baa2c175) (Attributed to DeCloud and is licensed under [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/). We use this asset with modification, i.e. rendered image).

<p align="center">
<img src="images/static_assets/shelf.jpg" width="236" />
Expand All @@ -52,7 +52,7 @@ NOTE: Objaverse supports downloads using python [API](https://colab.research.goo

## Create Static Asset Category

Now, we just need to define `Static{CategoryName}Factory = static_category_factory({CategoryName})`. Add the following lines to `infinigen/assets/static_assets/static_category.py` (This step is already done for this tutorial):
Now, we just need to define `Static{CategoryName}Factory = static_category_factory(infinigen/assets/static_assets/source/{CategoryName})`. Add the following lines to `infinigen/assets/static_assets/static_category.py` (This step is already done for this tutorial):

![alt text](images/static_assets/image.jpg)

Expand Down Expand Up @@ -161,7 +161,7 @@ mkdir infinigen/assets/static_assets/source/MyCategory
4. Add a line in `infinigen/assets/static_assets/static_category.py` to define the factory for this category. E.g.

```python
StaticMyCategoryFactory = static_category_factory("MyCategory")
StaticMyCategoryFactory = static_category_factory("infinigen/assets/static_assets/source/MyCategory")
```

5. Add a line in `infinigen/assets/static_assets/__init__.py` to import the factory from other files.
Expand Down Expand Up @@ -195,3 +195,20 @@ Now that you know how to import static assets, you can import all kinds of diffe
<img src="images/static_assets/vending.jpg" width="500" />
</p>

The external assets used here are:

- [St Olaf](https://sketchfab.com/3d-models/st-olaf-the-patron-saint-of-norway-342b6866ba7c46449392acbe27217aa2) (Attributed to Historiska and is licensed under [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/). We use this asset with modification, i.e. rendered image).

- [Dusty Bookshelves](https://sketchfab.com/3d-models/dusty-bookshelfs-caaf76f4506f4b01a2dffb553bae9342) (Attributed to Meanphrog and is licensed under [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/). We use this asset with modification, i.e. rendered image).

- [Minotaur Statue](https://sketchfab.com/3d-models/minotaur-statue-d3f9aaecb7e94b12bc28256c85a40ce0) (Attributed to plasmaernst and is licensed under [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/). We use this asset with modification, i.e. rendered image).

- [Dusty Piano](https://sketchfab.com/3d-models/dusty-piano-fe58e81e5fa940319e79796e23053182) (Attributed to Vincent074 and is licensed under [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/). We use this asset with modification, i.e. rendered image).

- [Divergence Meter (Steins;Gate)](https://sketchfab.com/3d-models/divergence-meter-steinsgate-b43abf482d30435fa0683b765deee31b) (Attributed to Amatsukast and is licensed under [CC BY-NC-SA 4.0](https://creativecommons.org/licenses/by-nc-sa/4.0/). We use this asset with modification, i.e. rendered image).

- [Stone Griffin](https://sketchfab.com/3d-models/stone-griffin-downing-college-cambridge-d94638d6c6ad4119b868567cf8e9fe2b) (Attributed to Thomas Flynn and is licensed under [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/). We use this asset with modification, i.e. rendered image).

- [Hologram Console](https://sketchfab.com/3d-models/hologram-console-bfbbb481e98e4be38774b1d0204c192c) (Attributed to TooManyDemons and is licensed under [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/). We use this asset with modification, i.e. rendered image).

- [vending machine](https://sketchfab.com/3d-models/vending-machine-fb0516c9c6954e5dbeb420aaa48059c0) (Attributed to wilsz95 and is licensed under [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/). We use this asset with modification, i.e. rendered image).
Binary file modified docs/images/static_assets/image.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 0 additions & 10 deletions infinigen/assets/static_assets/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@


class StaticAssetFactory(AssetFactory):
root_asset_dir = os.path.join(os.path.dirname(os.path.abspath(__file__)), "source")

import_map: Dict[str, Callable] = {
"dae": bpy.ops.wm.collada_import,
"abc": bpy.ops.wm.alembic_import,
Expand All @@ -29,16 +27,8 @@ class StaticAssetFactory(AssetFactory):
"blend": bpy.ops.wm.append,
}

@classmethod
def set_root_asset_dir(cls, directory):
cls.root_asset_dir = directory

def __init__(self, factory_seed, coarse=False):
super().__init__(factory_seed, coarse)
if self.root_asset_dir is None:
raise ValueError(
"Root asset directory not set. Call StaticAssetFactory.set_root_asset_dir() first."
)

def import_single_object_from_blend(self, file_path):
with bpy.data.libraries.load(file_path, link=False) as (data_from, data_to):
Expand Down
18 changes: 12 additions & 6 deletions infinigen/assets/static_assets/static_category.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@


def static_category_factory(
category,
path_to_assets: str,
tag_support=False,
x_dim: float = None,
y_dim: float = None,
Expand All @@ -33,9 +33,9 @@ class StaticCategoryFactory(StaticAssetFactory):
def __init__(self, factory_seed, coarse=False):
super().__init__(factory_seed, coarse)
with FixedSeed(factory_seed):
self.category = category
self.path_to_assets = path_to_assets
self.tag_support = tag_support
self.asset_dir = os.path.join(self.root_asset_dir, category)
self.asset_dir = path_to_assets
self.x_dim, self.y_dim, self.z_dim = x_dim, y_dim, z_dim
self.rotation_euler = rotation_euler
asset_files = [
Expand Down Expand Up @@ -86,6 +86,12 @@ def create_asset(self, **params) -> bpy.types.Object:


# Create factory instances for different categories
StaticSofaFactory = static_category_factory("Sofa")
StaticTableFactory = static_category_factory("Table")
StaticShelfFactory = static_category_factory("Shelf", tag_support=True, z_dim=2)
StaticSofaFactory = static_category_factory(
"infinigen/assets/static_assets/source/Sofa"
)
StaticTableFactory = static_category_factory(
"infinigen/assets/static_assets/source/Table"
)
StaticShelfFactory = static_category_factory(
"infinigen/assets/static_assets/source/Shelf", tag_support=True, z_dim=2
)
8 changes: 4 additions & 4 deletions infinigen_examples/constraints/semantics.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ def home_asset_usage():
shelves.SimpleBookcaseFactory,
shelves.CellShelfFactory,
shelves.LargeShelfFactory,
static_assets.StaticShelfFactory,
# static_assets.StaticShelfFactory,
shelves.KitchenCabinetFactory,
shelves.SingleCabinetFactory,
}
Expand All @@ -138,7 +138,7 @@ def home_asset_usage():
tables.TableCocktailFactory,
shelves.SimpleDeskFactory,
tables.CoffeeTableFactory,
static_assets.StaticTableFactory,
# static_assets.StaticTableFactory,
},
)

Expand All @@ -150,7 +150,7 @@ def home_asset_usage():

used_as[Semantics.LoungeSeating] = {
seating.SofaFactory,
static_assets.StaticSofaFactory,
# static_assets.StaticSofaFactory,
seating.ArmChairFactory,
}

Expand Down Expand Up @@ -187,7 +187,7 @@ def home_asset_usage():
bathroom.ToiletFactory,
bathroom.BathtubFactory,
seating.SofaFactory,
static_assets.StaticSofaFactory,
# static_assets.StaticSofaFactory,
shelves.TVStandFactory,
},
)
Expand Down

0 comments on commit 04fe4d3

Please sign in to comment.