Skip to content

Commit

Permalink
Handle captures with missing textures
Browse files Browse the repository at this point in the history
  • Loading branch information
eliemichel committed Oct 24, 2020
1 parent dff7cf8 commit bd6a181
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 20 deletions.
17 changes: 11 additions & 6 deletions blender/MapsModelsImporter/google_maps.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

SCRIPT_PATH = os.path.join(os.path.dirname(os.path.realpath(__file__)), "google_maps_rd.py")
MSG_INCORRECT_RDC = """Invalid RDC capture file. Please make sure that:
1. You are importing from Google Maps (NOT Google Earth)
1. You are importing from Google Maps or Google Earth web
2. You were MOVING in the 3D view while taking the capture (you can use the Capture after delay button in RenderDoc).
Please report to MapsModelsImporter developers providing the .rdc file as well as the full console log.
Console log is accessible in Windows > Toggle System Console (right click to copy)."""
Expand Down Expand Up @@ -166,10 +166,11 @@ def addImageMaterial(name, obj, img):
principled = nodes["Principled BSDF"]
principled.inputs["Specular"].default_value = 0.0
principled.inputs["Roughness"].default_value = 1.0
texture_node = nodes.new(type="ShaderNodeTexImage")
texture_node.image = img
links = mat.node_tree.links
link = links.new(texture_node.outputs[0], principled.inputs[0])
if img is not None:
texture_node = nodes.new(type="ShaderNodeTexImage")
texture_node.image = img
links = mat.node_tree.links
link = links.new(texture_node.outputs[0], principled.inputs[0])

def loadData(prefix, drawcall_id):
with open("{}{:05d}-indices.bin".format(prefix, drawcall_id), 'rb') as file:
Expand All @@ -181,7 +182,11 @@ def loadData(prefix, drawcall_id):
with open("{}{:05d}-uv.bin".format(prefix, drawcall_id), 'rb') as file:
uvs = pickle.load(file)

img = bpy.data.images.load("{}{:05d}-texture.png".format(prefix, drawcall_id))
texture_filename = "{}{:05d}-texture.png".format(prefix, drawcall_id)
if os.path.isfile(texture_filename):
img = bpy.data.images.load(texture_filename)
else:
img = None

with open("{}{:05d}-constants.bin".format(prefix, drawcall_id), 'rb') as file:
constants = pickle.load(file)
Expand Down
33 changes: 19 additions & 14 deletions blender/MapsModelsImporter/google_maps_rd.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,20 +233,25 @@ def run(self):
with open("{}{:05d}-constants.bin".format(FILEPREFIX, drawcallId), 'wb') as file:
pickle.dump(constants, file)

# Texture
# dirty
bindpoints = state.GetBindpointMapping(rd.ShaderStage.Fragment)
texture_bind = bindpoints.samplers[-1].bind
resources = state.GetReadOnlyResources(rd.ShaderStage.Fragment)
rid = resources[texture_bind].resources[0].resourceId

texsave = rd.TextureSave()
texsave.resourceId = rid
texsave.mip = 0
texsave.slice.sliceIndex = 0
texsave.alpha = rd.AlphaMapping.Preserve
texsave.destType = rd.FileType.PNG
controller.SaveTexture(texsave, "{}{:05d}-texture.png".format(FILEPREFIX, drawcallId))
self.extractTexture(drawcallId, state)

def extractTexture(self, drawcallId, state):
"""Save the texture in a png file (A bit dirty)"""
bindpoints = state.GetBindpointMapping(rd.ShaderStage.Fragment)
if not bindpoints.samplers:
print(f"Warning: No texture found for drawcall {drawcallId}")
return
texture_bind = bindpoints.samplers[-1].bind
resources = state.GetReadOnlyResources(rd.ShaderStage.Fragment)
rid = resources[texture_bind].resources[0].resourceId

texsave = rd.TextureSave()
texsave.resourceId = rid
texsave.mip = 0
texsave.slice.sliceIndex = 0
texsave.alpha = rd.AlphaMapping.Preserve
texsave.destType = rd.FileType.PNG
controller.SaveTexture(texsave, "{}{:05d}-texture.png".format(FILEPREFIX, drawcallId))

def main(controller):
scraper = CaptureScraper(controller)
Expand Down

0 comments on commit bd6a181

Please sign in to comment.