diff --git a/src/loaders/blend.nim b/src/loaders/blend.nim index 5a52298..929d4ec 100644 --- a/src/loaders/blend.nim +++ b/src/loaders/blend.nim @@ -94,6 +94,7 @@ method close*(self: BlendLoader) = self.resource = nil self.blend_file = nil self.cached_materials.clear() + self.textures.clear() method openAssetFile*(self: BlendLoader, path: string) = if self.resource != nil: @@ -204,17 +205,21 @@ method loadTextureImpl*(self: BlendLoader, name: string, img: FNode): Texture = return self.engine.newTexture(name,1,1,1,RGBA_f16,pixels=c16.to float32) # of 5: # UDIM sequence else: - assert false, "Image source not supported yet: " & $source + assert false, &"Image source not supported yet: {source}, image '{name}'" method loadTexture*(self: BlendLoader, name: string): Texture = # sources: # 1 image # 4 generated # 5 render + if name in self.textures: + return self.textures[name] for img in self.blend_file.named_blocks["IM"]: let nm = img.id.name.str.strip2 if name == nm: - return self.loadTextureImpl(name, img) + let tex = self.loadTextureImpl(name, img) + self.textures[name] = tex + return tex raise newException(KeyError, "Can't find image " & name) proc makeMaterialAndTextures(self: BlendLoader; diff --git a/src/loaders/blend_mesh.nim b/src/loaders/blend_mesh.nim index a8f4bf6..9ac853f 100644 --- a/src/loaders/blend_mesh.nim +++ b/src/loaders/blend_mesh.nim @@ -77,6 +77,8 @@ proc pack_normal(v: Vec3): float32 = (z) let f = cast[float32](i) return f - (if f >= 0.0: 1.0 else: -1.0) + + proc equals[T](a: ArrRef[T], s:seq[T], offset: int): bool = for i, v in a: if a[i] != s[offset+i]: return false diff --git a/src/types.nim b/src/types.nim index 5db859a..85bd97d 100644 --- a/src/types.nim +++ b/src/types.nim @@ -914,6 +914,7 @@ type BlendLoader* = ref object of Loader cached_materials*: Table[(FNode, string, bool), (string, seq[Varying], OrderedTable[string, string], OrderedTable[string, TexturePixels])] ## private resource*: LoadableResource + textures*: Table[string, Texture] template enqueue*(renderer: RenderManager, fun: untyped) = ## Run a proc after the renderer has been initialized.