Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified res/Sketchfab_Logo_exporter.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified res/Sketchfab_Logo_importer.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified res/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified res/modelPlaceholder.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion sketchfab/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -536,4 +536,4 @@ def get_square_crop_resolution(im):
self.skfb_api.search_results['current'][uid].preview_path = preview_path
self.skfb_api.search_results['current'][uid].thumbnail_path = thumbnail_path
if self.skfb_api.request_callback:
self.skfb_api.request_callback()
self.skfb_api.request_callback()
2 changes: 0 additions & 2 deletions sketchfab/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,5 +107,3 @@ def get_temp_path():
('LIKES', "Likes", ""),
('VIEWS', "Views", ""),
('RECENT', "Recent", ""))


44 changes: 22 additions & 22 deletions sketchfab/import_gltf.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def run(self, filepath, uid=None):
gui.MessageDialog(text=msg, type=c4d.GEMB_OK)
self.is_done = True
self.progress_callback('Done', 1, 1)
return
return

# Import
self.import_gltf_textures(gltf)
Expand Down Expand Up @@ -165,7 +165,7 @@ def switch_handedness_v3(self, v3):
return v3

def quat_to_eulerxyz(self, quat):

x, y, z, w = quat

X = math.atan2(2*(w*x+y*z), 1-2*(x*x+y*y))
Expand Down Expand Up @@ -221,7 +221,7 @@ def create_c4d_nodes(self, gltf, skins, materials):

gltf_node = gltf.data.nodes[i]
c4d_object, name = None, None

if i not in joints:
if gltf_node.mesh is not None:
c4d_object = self.convert_mesh(gltf, gltf_node.mesh, materials)
Expand All @@ -237,7 +237,7 @@ def create_c4d_nodes(self, gltf, skins, materials):
nodes[i] = c4d_object
c4d_object.SetName(name)

# Transforms
# Transforms
c4d_object.SetRotationOrder(5) # Local XYZ
c4d_object.SetQuaternionRotationMode(1, 0)
ignoreTransforms = gltf_node.mesh is not None and gltf_node.skin is not None
Expand Down Expand Up @@ -291,7 +291,7 @@ def apply_transforms(self, obj, gltf_node):
if gltf_node.translation:
tr = gltf_node.translation
obj.SetRelPos(c4d.Vector(tr[0], tr[1], -tr[2]))

def convert_primitive(self, prim, gltf, materials):
# Helper functions
def float2bytes(f):
Expand Down Expand Up @@ -437,7 +437,7 @@ def parse_tangents():
parse_texcoords(texcoord_index, c4d_mesh)

if prim.material is not None:

mat = materials[prim.material]

# Only parse COLORS_0
Expand Down Expand Up @@ -478,7 +478,7 @@ def create_c4d_hierarchy(self, gltf, nodes, skins):
# Add GlTF root objects to document
for node in gltf.data.scenes[0].nodes:
c4d.documents.GetActiveDocument().InsertObject(nodes[node])

# Do the parenting
for n in nodes:
if nodes[n] is not None:
Expand Down Expand Up @@ -520,7 +520,7 @@ def create_c4d_weights(self, gltf, nodes, skins):
for i in skins:

skin = skins[i]

for iNode, iMesh in zip(skin.node_idx, skin.mesh_idx):

c4d_obj = nodes[iNode]
Expand All @@ -535,12 +535,12 @@ def create_c4d_weights(self, gltf, nodes, skins):

# Create the C4D tag
tag = CAWeightTag()
c4d_obj.InsertTag(tag)
c4d_obj.InsertTag(tag)

# Accessor data
weights = BinaryData.get_data_from_accessor(gltf, prim.attributes["WEIGHTS_0"]) if "WEIGHTS_0" in prim.attributes else []
joints = BinaryData.get_data_from_accessor(gltf, prim.attributes["JOINTS_0"]) if "JOINTS_0" in prim.attributes else []

# Unique list of joints used for the skinning
local_joints = list(set([j for sub in joints for j in sub]))

Expand All @@ -554,7 +554,7 @@ def create_c4d_weights(self, gltf, nodes, skins):
ind = skin.joints[idx]
joint = nodes[ind]
gltf_to_c4d[ind] = tag.AddJoint(joint)

