I would like to color the top of this shape to rfClr, any ideas? I can change the whole thing Grey, but how to change the top to blue?
l=100
w=60
h=20
hl=8
slope=4
clr='Gray'
rfClr='blue'
ent = Sketchup.active_model.entities
#---------Clear All
Sketchup.active_model.entities.clear!
#----------------
model = Sketchup.active_model
model.start_operation "Create Box"
#-----------------------------------------------------------------------------
entities = model.active_entities
group = entities.add_group
entities = group.entities
group.name="Box"
#pt0 = [0, 0, 0]
#pt1 = [0, 0, h*12+hl]
#pt2 = [w*12/2, 0, 12*h+hl+(w/2)*slope]
#pt3 = [w*12, 0, 12*h+hl]
#pt4 = [w*12, 0, 0]
newface = entities.add_face(#pt0, #pt1, #pt2, #pt3 , #pt4)
newface.material=Sketchup::Color.new clr
#newface.reverse!
newface.pushpull l*12
I found this answer.
I guess it finds the faces that have a z value
vfaces = entities.grep(Sketchup::Face).find_all{|f| f.normal.z.abs != 0 }
vfaces.each{|f| f.material = rfClr }
Related
this is a question about creating a UIGridLayout. I know how to do this using the Studio menus, but I am trying to do it with only code. Here is my code:
local layout = Instance.new("UIGridLayout")
layout.Name = "UIGridLayout"
layout.Parent = script.Parent
layout.FillDirection = Enum.FillDirection.Horizontal
layout.CellPadding = UDim2.new(0, 100, 0, 5)
layout.CellSize = UDim2.new(0, 200, 0, 200)
layout.HorizontalAlignment = Enum.HorizontalAlignment.Center
layout.SortOrder = Enum.SortOrder.LayoutOrder
layout.StartCorner = Enum.StartCorner.TopLeft
layout.VerticalAlignment = Enum.VerticalAlignment.Bottom
local teamFrame = Instance.new("Frame")
teamFrame.BackgroundTransparency = 0
teamFrame.LayoutOrder = 0
teamFrame.Parent = script.Parent
local lblTeamTag = Instance.new("TextLabel", teamFrame)
lblTeamTag.TextTransparency = 0
lblTeamTag.TextStrokeTransparency = 0
lblTeamTag.Name = "TeamTag"
lblTeamTag.Text = "Team"
lblTeamTag.Size = UDim2.new(0, 200, 0, 50)
lblTeamTag.Position = UDim2.new(0, 0, 0, 0)
local lblPoints = Instance.new("TextLabel", teamFrame)
lblPoints.TextStrokeTransparency = 0
lblPoints.BackgroundTransparency = 0
lblPoints.Name = "Points"
lblPoints.Text = "0"
lblPoints.Size = UDim2.new(0, 200, 0, 150)
lblPoints.Position = UDim2.new(0, 0, 0, 50)
The script where this code sits is a local script child of ScreenGui. I am expecting to see something like this:
But I got nothing. I know I am close. What am I missing. Many thanks
If what you're getting is just the TextLabels not being in the right places, it's because the UIGridLayout has to be inside the frame instead of being inside the same parent of the frame. So if you instance the UIGridLayout after instancing the frame and then making the frame the parent of the UIGridLayout it should work. Here's how it should be done so you can just copy and paste:
local teamFrame = Instance.new("Frame")
teamFrame.BackgroundTransparency = 0
teamFrame.LayoutOrder = 0
teamFrame.Parent = script.Parent
local layout = Instance.new("UIGridLayout")
layout.Name = "UIGridLayout"
layout.Parent = script.Parent
layout.FillDirection = Enum.FillDirection.Horizontal
layout.CellPadding = UDim2.new(0, 100, 0, 5)
layout.CellSize = UDim2.new(0, 200, 0, 200)
layout.HorizontalAlignment = Enum.HorizontalAlignment.Center
layout.SortOrder = Enum.SortOrder.LayoutOrder
layout.StartCorner = Enum.StartCorner.TopLeft
layout.VerticalAlignment = Enum.VerticalAlignment.Bottom
local lblTeamTag = Instance.new("TextLabel", teamFrame)
lblTeamTag.TextTransparency = 0
lblTeamTag.TextStrokeTransparency = 0
lblTeamTag.Name = "TeamTag"
lblTeamTag.Text = "Team"
lblTeamTag.Size = UDim2.new(0, 200, 0, 50)
lblTeamTag.Position = UDim2.new(0, 0, 0, 0)
local lblPoints = Instance.new("TextLabel", teamFrame)
lblPoints.TextStrokeTransparency = 0
lblPoints.BackgroundTransparency = 0
lblPoints.Name = "Points"
lblPoints.Text = "0"
lblPoints.Size = UDim2.new(0, 200, 0, 150)
lblPoints.Position = UDim2.new(0, 0, 0, 50)
I'm trying to build my own camera class in WebGL for learning purposes. It's almost complete but I have 1 slight issue with the lookAt function. If I translate my object in the -z direction then it will work fine but once I move it in the +z direction it acts as if it's doing the opposite and the object will begin to stretch across the screen if I move the camera up or down.
This is what I currently have:
var zAxis = new Vector(cameraPosition.x, cameraPosition.y, cameraPosition.z)
.subtract(target)
.normalize();
var xCross = math.cross(up.flatten(3), zAxis.flatten(3));
var xAxis = new Vector(xCross[0], xCross[1], xCross[2]).normalize();
var yCross = math.cross(zAxis.flatten(3), xAxis.flatten(3));
var yAxis = new Vector(yCross[0], yCross[1], yCross[2]).normalize();
var orientation = [
xAxis.x, xAxis.y, xAxis.z, 0,
yAxis.x, yAxis.y, yAxis.z, 0,
zAxis.x, zAxis.y, zAxis.z, 0,
0, 0, 0, 1
];
var translation = [
1, 0, 0, 0,
0, 1, 0, 0,
0, 0, 1, 0,
cameraPosition.x, cameraPosition.y, cameraPosition.z, 1
];
this.multiply(translation);
this.multiply(orientation);
Does anyone know what I've done wrong?
I'm trying to change the brightness of an image in Flash. I have converted the flash to a bitmap, and would like to make a button that increases or decreases the brightness of the image as a whole. Is there a way to access every pixel in the image at once to do this (using code, not the Panels on Stage)?
Using the ColorMatrixFilter class, you can adjust the brightness by applying the same multiplier to each color channel.
So something like this (from this source):
image.filters = [makeBrightFilter(50)];
function makeBrightFilter(amount):ColorMatrixFilter {
amount = amount * (255/250);
var m:Array = new Array();
m = m.concat([1, 0, 0, 0, amount]); // red
m = m.concat([0, 1, 0, 0, amount]); // green
m = m.concat([0, 0, 1, 0, amount]); // blue
m = m.concat([0, 0, 0, 1, 0]); // alpha
return new ColorMatrixFilter(m);
}
To abstract it out and make it even easier, you could use a library like Grant Skinner's ColorMatrix class.
Then you do something like this:
import com.gskinner.geom.ColorMatrix;
import flash.filters.ColorMatrixFilter;
var matrix:ColorMatrix = new ColorMatrix();
matrix.adjustBrightness(50);
image.filters = [new ColorMatrixFilter(matrix)];
I am using XGetImage to read the pixels of an OpenGL window. The XImage that is returned shows a depth of 24-bits, but my OpenGL context has alpha values that I would like to be returned. Is there any way to get a 32-bit XImage from XGetImage, or does X already flatten the image to 24-bits?
Function call:
::XImage *winImage = XGetImage(dpy_i->dpy, wnd_i->wnd,
x, y, width, height, 0xffffffff, ZPixmap);
GDB output:
(gdb) print *winImage
$2 = {width = 640, height = 512, xoffset = 0, format = 2,
data = 0x7fffe72fd010 "\377\377\377", byte_order = 0,
bitmap_unit = 32, bitmap_bit_order = 0, bitmap_pad = 32,
depth = 24, bytes_per_line = 2560, bits_per_pixel = 32,
red_mask = 16711680, green_mask = 65280, blue_mask = 255,
obdata = 0x0, f = {create_image = 0x7ffff4b67810 <XCreateImage>,
destroy_image = 0x7ffff4b665b0, get_pixel = 0x7ffff4b67520,
put_pixel = 0x7ffff4b67450, sub_image = 0x7ffff4b67170,
add_pixel = 0x7ffff4b66650}}
I seem to always get a 32bit image. This is my code, js-ctypes, i take a screenshot of all monitors.
https://github.com/Noitidart/_scratchpad/blob/c41012b16842f0769595033bd51a3801451319be/x11%20new%20way%20skel%20non%20jsm.js
This is my XImage struct after XGetImage:
"width:" "1280" "height:" "919" "xoffset:" "0" "format:" "2" "data:" "ctypes.char.ptr(ctypes.UInt64("0x7f850fe00000"))" "byte_order:" "0" "bitmap_unit:" "32" "bitmap_bit_order:" "0" "bitmap_pad:" "32" "depth:" "24" "bytes_per_line:" "5120" "bits_per_pixel:" "32" "red_mask:" "16711680" "green_mask:" "65280" "blue_mask:" "255" "_END_"
I have created some box geometries in my threejs app and I have successfully drawn a cylinder from the center of one to the center of another using the code below:
function cylinderMesh(pointX, pointY, material) {
var direction = new THREE.Vector3().subVectors(pointY, pointX);
var orientation = new THREE.Matrix4();
orientation.lookAt(pointX, pointY, new THREE.Object3D().up);
orientation.multiply(new THREE.Matrix4(1, 0, 0, 0,
0, 0, 1, 0,
0, -1, 0, 0,
0, 0, 0, 1));
var edgeGeometry = new THREE.CylinderGeometry(2, 2, direction.length(), 8, 1);
var edge = new THREE.Mesh(edgeGeometry, material);
edge.applyMatrix(orientation);
edge.position.x = (pointY.x + pointX.x) / 2;
edge.position.y = (pointY.y + pointX.y) / 2;
edge.position.z = (pointY.z + pointX.z) / 2;
return edge;
}
scene.add(cylinderMesh(vertex1, vertex2, globalMaterial));
My question is: How to I keep the cylinder "connected" to the two vertices I provide if they move?
I don't want to use a THREE.Line because I can't control the width of the line and I have noticed weird issues with clipping if the camera gets too close.
Any ideas?