Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
wedgeMeshVertData.applyToMesh(wedgeMesh);
wedgeMesh.isVisible = false; // but newly created copies and instances will be visible by default
wedgeMesh.doNotSyncBoundingInfo = true;
meshTemplates.wedge = wedgeMesh;
// empty mesh for making drawings invisible
var emptyMesh = new BABYLON.Mesh('emptyMesh', scene);
meshTemplates.empty = emptyMesh;
// add transform node for playerPosNode that's going to copy avatar's position so that the
// camera can follow them without crashing when the avatar is rendered as billboard
playerPosNode = new BABYLON.TransformNode('playerPosNode');
// material
baseMat = new BABYLON.StandardMaterial('base material', scene);
baseMat.ambientColor = new BABYLON.Color3(1, 1, 1);
baseMat.maxSimultaneousLights = 0;
baseMat.freeze();
hackOptions.init(scene);
textCanvas = document.createElement('canvas');
textCanvas.id = 'textCanvas';
textCanvas.width = bitsy.canvas.width;
textCanvas.height = bitsy.canvas.height;
gameContainer.appendChild(textCanvas);
textContext = textCanvas.getContext('2d');
bitsy.dialogRenderer.AttachContext(textContext);
// Watch for browser/canvas resize events
engine.setSize(hackOptions.size.width, hackOptions.size.height);
addTexture(image) {
// Get base 64 string
const dummyCanvas = document.createElement('canvas');
dummyCanvas.width = image.width;
dummyCanvas.height = image.height;
const ctx = dummyCanvas.getContext('2d');
ctx.drawImage(image, 0, 0);
const base64String = dummyCanvas.toDataURL();
const materialSphere1 = new StandardMaterial('texture1', this._scene);
materialSphere1.diffuseTexture = Texture.CreateFromBase64String(
base64String,
'texture name',
this._scene
);
this._sphere.material = materialSphere1;
}
if (screenPlane) {
screenPlane.scaling = new BABYLON.Vector3(-15, -15, -15)
screenPlane.translate(new BABYLON.Vector3(1, 0, 0), 0.256) // X
screenPlane.translate(new BABYLON.Vector3(0, 1, 0), 0.819) // Y
screenPlane.translate(new BABYLON.Vector3(0, 0, 1), 0.35) // Z
linesTexture = GUI.AdvancedDynamicTexture.CreateForMesh(
screenPlane,
planeWidth,
planeHeight
);
linesTexture.addControl(textBlock);
// create material
screenMat = new BABYLON.StandardMaterial("mat", scene);
screenMat.emissiveTexture = linesTexture;
// screenMat.useEmissiveAsIllumination = true
screenMat.emissiveColor = new BABYLON.Color3(0, 0.15, 0.1);
screenMat.diffuseColor = new BABYLON.Color3(0, 0, 0);
// apply material
screenPlane.material = screenMat;
applyLinesToScreen()
// Emissive textures should glow
const glow = new BABYLON.GlowLayer('glow', scene, {
mainTextureSamples: 4
})
}
create(scene: Scene): Mesh {
const skybox = Mesh.CreateBox("skyBox", 100.0, scene)
this.skybox = skybox
const skyboxMaterial = new StandardMaterial("skyBox", scene)
// assign to local var to recreate cube-textures
this.skyboxMaterial = skyboxMaterial
skyboxMaterial.backFaceCulling = false
skyboxMaterial.disableLighting = true
skybox.material = skyboxMaterial
// Next, we set the infiniteDistance property. This makes the skybox follow our camera's position.
skybox.infiniteDistance = this.props.infiniteDistance ? this.props.infiniteDistance : true
// Now we must remove all light reflections on our box (the sun doesn't reflect on the sky!):
skyboxMaterial.disableLighting = true
// Next, we apply our special sky texture to it. This texture must have been prepared to be a skybox, in a dedicated directory, named “skybox” in our example:
this.lastTexture = this.props.texture
skyboxMaterial.reflectionTexture = new CubeTexture(this.props.texture, scene)
module.exports.prototype.getMesh = function(item, scene) {
//var cap = babylon.MeshBuilder.CreateDisc(item.id, {diameter: item.diameter - item.thickness, tessellation: item.sides,height:thickness, sideOrientation: babylon.Mesh.DOUBLESIDE}, scene);
var cylinder = babylon.MeshBuilder.CreateCylinder(
item.id,
{
diameterTop: item.diameter - item.thickness,
diameterBottom: item.diameter,
tessellation: item.sides,
height: item.thickness,
sideOrientation: babylon.Mesh.DOUBLESIDE
},
scene
);
var material = new babylon.StandardMaterial(
"textureX" + this.internalId,
scene
);
var rgb = this.hexToRgb(item.color);
material.diffuseColor = new babylon.Color3(
rgb.r / 256,
rgb.g / 256,
rgb.b / 256
);
material.ambientColor = material.diffuseColor;
cylinder.material = material;
this.internalId++;
cylinder.data = {};
cylinder.data.item = item;
cylinder.rotation.y = -Math.PI / 2;
const sphere = Mesh.CreateSphere("sphere1", 16, 1, scene);
const bin = MeshBuilder.CreateCylinder("bin", {
diameterTop: 2,
diameterBottom: 1,
height: 2,
},scene);
const binInner = MeshBuilder.CreateCylinder("bin", {
diameterTop: 1.9,
diameterBottom: 0.9,
height: 2,
},scene);
const outerCSG = CSG.FromMesh(bin);
const innerCSG = CSG.FromMesh(binInner);
const subCSG = outerCSG.subtract(innerCSG);
const mat0 = new StandardMaterial("mat0", scene);
const displayBin = subCSG.toMesh('displayBin', mat0, scene);
scene.removeMesh(bin);
scene.removeMesh(binInner);
const materialSphere1 = new StandardMaterial("texture1", scene);
const materialGround1 = new StandardMaterial("texture2", scene);
ground.receiveShadows = true;
shadowGenerator.getShadowMap().renderList.push(sphere);
shadowGenerator.getShadowMap().renderList.push(displayBin);
sphere.material = materialSphere1;
ground.material = materialGround1;
materialSphere1.diffuseTexture = new Texture("ball.png", scene);
materialGround1.diffuseTexture = new Texture("floor.jpg", scene);
materialGround1.diffuseTexture.uScale = 5.0;
materialGround1.diffuseTexture.vScale = 5.0;
);
let magnitude = Math.sqrt(
vectorPixelCoordinates.x * vectorPixelCoordinates.x +
vectorPixelCoordinates.y * vectorPixelCoordinates.y
);
let height = this.hexDefinition.hexagon_edge_to_edge_width;
let width = magnitude + item.lineWidth;
let lineWidthRatio = item.lineWidth / width;
let square = babylon.MeshBuilder.CreatePlane(
"plane",
{ width: width, height: height },
scene
);
var myMaterial = new babylon.StandardMaterial("myMaterial", scene);
if (item.isEmissive) {
myMaterial.ambientColor = myMaterial.diffuseColor = myMaterial.emissiveColor = new babylon.Color3(
1,
1,
1
);
}
myMaterial.diffuseTexture = myMaterial.emissiveTexture = new babylon.DynamicTexture(
"dynamic texture",
{ width: width, height: height },
scene,
true
);
//If we wanted to make a beveled or rounded edge, this extrusion would be the place to do it
var extrudedCenter2 = babylon.Mesh.ExtrudeShape(
"extruded",
shape2,
[
new babylon.Vector3(0, 0, -1 * item.lineWidth),
new babylon.Vector3(0, 0, item.lineWidth)
],
1,
0,
babylon.Mesh.CAP_END,
scene
);
//Color the center
var arrowCenterMaterial = new babylon.StandardMaterial(
"arrowCenterMaterial",
scene
);
rgb = this.hexToRgb(item.fillColor);
arrowCenterMaterial.diffuseColor = new babylon.Color3(
rgb.r / 256,
rgb.g / 256,
rgb.b / 256
);
arrowCenterMaterial.specularColor = new babylon.Color3(
rgb.r / 256,
rgb.g / 256,
rgb.b / 256
);
arrowCenterMaterial.emissiveColor = new babylon.Color3(
rgb.r / 256,
protected _createDefaultMaterial(scene: Scene): Material {
var result = new StandardMaterial("Plastic", scene);
result.diffuseColor = this._dataSource!.color;
result.specularColor = Color3.Black();
return result;
}
} else if (i === 2) {
return item.shaftWidth * 1.5;
} else {
return 0;
}
},
0,
scene
);
//merge the cap and vector
var compoundMesh = babylon.Mesh.MergeMeshes([joint, vector]);
//color it
var rgb = this.hexToRgb(item.color);
var material = new babylon.StandardMaterial("vectorMaterial", scene);
material.diffuseColor = new babylon.Color3(
rgb.r / 256,
rgb.g / 256,
rgb.b / 256
);
//material.specularColor = new babylon.Color3(rgb.r/256, rgb.g/256, rgb.b/256);
//material.emissiveColor = new babylon.Color3(rgb.r/256, rgb.g/256, rgb.b/256);
compoundMesh.material = material;
compoundMesh.data = {};
//Will be used to test if the click was near enough to the head
compoundMesh.data.isDrag = function() {
return true;
};
compoundMesh.rotation.z = angle;