c4d_ibms.append(ibm)
c4d_joints.append(joint)

Expand All @@ -564,8 +564,8 @@ def create_c4d_weights(self, gltf, nodes, skins):
weight = weights[vert_idx][influence_idx]
if weight > 0:
tag.SetWeight(
gltf_to_c4d[ skin.joints[joints[vert_idx][influence_idx] ]],
vert_idx,
gltf_to_c4d[ skin.joints[joints[vert_idx][influence_idx] ]],
vert_idx,
weight
)

Expand All @@ -574,7 +574,7 @@ def create_c4d_weights(self, gltf, nodes, skins):

if joint.GetName() not in initial_transforms:
initial_transforms[joint.GetName()] = joint.GetMl()

# Read the IBM
if M is not None:
c4d_mat = self.gltf_matrix_to_c4d(M)
Expand All @@ -584,7 +584,7 @@ def create_c4d_weights(self, gltf, nodes, skins):
doc = c4d.documents.GetActiveDocument()
doc.SetActiveTag(tag, mode=c4d.SELECTION_NEW)
c4d.CallButton(tag, c4d.ID_CA_WEIGHT_TAG_SET)

# Restore the inital position
for jt in skin.joints:
joint = nodes[jt]
Expand Down Expand Up @@ -670,12 +670,12 @@ def import_animations(self, gltf, nodes):
ranges[i]["start"] += animationStart
ranges[i]["end"] += animationStart
animationStart += margin + ranges[i]["end"] - ranges[i]["start"]

# Remember the static positions of the nodes concerned by the keyframed channels
for ID in CHANNELS:
node_idx = CHANNELS[ID]["node"]
path = CHANNELS[ID]["path"]

c4d_object = nodes[node_idx]
CHANNELS[ID]["rest_data"] = None
if path == "translation":
Expand All @@ -692,7 +692,7 @@ def import_animations(self, gltf, nodes):
if not len(c["time"][i]): # Empty channel -> we fix it to the rest position
pass
c["time"][i] = [ranges[i]["start"] + eps, ranges[i]["end"] - eps]
c["data"][i] = [c["rest_data"], c["rest_data"]]
c["data"][i] = [c["rest_data"], c["rest_data"]]
c["fixed"][i] = 1

else:
Expand Down Expand Up @@ -741,7 +741,7 @@ def import_animations(self, gltf, nodes):
for axis in [c4d.VECTOR_X, c4d.VECTOR_Y, c4d.VECTOR_Z]:

descid = c4d.DescID(
c4d.DescLevel(trackType, c4d.DTYPE_VECTOR,0),
c4d.DescLevel(trackType, c4d.DTYPE_VECTOR,0),
c4d.DescLevel(axis, c4d.DTYPE_REAL,0)
)
descid = [trackType, axis]
Expand All @@ -759,7 +759,7 @@ def import_animations(self, gltf, nodes):

# Create the keyframes
for i,o in zip(in_data, out_data):

data = None
if channel["fixed"][ani]:
# Animation data for "fixed" keyframes
Expand All @@ -786,7 +786,7 @@ def import_animations(self, gltf, nodes):
curves[j].InsertKey(key)
key.SetInterpolation(curves[j], c4d.CINTERPOLATION_LINEAR)
key.SetQuatInterpolation(curves[j], c4d.ROTATIONINTERPOLATION_QUATERNION_SLERP)


# Update
c4d_object.Message(c4d.MSG_UPDATE)
Expand Down Expand Up @@ -841,7 +841,7 @@ def make_vertex_colors_layer(self, mat, colortag):
mat.SetParameter(c4d.MATERIAL_COLOR_SHADER, vtxcolorshader, c4d.DESCFLAGS_SET_NONE)

# check if vertex color already enabled:
if not colortag or mat.GetReflectionLayerIndex(0).GetName() == 'Vertex Colors':
if not colortag or (mat.GetReflectionLayerIndex(0) and (mat.GetReflectionLayerIndex(0).GetName() == 'Vertex Colors')):
return

vtx_color_diffuse = mat.AddReflectionLayer()
Expand Down
Loading