def set_noise(self, body_id, link_id, rgb1, rgb2, fraction=0.9): """ Apply noise to the texture. Args: body_id (int): body index. link_id (int): link index in the body. rgb1 (list or np.ndarray): background rgb color (shape: :math:`[3,]`). rgb2 (list or np.ndarray): color of random noise foreground color (shape: :math:`[3,]`). fraction (float): fraction of pixels with foreground color. """ if not self._check_link_has_tex(body_id, link_id): return rgb1 = np.array(rgb1).flatten() rgb2 = np.array(rgb2).flatten() tex_id, height, width = self.texture_dict[body_id][link_id] fraction = clamp(fraction, 0.0, 1.0) mask = np.random.uniform(size=(height, width)) < fraction new_color = np.tile(rgb1, (height, width, 1)) new_color[mask, :] = rgb2 p.changeTexture(tex_id, new_color.flatten(), width, height, physicsClientId=self._pb_id)
def set_texture(texture, image): # Alias/WaveFront Material (.mtl) File Format # https://people.cs.clemson.edu/~dhouse/courses/405/docs/brief-mtl-file-format.html #print(get_visual_data(body)) width, height, channels = image.shape pixels = image.flatten().tolist() assert len(pixels) <= 524288 # b3Printf: uploadBulletFileToSharedMemory 747003 exceeds max size 524288 p.changeTexture(texture, pixels, width, height, physicsClientId=CLIENT)
def load(self, parent): self.parent = parent num_planes = p.getNumJoints(parent) self.joints = [-1] + list(range(num_planes)) self.textures = [] for j in self.joints: p.changeVisualShape(parent, j, rgbaColor=[1, 1, 1, 1]) t = p.loadTexture(DATA_DIR + "tex256.png") self.textures.append(t) p.changeTexture(t, self.random_pixels(), self.w, self.h) p.changeVisualShape(parent, j, textureUniqueId=t)
def set_gradient(self, body_id, link_id, rgb1, rgb2, vertical=True): """ Creates a linear gradient from rgb1 to rgb2. Args: body_id (int): body index. link_id (int): link index in the body. rgb1 (list or np.ndarray): first rgb color (shape: :math:`[3,]`). rgb2 (list or np.ndarray): second rgb color (shape: :math:`[3,]`). vertical (bool): if True, the gradient in the vertical direction, if False it's in the horizontal direction. """ rgb1 = np.array(rgb1).reshape(1, 3) rgb2 = np.array(rgb2).reshape(1, 3) if not self._check_link_has_tex(body_id, link_id): return tex_id, height, width = self.texture_dict[body_id][link_id] if vertical: intp = np.linspace(0, 1, height) comp_intp = 1.0 - intp rgb_intp = np.multiply(rgb1, intp[:, None]) rgb_intp += np.multiply(rgb2, comp_intp[:, None]) new_color = np.repeat(rgb_intp, width, axis=0).flatten() else: intp = np.linspace(0, 1, width) comp_intp = 1.0 - intp rgb_intp = np.multiply(rgb1, intp[:, None]) rgb_intp += np.multiply(rgb2, comp_intp[:, None]) new_color = np.repeat(rgb_intp[None, :, :], height, axis=0).flatten() new_color = new_color.astype(np.uint8) p.changeTexture(tex_id, new_color, width, height, physicsClientId=self._pb_id)
def randomize(self): for t in self.textures: p.changeTexture(t, self.random_pixels(), self.w, self.h)
# Width for i in range(width): # Height for j in range(height): # Change color image[(i + j * width) * 3 + 0] = i image[(i + j * width) * 3 + 1] = (j + blue) % 256 image[(i + j * width) * 3 + 2] = blue # end for # end for # Increase blue component blue = blue + 1 # Change texture p.changeTexture(text_uid, image, width, height) # Start measuring time start = time.time() # Get image from camera p.getCameraImage(300, 300, renderer=p.ER_BULLET_HARDWARE_OPENGL) end = time.time() # Print time for rendering print("rendering duration") print(end - start) # end for # Stop state logging
width = 256 height = 256 pixels = [255] * width * height * 3 colorR = 0 colorG = 0 colorB = 0 #p.configureDebugVisualizer(p.COV_ENABLE_RENDERING,0) #p.configureDebugVisualizer(p.COV_ENABLE_GUI,0) blue = 0 logId = p.startStateLogging(p.STATE_LOGGING_PROFILE_TIMINGS, "renderbench.json") for i in range(100000): p.stepSimulation() for i in range(width): for j in range(height): pixels[(i + j * width) * 3 + 0] = i pixels[(i + j * width) * 3 + 1] = (j + blue) % 256 pixels[(i + j * width) * 3 + 2] = blue blue = blue + 1 p.changeTexture(texUid, pixels, width, height) start = time.time() p.getCameraImage(300, 300, renderer=p.ER_BULLET_HARDWARE_OPENGL) end = time.time() print("rendering duration") print(end - start) p.stopStateLogging(logId) #p.configureDebugVisualizer(p.COV_ENABLE_RENDERING,1) #p.configureDebugVisualizer(p.COV_ENABLE_GUI,1)
width = 256 height = 256 pixels = [255] * width * height * 3 colorR = 0 colorG = 0 colorB = 0 #p.configureDebugVisualizer(p.COV_ENABLE_RENDERING,0) #p.configureDebugVisualizer(p.COV_ENABLE_GUI,0) blue = 0 logId = p.startStateLogging(p.STATE_LOGGING_PROFILE_TIMINGS, "renderbench.json") for i in range(100000): p.stepSimulation() for i in range(width): for j in range(height): pixels[(i + j * width) * 3 + 0] = i pixels[(i + j * width) * 3 + 1] = (j + blue) % 256 pixels[(i + j * width) * 3 + 2] = blue blue = blue + 1 p.changeTexture(texUid, pixels, width, height) start = time.time() p.getCameraImage(300, 300, renderer=p.ER_BULLET_HARDWARE_OPENGL) end = time.time() print("rendering duraction") print(end - start) p.stopStateLogging(logId) #p.configureDebugVisualizer(p.COV_ENABLE_RENDERING,1) #p.configureDebugVisualizer(p.COV_ENABLE_GUI,1)