这段代码在浏览器中导致内存泄漏是否正确?
/**
* @param {Canvas2DRenderingContext} ctx
* @param {string} url
*/
function loadImageDrawIntoCanvas(ctx, x, y, url) {
var img = new Image();
img.onload = function() {
ctx.drawImage(img, x, y);
}
img.src = url;
};
Run Code Online (Sandbox Code Playgroud)
我的理解是因为img是一个DOM元素,因为我用img.onload浏览器将JavaScript附加到它上面,所以永远不会垃圾收集它.要纠正我需要清除img.onload的内容
/**
* @param {Canvas2DRenderingContext} ctx
* @param {string} url
*/
function loadImageDrawIntoCanvas(ctx, x, y, url) {
var img = new Image();
img.onload = function() {
ctx.drawImage(img, x, y);
img.onload = null; // detach the javascript from the Image
img = null; …Run Code Online (Sandbox Code Playgroud) 我有一个包含2个lfs跟踪文件的repoA。我像这样将那个仓库带入repoB
cd repoB
git fetch repoA somebranch
git checkout -b temp FETCH_HEAD
git rebase someotherbranch
Run Code Online (Sandbox Code Playgroud)
这将打印几行“正在应用:...”,然后
Using index info to reconstruct a base tree...
Falling back to patching base and 3-way merge...
error: Your local changes to the following files would be overwritten by merge:
Assets/HappyFunTimes/HappyFunTimesCore/Server/Resources/HFTOSXServer.bytes
Please, commit your changes or stash them before you can merge.
Aborting
error: Failed to merge in the changes.
Patch failed at 0340 update server
The copy of the patch that failed is found …Run Code Online (Sandbox Code Playgroud) 有没有办法暗示VSCode/Monaco的intellisense变量类型.
我有一些像这样的代码
var loc = window.location;
var gl = context1.getContext("webgl");
var ctx = context2.getContext("2d");
Run Code Online (Sandbox Code Playgroud)
我看到VSCode知道这loc是一个URL
但它不知道什么gl是
它也不知道什么ctx是
这是有道理的,让函数根据其输入返回不同的类型是一个有点不寻常的情况.
但它确实有类型数据 WebGLRenderingContext
而且它知道 CanvasRenderingContext2D
有没有办法为我告诉vscode /摩纳哥即gl是实例WebGLRenderingContext,并且ctx是一个实例CanvasRenderingContext2D,而无需切换到打字稿?也许通过添加某种评论?
我需要解决方案在摩纳哥工作(至少在我的测试中显示所有相同的完成),因为这是一个WebGL教程站点,实际上不是VSCode,但我希望解决方案是相同的.
我正在尝试将 Pixi v3 的自定义着色器转换为 v4。
原文在这里: http://www.awwwards.com/a-gentle-introduction-to-shaders-with-pixi-js.html
相关的 CodePen 位于 http://codepen.io/omarshe7ta/pen/xVeWWy
到目前为止,我已经得到了这个:
function CustomFilter(fragmentSource) {
PIXI.Filter.call(this,
null,
fragmentSource
);
}
CustomFilter.prototype = Object.create(PIXI.Filter.prototype);
CustomFilter.prototype.constructor = CustomFilter;
// smoke shader
var shaderCode = document.getElementById('fragShader').innerHTML
var smokeShader = new CustomFilter(shaderCode);
smokeShader.uniforms.resolution[0] = width;
smokeShader.uniforms.resolution[1] = height;
smokeShader.uniforms.alpha = 1.0;
smokeShader.uniforms.shift = 1.6;
smokeShader.uniforms.time = 0;
smokeShader.uniforms.speed[0] = 0.7;
smokeShader.uniforms.speed[1] = 0.4;
var bg = PIXI.Sprite.fromImage("pixi_v3_github-pad.png");
bg.width = width;
bg.height = height;
bg.filters = [smokeShader]
stage.addChild(bg);
var logo = PIXI.Sprite.fromImage("pixi_v3_github-pad.png");
logo.x = width …Run Code Online (Sandbox Code Playgroud) 我对 Chart.js 有问题。
我想要一个警报,当我单击图表中的一个点时,向我显示数据集中设置的 ID 值。
我试过使用getElementsAtEvent(evt);,但它没有按我预期的那样工作。
有人可以帮助我吗?谢谢!
var ctx = document.getElementById("myChart");
var color = ["#ff6384", "#5959e6", "#2babab", "#8c4d15", "#8bc34a", "#607d8b", "#009688"];
var scatterChart = new Chart(ctx, {
type: 'line',
data: {
datasets: [{
label: 'Linea A',
backgroundColor: "transparent",
borderColor: color[1],
pointBackgroundColor: color[1],
pointBorderColor: color[1],
pointHoverBackgroundColor: color[1],
pointHoverBorderColor: color[1],
data: [{
x: "2014-09-02",
y: 90,
id: '1A'
}, {
x: "2014-11-02",
y: 96,
id: '2A'
}, {
x: "2014-12-03",
y: 97,
id: '3A'
}]
},
{
label: 'Linea …Run Code Online (Sandbox Code Playgroud)我试图使用一些服务器的API函数,突然出现了这个错误.我将在代码示例后解释它:
public IEnumerator Post(Dictionary<string, string> data)
{
var request = UnityWebRequest.Post(Url, data);
request.SetRequestHeader("Content-Type", "application/x-www-form-urlencoded");
yield return request.Send();
if (request.isError)
UpdateNetworkLog("Network error has occured: " + request.error);
else
// Some code after success
}
Run Code Online (Sandbox Code Playgroud)
正如你所看到的,主要是我把它从Unity手动考虑POST请求这里.但是,有一个问题 - 请求从未正确完成,它总是有错误(使用UpdateNetworkLog函数显示):"通用/未知HTTP错误",而请求的响应代码为0.此外,我试图使用遗留本手册中的方法和WWW类获得相同的结果.
我认为,问题在于Unity如何获得响应:我通过Wireshark检查了数据包,我的POST请求和服务器的响应都非常好,没有错误或错误.
另一个重要的问题是我正在使用WebGL,并且编辑器中的所有内容都可以,程序得到正确的响应并正常工作; 只有在浏览器中构建并运行游戏(在Chrome和Safari中测试)后才会出现错误.此外,尝试使用Unity WebGL播放器启动它,但XAMPP:相同.
感谢所有未来的回复,因为Google对此一无所知.
我正在尝试在 BufferGeometry 中设置每个面的 UV 索引。
我从几何开始。我的几何体的每个面都有一个face.materialIndex对应的 UV 指数。我正在尝试将其转换为 BufferGeometry,然后将其映射face.materialIndex到BufferGeometry.
这是我到目前为止所拥有的:
// Convert geometry > buffergeometry
const bufGeo = new BufferGeometry().fromGeometry( geometry );
// Get an array of all the original geometry's indices...
const faceIndices = geometry.faces.map( face => face.materialIndex );
// Build a new array with the indices...
const indices = new Uint16Array( faceIndices );
// Apply to the BufferGeometry
bufGeo.setIndex( new BufferAttribute( indices, 1 ) );
Run Code Online (Sandbox Code Playgroud)
现在这似乎破坏了我的网格并使其根本无法绘制。我究竟做错了什么?
顺便说一句,在幕后,当 Geometry 转换为 BufferGeometry 时,Three.js 首先将其置于称为 …
在此rand()Three.js 着色器示例中,使用名为(以 avec2作为参数)的函数来生成随机数。
但是,该函数未在着色器代码中定义。相反,它似乎包含在使用#include <common>(片段着色器的第一行)中。
我猜它#include的工作原理有点像 C/C++,但它到底<common>指的是什么?是外部文件吗?它是 Three.js 特有的东西还是一般也适用于 WebGL/GLSL?
免责声明:一般来说,我对three.js、WegGL 和3D 图形比较陌生。
我正在使用 Three.js 以 3D 形式显示 GPS 轨迹中的点。我们必须能够可视化的数据集可能非常大(数十万个点),因此性能非常重要。
我使用一个Points对象,我用一个BufferGeometry包含所有点的对象填充该对象。这些点是按照曲目的顺序添加的,所以按时间顺序。
然后,我们使用PointsMaterial带有 2D 纹理(精灵)的 a 将点表示为一个圆,圆外的区域是透明的。因为颜色是动态的,所以 2D 纹理是动态绘制到画布上的。
问题是,如果我们看轨迹方向上的点,即离相机较远的点是在较近的点之后渲染的点,在点重叠的地方会出现伪影,较近点的透明部分被绘制在更远的点上:
当我们从另一个方向看轨道时,即从后向前渲染的点,问题就消失了:
我尝试了以下两个选项来解决该问题:
alphaTest0和1之间的一个数值,它样的作品
depthWrite: false的材料的点,它呈现漂亮,但随后近点总是绘制在旧的无论相机的方向,它看起来奇怪,是错误的实际渲染深度 顺序中的点从最远的开始到最近的结束的解决方案是什么?
以下是代码的相关部分。
几何的构建。该timeline3d对象包含所有点并来自 XHR 请求:
const particlesGeometry = new BufferGeometry();
const vertices = [];
for (let i = 0; i < timeline3d.points.length; i++) {
const coordinates = timeline3d.points[i].sceneCoordinates;
vertices.push(coordinates[0], coordinates[1], coordinates[2]);
}
particlesGeometry.addAttribute('position', …Run Code Online (Sandbox Code Playgroud) javascript ×6
three.js ×3
3d ×1
chart.js ×1
charts ×1
git ×1
git-lfs ×1
glsl ×1
html ×1
http ×1
iframe ×1
intellisense ×1
memory-leaks ×1
pixi.js ×1
slack ×1
slack-api ×1
unity-webgl ×1