def CreateText(pos, message): tex = MaxPlus.Factory.CreateShapeObject(MaxPlus.ClassIds.text) tex.ParameterBlock.size.Value = 20.0 tex.ParameterBlock.text.Value = message node = MaxPlus.Factory.CreateNode(tex) node.Position = MaxPlus.Point3(pos.X, pos.Y - 5, pos.Z) node.WireColor = MaxPlus.Color(1.0, 0.5, 1.0)
def solidMaterial(color): m = MaxPlus.Factory.CreateDefaultStdMat() m.Ambient = color m.Diffuse = color m.Specular = MaxPlus.Color(1, 1, 1) m.Shininess = 0.5 m.ShinyStrength = 0.7 return m
def glmVRayGolaemPostCreationCallback(proxyName): # get node node = MaxPlus.INode.GetINodeByName(proxyName) defaultMatName = node.BaseObject.ParameterBlock.default_material.GetValue() if not defaultMatName: defaultMatName = "crowdProxyDefaultShader" # create VRayMtl (used as default) mat = MaxPlus.Factory.CreateMaterial( MaxPlus.Class_ID(0x37bf3f2f, 0x7034695c)) mat.Diffuse = MaxPlus.Color(1, 0.47, 0) mat.SetName(MaxPlus.WStr(defaultMatName + "@")) # create multi material mmat = MaxPlus.Factory.CreateDefaultMultiMtl() mmat.SetName(MaxPlus.WStr(proxyName + "Mtl")) mmat.SetSubMtl(0, mat) # apply multi material to node node.Material = mmat print("VRayGolaem: " + proxyName + "Mtl MultiMaterial has been successfully assigned to " + proxyName)
def solidMaterial(color): m = MaxPlus.Factory.CreateDefaultStdMat() m.Ambient = color m.Diffuse = color m.Specular = MaxPlus.Color(1, 1, 1) m.Shininess = 0.5 m.ShinyStrength = 0.7 return m def descendants(node): for c in node.Children: yield c for d in descendants(c): yield d def allNodes(): return descendants(MaxPlus.Core.GetRootNode()) def applyMaterialToNodes(m, nodes=allNodes()): for n in nodes: n.Material = m if __name__ == '__main__': createSphere() m = solidMaterial(MaxPlus.Color(0, 0, 1)) applyMaterialToNodes(m)
def reinstance_current_layer(): pre_name = preNameTextBox.toPlainText() _layer = MaxPlus.LayerManager_GetCurrentLayer() _n = _layer.GetName() if _n == "0" or _n == "_Problems_" or _n == "_Boundaries_" or _n == "_Inner_Layers_" or _n == "_Middle_Layers_" or _n == "_Outer_Layers_": logger.log("The following layers not allowed: 0(default), _Inner_Layers_, _Middle_Layers_, _Outer_Layers_, _Problems_ and _Boundaries_ . Move your nodes to new layer.") refModelTextBox.setText("") return y = _n.startswith('Layer') if not y: logger.log("Layer name \"" + _n + "\" must have start with \"Layer\"") refModelTextBox.setText("") return #get layer index as str _layer_index_str = str(_n .replace('Layer', '')) #check is it valid ? _layer_index = 0 try: _layer_index = int(_layer_index_str) except: _layer_index = -maxint - 1 if _layer_index == (-maxint - 1): logger.log("Layer \"" + _n + "\" must have in following format: Layer + Number; for example Layer001, Layer1, Layer1000") refModelTextBox.setText("") return _layer_index_str = get_standard_index_name(_layer_index) #find ref node No_Ref_Founded = 0 _ref_index = -1 _lod_index = -1 nodes = _layer.GetNodes() instances_index = [] _len_nodes = len(nodes) if _len_nodes == 0: logger.log("Layer \"" + _n + "\" does not have any node") refModelTextBox.setText("") return _preferred_ref_name = refModelTextBox.toPlainText() #check for ref ch_indexer = 1 lod_indexer = 1 for j in range(0, _len_nodes): _node = nodes[j] _rotate = _node.GetWorldRotation() _rx, _ry, _rz = quaternion_to_euler_angle(_rotate.GetW(), _rotate.GetX(), _rotate.GetY(), _rotate.GetZ()) _node_name = _node.Name if _node_name.find("-ch") != -1 or _node_name.find("_ch") != -1 or _node_name.find("-CH") != -1 or _node_name.find("-Ch") != -1 or _node_name.find("-cH") != -1 or _node_name.find("_CH") != -1 or _node_name.find("_Ch") != -1 or _node_name.find("_cH") != -1: nodes[j].Name = pre_name + _layer_index_str + "-ch" + str(ch_indexer) ch_indexer = ch_indexer + 1 apply_editpoly_reset_xform_selected_model(nodes[j].Name) continue if _node_name.find("-lod") != -1 or _node_name.find("_lod") != -1 or _node_name.find("-Lod") != -1 or _node_name.find("_Lod") != -1 or _node_name.find("-LOD") != -1 or _node_name.find("_LOD") != -1: nodes[j].Name = pre_name + _layer_index_str + "-lod" + str(lod_indexer) lod_indexer = lod_indexer + 1 apply_editpoly_reset_xform_selected_model(nodes[j].Name) _lod_index = j continue if _node_name.find("-ins") != -1: _lod_index = j continue if _preferred_ref_name == "": if in_range_of(_rx, -0.1, 0.1) and in_range_of(_ry, -0.1, 0.1) and in_range_of(_rz, -0.1, 0.1): _ref_index = j break else: if _preferred_ref_name == _node_name and in_range_of(_rx, -0.1, 0.1) and in_range_of(_ry, -0.1, 0.1) and in_range_of(_rz, -0.1, 0.1): _ref_index = j break if _ref_index == -1: logger.log("Layer \"" + _n + "\" does not have ref object, At least one node should contain zero rotation or may be the preferred Ref node is not child of current active layer") refModelTextBox.setText("") return _ref = nodes[_ref_index] logger.log("using " + _ref.Name + " as ref node") for j in range(0, _len_nodes): _node = nodes[j] _rotate = _node.GetWorldRotation() _rx, _ry, _rz = quaternion_to_euler_angle(_rotate.GetW(), _rotate.GetX(), _rotate.GetY(), _rotate.GetZ()) _node_name = _node.Name #convex hull if _node_name.find("-ch") != -1: continue #lod if _node_name.find("-lod") != -1: _lod_index = j continue #ref if j == _ref_index: continue _node.Name = "(OLD-INS)" + _node.Name instances_index.append(j) #get ref node Equipment Name _equipment_name = "" _splits = _ref.Name.split("_", 1) if len(_splits) > 1: _equipment_name = _splits[1] _ref.Name = pre_name + _layer_index_str + "_" + _equipment_name #move lod to ref location _checked = align_lod_ref_check.checkState() if _lod_index != -1 and _checked == Qt.Checked: _lod = nodes[_lod_index] _ref_pos = _ref.Position _lod.SetPositionX(_ref_pos.GetX()) _lod.SetPositionY(_ref_pos.GetY()) _lod.SetPositionZ(_ref_pos.GetZ()) #apply convert to editpoly, reset xform apply_editpoly_reset_xform_selected_model(_ref.Name) default_mat = MaxPlus.Factory.CreateDefaultStdMat() default_mat.Ambient = MaxPlus.Color(0.0, 1.0, 0.0) default_mat.Diffuse = MaxPlus.Color(0.0, 1.0, 0.0) default_mat.Specular = MaxPlus.Color(1.0, 1.0, 1.0) default_mat.Shininess = 0.5 default_mat.ShinyStrength = 0.7 num_instances = len(instances_index) for k in xrange(0, num_instances): old_ins = nodes[instances_index[k]] pos = old_ins.Position rot = old_ins.GetWorldRotation() _equipment_name = "" #get ref node Equipment Name _splits = old_ins.Name.split("_", 1) if len(_splits) > 1: _equipment_name = _splits[1] #create instance instance = _ref.CreateTreeInstance() instance.Name = pre_name + _layer_index_str + "-ins" + get_standard_index_name(k + 1) + "_" + _equipment_name instance.SetPositionX(pos.GetX()) instance.SetPositionY(pos.GetY()) instance.SetPositionZ(pos.GetZ()) instance.SetWorldRotation(rot) #change color of old instance old_ins.Material = default_mat #old_ins.WireColor = MaxPlus.Color(1.0, 0.0, 0.0) #store to old instances ##################################################old_instances[0].append(old_ins) refModelTextBox.setText("")